zoukankan      html  css  js  c++  java
  • oidc User.Identity.Name 为空解决方法

         public override Task TicketReceived(TicketReceivedContext context)
            {
    var result = base.TicketReceived(context);
    
                var identity = context.Principal.Identity as ClaimsIdentity;
                if (identity != null)
                {
                    // Add the Name ClaimType. This is required if we want User.Identity.Name to actually return something!
                    if (!context.Principal.HasClaim(c => c.Type == ClaimTypes.Name) &&
                    identity.HasClaim(c => c.Type == "name"))
                        identity.AddClaim(new Claim(ClaimTypes.Name, identity.FindFirst("name").Value));
    
                    // Check if token names are stored in Properties
                    if (context.Properties.Items.ContainsKey(".TokenNames"))
                    {
                        // Token names a semicolon separated
                        string[] tokenNames = context.Properties.Items[".TokenNames"].Split(';');
    
                        // Add each token value as Claim
                        foreach (var tokenName in tokenNames)
                        {
                            // Tokens are stored in a Dictionary with the Key ".Token.<token name>"
                            string tokenValue = context.Properties.Items[$".Token.{tokenName}"];
                            identity.AddClaim(new Claim(tokenName, tokenValue));
                        }
                    }
                }
               return result;
            }
  • 相关阅读:
    解决git推不上去1
    django中CBV源码分析
    Form和ModelForm组件
    jquery操作cookie
    django中的中间件
    django中ORM中锁和事务
    django_ajax
    docker安装jenkins 容器,集成python环境
    支付宝第三方支付
    redis基本使用
  • 原文地址:https://www.cnblogs.com/xiaoyu369/p/8931450.html
Copyright © 2011-2022 走看看