- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试在 MVC5 项目中使用 Microsoft.Owin.Security.Google 获取 Google 帐户的刷新 token 。要从谷歌服务器响应获取 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);
最佳答案
Microsoft.Owin.Security 库的 3.0.0 版会将此选项添加到 GoogleOAuth2AuthenticationProvider(参见已修复的 issue #227)。根据Katana Project roadmap它将在 2014 年夏末推出。如果您在正式发布之前需要此功能,您可以通过预发布 NuGet channel 获取最新版本。
然后您可以像这样配置它(在 Startup.Auth.cs 中):
app.UseGoogleAuthentication(new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions {
ClientId = ...,
ClientSecret = ...,
AccessType = "offline",
Provider = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationProvider {
OnAuthenticated = context => {
if (!String.IsNullOrEmpty(context.RefreshToken)) {
context.Identity.AddClaim(new Claim("RefreshToken", context.RefreshToken));
}
return Task.FromResult<object>(null);
}
});
并且您可以在 ExternalLoginCallback 中获取刷新 token (如果保留默认代码组织,则为 AccountController.cs):
string refreshToken = loginInfo.ExternalIdentity.Claims
.Where(i => i.Type == "RefreshToken")
.Select(i => i.Value)
.SingleOrDefault();
关于c# - GoogleOAuth2AuthenticationOptions 将 access_type 设置为离线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22486945/
我正在尝试调整一个非常简单的查询: select * from log where user_id in (...) order by id desc limit 25 我只想显示一组不同用户 ID(
我正在尝试在 MVC5 项目中使用 Microsoft.Owin.Security.Google 获取 Google 帐户的刷新 token 。要从谷歌服务器响应获取 RefreshToken,我需要
我正在尝试更改我们对 .net 客户端库的旧 rest 调用,我有两个相关的问题/问题...... 此页面上的示例应用程序 https://developers.google.com/api-clie
请求 OAuth 凭据时,我可以将 access_type 指定为 Offline 或 Online。 选择在线访问类型会强制用户在每次登录时批准对我的应用程序的访问。这是为什么?用户不是已经批准了我
我在 documentation 上看到您需要设置 access_type=offline 才能获得刷新 token 。 我确实在 OAuth url 中设置了这个值,我清楚地看到它与其他参数一起正确
我有一个已批准作为具有 openid 和 email 范围的授权 API 客户端的应用程序。我仍然看到“您的域管理员已批准访问”初始屏幕 as documented here 。解决方案是不通过 ac
这个问题类似于Not receiving Google OAuth refresh token ,但我已经按照已接受解决方案的评论中的建议指定了 access_type='offline'。 我正在编
这篇文章是 How to do OAuth-requiring operations in a GAE cron job? 的后续文章,我意识到我误用了 OAuth2DecoratorFromClie
我是一名优秀的程序员,十分优秀!