Announcement Announcement Module
Collapse
No announcement yet.
Using authenticateClient() for Twitter OAuth2 application authorization Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using authenticateClient() for Twitter OAuth2 application authorization

    I read Spring Social Twitter 1.0.4 Release notes and I have been trying to use application authorization for searching, etc. I do not want to use user authentication. I assume that application authorization should work something like this:

    Code:
    OAuth2Operations operations = new OAuth2Template(
    				"key",
    				"secret",
    				"https://api.twitter.com/oauth/authorize",
    				"https://api.twitter.com/oauth/access_token");
    		AccessGrant accessGrant = operations.authenticateClient();
    		Twitter twitter = new TwitterTemplate(accessGrant.getAccessToken());
    But the authenticateClient() call fails with
    Code:
    Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 401 Unauthorized
            at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:90)
            at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:494)
            at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:451)
            at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409)
            at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:287)
            at org.springframework.social.oauth2.OAuth2Template.postForAccessGrant(OAuth2Template.java:228)
            at org.springframework.social.oauth2.OAuth2Template.authenticateClient(OAuth2Template.java:191)
            at org.springframework.social.oauth2.OAuth2Template.authenticateClient(OAuth2Template.java:178)
    The strings "key" and "secret" are replaced with the Twitter Consumer Key and Consumer Secret assigned to the application.

    I also noticed the Spring Social Twitter 1.0.5 bugfix release announcement. I am using spring-social-core-1.0.3.RELEASE, spring-social-twitter-1.0.5.RELEASE, and Spring 3.1.4.RELEASE.

    Is this the way it's supposed to work? If so, what might I be missing?

    Mark

  • #2
    For the purposes of client authentication, the 3rd parameter to OAuth2Template's constructor is irrelevant. It's the authorization page URL, which plays no part in client authentication. For my own testing purposes, I simply set it to "" when I know I'm only dealing with client authentication.

    As for the 4th parameter, it should be "https://api.twitter.com/oauth2/token".

    Comment


    • #3
      Thanks for the response. It's working now. Now that I've read Twitter's documentation on application-only authentication more carefully, I see that it refers to the oauth2/token path.

      Thanks again.

      Comment

      Working...
      X