给定的
我有一个身份服务器v4正在运行。Javascript客户端创建一个令牌,并使用生成的访问程序访问asp.core api。
在Asp Core Api中,我有这样的代码,它可以工作
services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication(options =>
{
options.Authority = authority;
options.ApiName = "myApi";
});
在IdentityServer中,我将"myApi“定义为ApiResource。
问题
现在,我想包含另一个api,它是旧的webapi,用.net4.6.1编写的。但是对这个api的所有调用都以401结尾。
对具有相同令牌的核心api使用相同的请求是可行的。
该代码的外观如下所示:
JwtSecurityTokenHandler.InboundClaimTypeMap.Clear();
var options = new IdentityServerBearerTokenAuthenticationOptions
{
Authority = identServer,
RequiredScopes = new List<string>
{
"myApi"
}
};
app.UseIdentityServerBearerTokenAuthentication(options);
但是运行核心项目的令牌在那里不起作用。我能看到的一件事是,我不能在中设置api名称。
目前我正在使用IdentityServer3.AccessTokenValidation Nuget软件包。也许这和问题有关吧?
由于一些依赖问题,我不能使用IdentityServer4.AccessTokenValidation。例如,只有AddOptions用于netcore身份验证构建器
使用jwt.io,我也擦了记号,可以看到t hat myApi是aud
和scope
的一部分。
我还试着不设置需要的作用域,但是我得到了401
不久前,我在身份服务器v3上测试了它的工作原理。
此外,我没有在日志中看到任何验证错误。为了记录api令牌验证的错误,我遗漏了什么?
我遗漏了什么?
当将验证模式设置为我在标识服务器中得到的异常时,更新。
失败: IdentityServer4.Validation.ApiSecretValidator没有找到该名称的API资源。中止失败: IdentityServer4.Endpoints.IntrospectionEndpoint API未经授权调用内省端点。流产。
不巧的是它没有告诉我api是什么.如前所述,"myApi“被定义为ApiResource,但是如何在非核心环境中设置api名称?
发布于 2018-01-23 09:10:05
在对IdentityServer3.AccessTokenValidation
进行身份验证时使用IDS4是可以的,不要担心。
试试这个:
在Startup.cs
of .net4.6.1应用程序中,在IdentityServerBearerTokenAuthenticationOptions
中有一个属性ValidationMode
。将其设置为ValidationMode.Both
,然后重试。
发布于 2018-01-24 09:30:12
原因是当我使用非核心api进行身份验证时,api资源需要有一个秘密,然后api资源名和机密必须在api中设置。
在此:
在IdentityServer中
new ApiResource("myApi", "My Test API")
{
ApiSecrets = new List<Secret>()
{
new Secret("435tgsdgfdg".Sha256()) // This wasnt required when attaching a .net core api
}
}
然后netfx webapi中的配置是:
var options = new IdentityServerBearerTokenAuthenticationOptions
{
ClientId = "myApi",
ClientSecret = "435tgsdgfdg",
RequiredScopes = new List<string> { "myApi"},
Authority = identtityServerUri,
DelayLoadMetadata = true
};
对于asp核心webapi,我既不需要在身份服务器中设置机密,也不需要在客户端设置客户端和客户端秘密。
https://stackoverflow.com/questions/48402813
复制相似问题