我正在寻找关于使用OWIN获取refresh_token
的任何有用的建议。
所有东西都很好用。但是,至少我不知道如何检索refresh_token
我尝试在初始请求中添加"access_offline“,没有什么有用的。我肯定做错了什么。
为什么我需要它?-我正在尝试连锁Google Glass + MVC5 + OWIN
的功能。
附注:我将感激使用Google.Api.Auth构建的工作示例的任何链接。
谢谢。
发布于 2014-03-24 20:04:49
发布于 2014-03-24 21:51:30
发布于 2015-06-26 06:03:37
您可以使用这样的代码
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);
}
}
});
https://stackoverflow.com/questions/22614163
复制相似问题