[英]First call to AWS_IAM Secured API endpoint is always unauthorized
[英]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.