我希望有人能指出我正确的方向。
我试图让 javascript 客户端在引用 token 的帮助下与 api 进行通信。我正在使用身份服务器 4。
进展顺利:
登录时,javascript 客户端/webapplicatoin 被路由到身份服务器以进行用户和密码验证
成功后,用户将被路由回 javascript/webapplication 并拥有有效的 IdentityToken
什么不正常:
当 javascript 客户端/web 应用程序调用我的 Api 时,api 会收到请求。然后 api 想用 Identity Server 检查接收到的身份 token 以获取访问 token ,但无法联系服务器并在控制台中出现以下错误:
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",
};
身份服务器 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 期望共享 secret 被散列。
new ApiResource("myApi") {
ApiSecrets = {
new Secret("superweaksecret".Sha512())
}
}
关于javascript - Identity Server 4,API 未经授权调用自省(introspection)端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48694295/