I am using the OAuth.io JavaScript client SDK to authenticate via GitHub. On authentication success I receive a GitHub access_token. I have also set cache: true
so the user only gets the popup if they aren't already logged in.
Because I have caching enabled, when I call OAuth.popup
no popup actually appears and instead my callbacks are immediately called with the access_token
available.
How can I check to see if the user is already logged in and get the access token without showing the popup in the case where they aren't already logged in?
The reason for this is because I want to show the login button if they are not logged in, but I want to show data from GitHub if they are logged in. In either case, I don't want to show the pop-up window unless they actually click the login button.
Note: I am specifically looking for a way to do this with OAuth.io client JavaScript SDK. I know that I can manually save off credentials when they authenticate, but I would rather not have to if oauth.io already has that information cached somewhere.
Turns out it was right in front of my face on the documentation: http://docs.oauth.io/#caching-the-request-object
In particular,
OAuth.create('github')
is what I needed. It will give back the cached result object, the same one I would get back from attempting to authenticate.