【发布时间】:2014-04-24 13:57:07
【问题描述】:
我正在尝试在 MVC5 项目中使用 Microsoft.Owin.Security.Google 获取 Google 帐户的刷新令牌。要从谷歌服务器获取响应中的 RefreshToken,我需要设置access_type = offline。但我在 GoogleOAuth2AuthenticationOptions 对象中找不到任何合适的属性。
用于允许身份验证的代码
var gao = new GoogleOAuth2AuthenticationOptions
{
ClientId = ConfigurationManager.AppSettings.Get("GoogleClientId"),
ClientSecret = ConfigurationManager.AppSettings.Get("GoogleClientSecret"),
Provider = new GoogleOAuth2AuthenticationProvider
{
OnAuthenticated = async ctx =>
{
var refreshToken = ctx.RefreshToken;
//ctx.Identity.AddClaim(new Claim("refresh_token", refreshToken));
}
}
};
gao.Scope.Add(TasksService.Scope.Tasks);
gao.Scope.Add("openid");
app.UseGoogleAuthentication(gao);
【问题讨论】:
标签: c# oauth-2.0 asp.net-mvc-5 owin