簡體   English   中英

身份服務器 Windows 身份驗證聲明

[英]Identity Server Windows Authentication Claims

我正在嘗試將 Identity 4 服務器配置為與我的 API 項目一起使用。 此時我可以請求令牌,但我需要將用戶名和角色添加到有效負載。 我嘗試使用 IProfileService 但未執行任何操作。 如何從 windows 身份驗證中獲取此信息? 這是我的配置:

啟動設置.json

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

程序.cs

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseKestrel()
            .UseIISIntegration()
            .UseStartup<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
            }
        };

我只使用普通身份驗證,但創建和控制聲明與其他應用程序共享方式的類應該是相同的。

您可能只需要將聲明添加到 API 資源,因為默認情況下,客戶端使用的聲明不會包含在訪問令牌中,該令牌也提供給客戶端以請求 API。

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

             }),

您在那里添加的索賠名稱是索賠名稱。 如果這不起作用,向我們提供更多信息會很有幫助。 如何配置 API 資源(身份服務器端和客戶端)? 或者您是否嘗試將 API 配置為客戶端?

第一點在 IdentityServer 中,Windows 身份驗證是一個外部提供者(相對於 IS 本機身份驗證 cookie)。 Windows 身份驗證是通過使用方案Windows的 HttpContext 上的ChallengeAsync API 觸發的。您可以單擊此處了解詳細信息。

另一點是您正在使用客戶端憑據流,這在您的場景中是錯誤的。 客戶端憑證流使用應用程序的身份,其中沒有用戶。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM