为什么MVC 5 Owin Oauth没有点击/ Account/ExternalLoginCallbac
发布时间:2020-12-16 03:53:59 所属栏目:asp.Net 来源:网络整理
导读:我是MVC 5认证的新手.目前,我尝试使用Owin进行Google授权 startup.Auth.cs中的代码 var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions{ ClientId = "Client-id",ClientSecret = "secret-key",CallbackPath = new PathString("
我是MVC 5认证的新手.目前,我尝试使用Owin进行Google授权
startup.Auth.cs中的代码 var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions { ClientId = "Client-id",ClientSecret = "secret-key",CallbackPath = new PathString("/Account/ExternalLoginCallback"),Provider = new GoogleOAuth2AuthenticationProvider() { OnAuthenticated = async context => { context.Identity.AddClaim(new Claim("picture",context.User.GetValue("picture").ToString())); context.Identity.AddClaim(new Claim("profile",context.User.GetValue("profile").ToString())); } } }; googleOAuth2AuthenticationOptions.Scope.Add("email"); app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions); 但它没有点击ExternalLoginCallback Action进行调试. [AllowAnonymous] public async Task<ActionResult> ExternalLoginCallback(string returnUrl) 它停在/ Account / ExternalLoginCallback?ReturnUrl = /,带有空白屏幕. 解决方法
这类似于:
Google Authentication using OWIN Oauth in MVC5 not hitting ExternalLoginCallback function
基本上,将开发人员信息中心中的Google应用设置为指向* / ExternalLoginCallback方法. 保留GoogleProvider的默认回调路径. var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions { ClientId = "MYCLIENTID",ClientSecret = "MYSECRET" }; 在RouteConfig中添加处理signin-google的路由: routes.MapRoute( name: "signin-google",url: "signin-google",defaults: new { controller = "[YOURCONTROLLLER]",action = "ExternalLoginCallback"}); 这应该修复谷歌提供商和所有其他人. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp-classic – 检索ADO Recordset字段名称(经典ASP)
- 剃刀 – 我应该在哪里包含视图组件的脚本?
- asp.net-mvc – 获取Web层之外的当前Principal
- asp.net-web-api – Autofac,Owin,Webapi并注入Authorizati
- asp.net-mvc – ViewModel有自己的逻辑吗?
- asp.net – 中继器中继器
- asp.net-mvc – 用于测试目的的假开放ID提供程序
- asp.net – 带有VS2010 SP1的IIS Express不断重建网站
- asp.net – Visual Studio 2010图表控件:使Y轴成为整数值,
- asp.net-mvc – 人们如何使用编辑器/显示模板与Html助手?