簡體   English   中英

Identity Server 4,API未經授權調用內省端點

[英]Identity Server 4, API unauthorized to call introspection endpoint

我希望有人能指出我正確的方向。

我試圖讓javascript客戶端在引用令牌的幫助下與api通信。 我正在使用Identity Server 4。

什么是好的:

登錄時,javascript客戶端/ webapplicatoin被路由到身份服務器以進行用戶和密碼驗證成功后,用戶將被路由回javascript / webapplication並具有有效的IdentityToken

什么是不行的:

當javascript客戶端/ web應用程序調用我的Api時,api會收到請求。 然后api想要通過Identity Server檢查收到的身份令牌以獲取訪問令牌,但是在控制台中無法通過以下錯誤聯系服務器:

 fail: IdentityServer4.Validation.ApiSecretValidator[0] API validation failed. fail: IdentityServer4.Endpoints.IntrospectionEndpoint[0] API unauthorized to call introspection endpoint. aborting. 

非常清楚Api不允許與te服務器通信...

我想我在某個地方有配置錯誤,但我不知道在哪里。 試過各種不同的設置,我沒有嘗試或改變的想法......

這就是我現在直到現在的情況:

對於javascript客戶端:

我使用oidc-redux包,我使用的配置:

var userManagerConfig = {
   authority: "http://localhost:50289",
   redirect_uri: "http://localhost:3000/callback",
   client_id : "js",
   response_type : "id_token",
   scope :"openid",
};

Identity Server 4配置

客戶定義:

public static IEnumerable<Client> GetClients()
{
    return new List<Client>
    {
        new Client
        {
            ClientId = "js",
            ClientName = "my js client",
            AllowedGrantTypes = GrantTypes.Implicit,
            RequireClientSecret = false,
            RequireConsent = false,
            RedirectUris           = { "http://localhost:3000/callback" },
            PostLogoutRedirectUris = { "http://localhost:3000" },
            AllowAccessTokensViaBrowser = false,
            AllowedCorsOrigins =     { "http://localhost:3000" },
            AllowedScopes =
            {
                IdentityServerConstants.StandardScopes.OpenId,
                IdentityServerConstants.StandardScopes.Profile,
                "myApi"
            }
        }
    };
}

Api資源定義:

public static IEnumerable<ApiResource> GetApiResources()
{
    return new List<ApiResource>
    {
        new ApiResource("myApi")
        {
            ApiSecrets =
            {
                new Secret("superweaksecret")
            }
        }
    };
}

在配置服務中,我將它們一起添加到容器中:

// configure identity server with in-memory stores, keys, clients and scopes
services.AddIdentityServer()
    .AddDeveloperSigningCredential()
    .AddInMemoryPersistedGrants()
    .AddProfileService<CustomClaimService>()
    .AddInMemoryIdentityResources(Config.GetIdentityResources())
    .AddInMemoryApiResources(Config.GetApiResources())
    .AddInMemoryClients(Config.GetClients())
    .AddAspNetIdentity<ApplicationUser>();

Api設置

基於.net Core,在ConfigureService方法中,我有以下內容:

services.AddAuthentication("Bearer")
    .AddIdentityServerAuthentication(options =>
    {
       options.Authority = "http://localhost:50289";
       options.RequireHttpsMetadata = false;
       options.ApiSecret = "superweaksecret";
       options.ApiName = "myApi";
       options.EnableCaching = false;

    });

希望有人看到我的錯誤。

如果我錯過了正確的芒果所需的信息或代碼,請告訴我。

親切的問候,羅爾

IdentityServer期望對共享機密進行哈希處理。

new ApiResource("myApi") {
    ApiSecrets = {
            new Secret("superweaksecret".Sha512())
    }
}

暫無
暫無

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

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