• 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;
            }
  • 相关阅读:
    学习进度
    毕设进度
    学习进度
    毕设进度
    学习进度
    学习进度
    第一周冲刺评论总结&&针对评论总结的改进
    第一阶段成果展示
    团队冲刺--Seven
    团队冲刺--six
  • 原文地址:https://www.cnblogs.com/xiaoyu369/p/8931450.html
Copyright © 2020-2023  润新知