• Skoruba.IdentityServer4.STS.Identity 踩坑


    记录:

    Skoruba.IdentityServer4.STS.Identity项目中注册的认证处理程序,接入第三方认证  

      

       

       如下图:这里没有指定默认的Authentication Scheme 

     

      但是在AddIdentityServer中 services.AddIdentityServer 添加Identityserver4 时

       

      

       

       

       在Identityserver4 扩展方法,identityserver4 重新指定默认 Authentication Scheme,还添加了cookie Scheme,一个默认Scheme ,一个可用于第三方认证使用。

      接入第三微软Azure AD 认证时,存在的问题

      注意 JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear() 使用,会造成错误 signInManager.GetExternalLoginInfoAsync()执行一直返回null。

      参考:https://blog.lcrun.com/wei-shi-yao-yao-shi-yong-jwtsecuritytokenhandler-defaultinboundclaimtypemap-clear/

       如下图:

      

       当使用 AddMicrosoftIdentityWebApp 方法时,在AccountController 中 ExternalLoginCallback会报错,下图代码展示区

      原因在于  调用_signInManager.GetExternalLoginInfoAsync();

      

      方法  signInManager.GetExternalLoginInfoAsync 方法内部,调用了 Context.AuthenticateAsync(IdentityConstants.ExternalScheme); 在运行的时候

      IdentityConstants.ExternalScheme ="Identity.External" 

      signInManager.GetExternalLoginInfoAsync()执行一直返回null,使用了错误的  Authentication Scheme,

     

      解决方案一

       

      如果改用 await  HttpContext.AuthenticateAsync(OpenIdConnectDefaults.AuthenticationScheme); 将得到正确的处理。那么可以重写 _signInManager.GetExternalLoginInfoAsync() 方法实现。

      解决方法二

      

       使用 AddAzureAD 扩展包,需要使用nuget 下载 Microsoft.AspNetCore.Authentication.AzureAD.UI 包。

      方案三

      参考 : https://github.com/AzureAD/microsoft-identity-web/issues/133

      

      存在的其他需要注意的问题

      不管使用 AddMicrosoftIdentityWebApp 还是 AddAzureAD ,如果还存在 GitHub 、Google 第三方认证的话

      例如:使用GitHub ,下图查看它的扩展方法

      

       

       

       github,会使用自己的Authentication Scheme 和 认证处理中间件,一般无需设置 options.CallbackPath = externalProviderConfiguration.GitHubCallbackPath;

       在github设置中 ,如下设置:

      

       

    © 版权声明
    文章版权归作者所有,未经允许请勿转载。
  • 相关阅读:
    Sql Server 2008 为开发带来的新特性
    MSMQ 与ESB
    面向服务架构(SOA)和企业服务总线(ESB)
    IBM网站 构建您的SOA 系列文章
    Visual Studio 2008 和 .NET Framework 3.5 Training Kit
    模式与实践 系列发布WCF Security Guidance 1.0
    跟NHibernate之夏一起学习NHibernate
    ORACLE一些不常用的脚本
    ORACLE已建表能否创建分区
    Access数据库问题锦集
  • 原文地址:https://www.cnblogs.com/youlicc/p/15260373.html
Copyright © 2020-2023  润新知