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...
- How should I be getting my token for the drive api? (I think I've got this working)
- Where should I keep it?
- How should I expose it to my javascript code?
Thanks for the attention.