0

Starting with Rick Anderson's great tutorial MVC 5 App with Facebook, Twitter, LinkedIn and Google OAuth2 Sign-on, using the Google Authentication particularly...

I extended the scope of Google Authentication to include the DriveAPI. That part all works fine and Fiddler shows the googleapi access_token coming back.

I now want to provide the google api token to my javascript code so I can call the Google drive api with my access token directly.

I can get the token from the GoogleoAuth2AuthenticationProvider

GoogleOAuth2AuthenticationOptions googleOptions = new GoogleOAuth2AuthenticationOptions() {
            ClientId = ConfigurationManager.AppSettings["ClientId"],
            ClientSecret = ConfigurationManager.AppSettings["ClientSecret"],
            SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
            Provider = new GoogleOAuth2AuthenticationProvider() {
                OnAuthenticated = async context => {
                    context.Identity.AddClaim(new Claim(GoogleApiAccessTokenClaimType, context.AccessToken));
                }
            },
        };

Clearly I need to store it somewhere. I thought that the claims were automatically persisted in the .AspNetApplicationCookie, and even though this cookie is read again I can't see an easy way to retrieve any claims I've added.

That makes me feel like I should store it AspNetUser tables. But that seems redundant if it is available from the cookie once it's read and decrypted.

Now say I have the token, how should I communicate it to my javascript. I've been just sending it down with the page in a block. Dominick Baier said that was ok. But I still wonder if I should consider another method.

So my question in summary is...

  1. How should I be getting my token for the drive api? (I think I've got this working)
  2. Where should I keep it?
  3. How should I expose it to my javascript code?

Thanks for the attention.

Community
  • 1
  • 1

1 Answers1

0

These other two questions and discussion cover most of the nitty-gritty.

Really helpful. Especially the symbol setup. (A little easier to work with than Reflector generated pdbs)

questions/24894789/how-to-renew-the-access-token-using-the-refresh-token

Somewhat helpful, in the ballpark.

questions/20637674/owin-security-how-to-implement-oauth2-refresh-tokens

Community
  • 1
  • 1