Announcement Announcement Module
Collapse
No announcement yet.
Facebook, no suitable HttpMessageConverter found Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Facebook, no suitable HttpMessageConverter found

    Hey everyone,

    I been working on a proof on concept at work.. Just trying to get oAuth2 connection from my client application to facebook. I got to the point where my client app is trying to get the access_token from facebook, but then I get the following exceptions..


    Code:
    2012-09-11 06:28:34.458 PDT [tomcat-http--39] DEBUG client.token.grant.code.AuthorizationCodeAccessTokenProvider - Retrieving token from https://graph.facebook.com/oauth/access_token?client_id=XXXXXX&client_secret=XXXXXX
    2012-09-11 06:28:34.507 PDT [tomcat-http--39] DEBUG org.springframework.web.client.RestTemplate - Created POST request for "https://graph.facebook.com/oauth/access_token?client_id=XXXXXX&client_secret=XXXXX"
    2012-09-11 06:28:35.207 PDT [tomcat-http--39] DEBUG org.springframework.web.client.RestTemplate - POST request for "https://graph.facebook.com/oauth/access_token?client_id=XXXXXXX&client_secret=XXXXXX" resulted in 200 (OK)
    2012-09-11 06:28:35.262 PDT [tomcat-http--39] DEBUG springframework.security.web.access.ExceptionTranslationFilter - Access is denied (user is not anonymous); delegating to AccessDeniedHandler
    org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException: Error requesting access token.
            at org.springframework.security.oauth2.client.token.OAuth2AccessTokenSupport.retrieveToken(OAuth2AccessTokenSupport.java:102)
            at org.springframework.security.oauth2.client.token.grant.code.AuthorizationCodeAccessTokenProvider.obtainAccessToken(AuthorizationCodeAccessTokenProvider.java:56)
            at org.springframework.security.oauth2.client.token.AccessTokenProviderChain.obtainNewAccessTokenInternal(AccessTokenProviderChain.java:110)
            at org.springframework.security.oauth2.client.token.AccessTokenProviderChain.obtainAccessToken(AccessTokenProviderChain.java:90)
    ...
    Caused by: org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [org.springframework.security.oauth2.common.OAuth2AccessToken] and content type [text/plain;charset=UTF-8]
            at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:84)
            at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:446)
            at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409)
            at org.springframework.security.oauth2.client.token.OAuth2AccessTokenSupport.retrieveToken(OAuth2AccessTokenSupport.java:94)
            ... 44 more

    I have the following messageConverters injected, just like in the tonr2 sample app..

    Code:
    <property name="messageConverters">
        <list>
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <bean class="org.springframework.http.MediaType">
                            <!--facebook sends its json as text/javascript for some reason -->
                            <constructor-arg value="text" />
                            <constructor-arg value="javascript" />
                        </bean>
                        <bean class="org.springframework.http.MediaType">
                            <constructor-arg value="application" />
                            <constructor-arg value="json" />
                        </bean>
                    </list>
                </property>
            </bean>
        </list>
    </property>
    What am I missing here? Any help would be really appreciated.. Thanks
    Last edited by jdevWF; Sep 11th, 2012, 09:48 AM. Reason: had some sensitive info..

  • #2
    The message converters in OAuth2RestTemplate are used to deserialize the responses from the API calls, not the token itself (and it works for me for basic user profile data without custom converters, so maybe tonr2 would work that way as well). Getting a token doesn't require any special configuration in tonr2 either, so I'm not sure why yours isn't working. The response type is text/plain according to the error you posted so maybe it's not a token and you just have a configuration problem. If you post your rest template and oauth:resource configuration maybe we can tell from that, but it's probably better to tcpdump the conversation and have a look at the actual content yourself.

    Comment

    Working...
    X