문제

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.

도움이 되었습니까?

다른 팁

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.

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);
        }
    }
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top