Reputation: 2625
I'm looking for any useful suggestion with regards to obtaining refresh_token
using OWIN libs.
I follow article http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on
all stuff works sweet. but no way, at least I don't know the way, to retrieve refresh_token
I've tried to add "access_offline" to initial request, nothing useful. I definitely do something wrong.
Why do I need it? - I'm trying to chain functionality of Google Glass + MVC5 + OWIN
.
p.s. I will appreciate any link to working sample built using Google.Api.Auth.
Thanks.
Upvotes: 1
Views: 3290
Reputation: 358
You can use a code like this
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "YOUR_CLIENT_ID",
ClientSecret = "YOUR_CLIENT_SECRET",
AccessType = "offline",
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnAuthenticated = (context) =>
{
TimeSpan expiryDuration = context.ExpiresIn ?? new TimeSpan();
context.Identity.AddClaim(new Claim("urn:tokens:google:email", context.Email));
context.Identity.AddClaim(new Claim("urn:tokens:google:url", context.GivenName));
if (!String.IsNullOrEmpty(context.RefreshToken))
{
context.Identity.AddClaim(new Claim("urn:tokens:google:refreshtoken", context.RefreshToken));
}
context.Identity.AddClaim(new Claim("urn:tokens:google:accesstoken", context.AccessToken));
context.Identity.AddClaim(new Claim("urn:tokens:google:accesstokenexpiry", DateTime.Now.Add(expiryDuration).ToString()));
return Task.FromResult(0);
}
}
});
Upvotes: 0
Reputation: 7435
Yea, there's an open issue related to this in the Katana project:
https://katanaproject.codeplex.com/workitem/227
In short, it needs to be easier.
Upvotes: 1
Reputation: 3512
Take a look in the following blogpost:
http://peleyal.blogspot.com/2014/01/aspnet-mvc-with-google-openid-and-oauth.html
And, you can find a working sample code in https://github.com/peleyal/peleyal/tree/master/Google.Apis.Sample.MVC.
Upvotes: 2