【问题标题】:User.Identity.GetUserName() and GetUserId() return empty strings when post IdentityServer3 authentication发布 IdentityServer3 身份验证时,User.Identity.GetUserName() 和 GetUserId() 返回空字符串
【发布时间】:2015-12-26 05:33:10
【问题描述】:

我正在使用 IdentityServer3 并希望 User.Identity.GetUserName() 和 User.Identity.GetUserId() 返回存储在声明中的值。现在,我在声明中将它们视为“子”和“电子邮件”。是否可以:

  1. 让 IdentityServer3 将这些作为声明返回?我猜他们会是 nameidentifier 和 name。

  2. 在客户端应用通过身份验证后添加声明,以便 User.Identity 方法可用。

希望这有点道理,我感谢任何反馈。

【问题讨论】:

    标签: identityserver3


    【解决方案1】:

    我想我明白了。

    我在 Scopes 类中添加了一个新的 Scope:

    new Scope
    {
         Name = "public",
         DisplayName = "Public scope",
         Type = ScopeType.Identity,
         IncludeAllClaimsForUser = true
    }
    

    然后我在 AccountController 的 SignIn 操作中修改了我的登录 url:

    var url = Settings.AuthorizeEndpoint +
         "?client_id=" + Settings.ClientId +
         "&response_type=id_token" +
         "&scope=openid email profile public" +
         "&redirect_uri=" + Settings.RedirectUri +
         "&response_mode=form_post" +
         "&state=" + state +
         "&nonce=" + nonce; 
    

    这似乎成功了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-27
      • 1970-01-01
      • 2018-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-07
      相关资源
      最近更新 更多