bil*_*ean 5 c# linkedin asp.net-core asp.net-core-identity asp.net-core-2.1
我已将LinkedIn添加为提供商。我已实现登录并在LinkedIn上注册,没有任何问题。在用例中,用户从提供者页面中取消(链接登录或取消应用程序的授权),身份中间件似乎抛出未处理的异常:
处理请求时发生未处理的异常。
异常:user_cancelled_login; Description =用户取消了LinkedIn登录
未知位置例外:处理远程登录时遇到错误。
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler.HandleRequestAsync()
System.Exception:user_cancelled_login; Description =用户取消了LinkedIn登录
例外:处理远程登录时遇到错误。
启动时的提供程序设置定义了回调:
services.AddAuthentication().AddOAuth("LinkedIn", "LinkedIn", c =>
{
c.ClientId = Configuration["Authentication:LinkedIn:ClientId"];
c.ClientSecret = Configuration["Authentication:LinkedIn:ClientSecret"];
c.Scope.Add("r_basicprofile");
c.Scope.Add("r_emailaddress");
c.CallbackPath = "/signin-linkedin";
....
Run Code Online (Sandbox Code Playgroud)
正如我所说的,中间件似乎可以处理所有其他情况,除非用户在LinkedIn页面中取消。LinkedIn的返回URL看起来正确:
但是永远都不会进入我的ExternalCallback控制器方法,在该方法中会处理其他类似成功登录/授权的情况?
我想知道这是否对第三方供应商的其他人有用吗?
有一个Github 问题更详细地解释了这里发生的事情,并提供了一些关于它为什么发生的信息,甚至表明这不会“修复”:
处理 RemoteFailure 事件是正确的做法。我们应该更新我们的文档/示例以展示如何处理该事件,并至少向用户显示更合适的消息。错误页面示例可能包含一个链接,使用户能够再次尝试登录。
不幸的是,很难以非常通用的方式实现这个事件,这种方式也非常有用,因为每个远程身份验证提供程序对于不同类型的故障都有自己的行为。
解决方法(如上所述)是处理 RemoteFailure 事件:
services.AddAuthentication().AddOAuth("LinkedIn", "LinkedIn", c => {
// ...
c.Events.OnRemoteFailure = ctx =>
{
// React to the error here. See the notes below.
return Task.CompletedTask;
}
// ...
});
Run Code Online (Sandbox Code Playgroud)
ctx是RemoteFailureContext 的一个实例,其中包含一个Exception描述出错原因的属性。ctx还包含一个HttpContext属性,允许您执行重定向等,以响应此类异常。
| 归档时间: |
|
| 查看次数: |
3117 次 |
| 最近记录: |