Identity Server 4,未经授权调用自省端点的 API

Roe*_*oel 8 javascript api jwt openid-connect identityserver4

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

我试图让 javascript 客户端在参考令牌的帮助下与 api 进行通信。我正在使用身份服务器 4。

一切正常:

登录时,javascript 客户端/webappplicatoin 被路由到身份服务器以进行用户和密码验证成功后,用户将被路由回 javascript/web 应用程序并具有有效的 IdentityToken

什么不正常:

当 javascript 客户端/网络应用程序调用我的 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.
Run Code Online (Sandbox Code Playgroud)

很明显,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",
};
Run Code Online (Sandbox Code Playgroud)

身份服务器 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"
            }
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

Api资源定义:

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

在配置服务中,我将它们全部添加到容器中:

// 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>();
Run Code Online (Sandbox Code Playgroud)

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;

    });
Run Code Online (Sandbox Code Playgroud)

希望有人看到我的错误。

如果我错过了正确 awnser 所需的信息或代码,请告诉我。

亲切的问候,罗尔

Sco*_*ady 5

IdentityServer 期望对共享秘密进行哈希处理。

new ApiResource("myApi") {
    ApiSecrets = {
            new Secret("superweaksecret".Sha512())
    }
}
Run Code Online (Sandbox Code Playgroud)