0
votes

I've created web application that uses 3-legged OAuth to access user's contacts API. At the end of the process I receive an access_token and access_token_secret which I save in a database together with the user_id(user's email).

The problem is that the next time someone tries to go through the OAuth I want if I already have existing token to use it instead of going through the whole procedure.

Is there a way to get the user_id before the user is authenticated.

For authentication I'm using the code from here: http://code.google.com/appengine/articles/java/retrieving_gdata_feeds.html

2

2 Answers

1
votes

In the background visit a page (\me?access_token=) using the stored access token. If the token still is valid you will get a response without errors. If the token is no longer valid, you'll get an OAuthException as response.

get userData with old access token 

if exception is thrown => Redo authentication process
else => continue with old token
1
votes

It depends on the resource protected by OAuth. Usually, if there is a target user_id, you can get it by an additional invocation of a RESTful service.

For example, with Google+ you'd have something like that (using my G+ wrapper):

String userId = plus.getPeopleOperations().get("me").getId();