【问题标题】:Identity Server Windows Authentication ClaimsIdentity Server Windows 身份验证声明
【发布时间】:2019-11-04 13:05:57
【问题描述】:

我正在尝试配置 Identity 4 服务器以使用我的 API 项目。此时我可以请求令牌,但我需要将用户名和角色添加到有效负载。我尝试使用 IProfileService 但未执行任何操作。如何从 Windows 身份验证中获取此信息?这是我的配置:

launchSettings.json

"iisSettings": {
  "windowsAuthentication": true, 
  "anonymousAuthentication": false 

程序.cs

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseKestrel()
            .UseIISIntegration()
            .UseStartup<Startup>();

Startup.cs

        services.Configure<IISOptions>(iis =>
        {
            iis.AutomaticAuthentication = true;
        });

        var builder = services.AddIdentityServer()
              .AddInMemoryIdentityResources(IdentityResourcesConfig.Get())
              .AddInMemoryApiResources(ApiResourcesConfig.Get())
              .AddInMemoryClients(ClientsConfig.Get());

ClientsConfig.cs

        return new Client[]
        {
            new Client
            {
                ClientId = "XYC",
                AllowedGrantTypes = GrantTypes.ClientCredentials,
                AllowedScopes = { "XYC" },
                RequireClientSecret = false,
                AlwaysIncludeUserClaimsInIdToken = true
            }
        };

【问题讨论】:

    标签: c# asp.net-core identityserver4 windows-authentication


    【解决方案1】:

    我只使用普通身份验证,但创建和控制声明与其他应用程序共享方式的类应该是相同的。

    您可能只需要将声明添加到 API 资源,因为默认情况下,客户端使用的声明不会包含在访问令牌中,该令牌也提供给客户端以请求 API。

        public static IEnumerable<ApiResource> GetApis()
        {
            return new ApiResource[]
            {
                 new ApiResource("MyApi", "This is my Api name", new List<string> {
                        "mynameclaimclaimname", 
    
                 }),
    

    您在其中添加的声明名称是声明名称。 如果这不起作用,向我们提供更多信息会很有帮助。 API 资源是如何配置的(IdentityServer 端和客户端)? 或者您是否尝试将 API 配置为 Client ?

    【讨论】:

      【解决方案2】:

      第一点是在 IdentityServer 中,Windows 身份验证是一个外部提供者(相对于 IS 本机身份验证 cookie)。 Windows 身份验证是通过使用 Windows 方案在 HttpContext 上使用 ChallengeAsync API 触发的。您可以单击 here了解详情。

      另一点是您正在使用客户端凭据流,这在您的场景中是错误的。客户端凭证流使用应用的身份,其中没有用户。

      【讨论】:

      • 我需要在没有任何登录方法的情况下进行身份验证,我只需要使用此声明生成令牌。那么什么样的流程和授权类型最适合我呢?
      猜你喜欢
      • 2020-11-09
      • 1970-01-01
      • 2017-06-26
      • 2019-03-26
      • 2021-01-11
      • 2019-08-17
      • 2016-08-31
      • 2014-05-20
      • 1970-01-01
      相关资源
      最近更新 更多