我使用Identity Server 4设置了身份验证服务器,但无法在.Net框架4.5.2内置的WebApi中使用Identity Server 4发行的令牌。尽管我能够保护Core内置的Web Api。
任何人都可以指导我如何执行此操作,因为我们的.Net Api是旧版应用程序,因此我们无法将其转换为Core API。
提前感谢。
最好,塔伦·奥赫里
我相信您正在寻找可以在WebApi中验证令牌的中间件。我几天前遇到这个问题,因为它是在.NET Core中开发的,因此无法安装IdentityServer4.AccessTokenValidation NuGet软件包。
所以我找到了解决方法。您可以安装IdentityServer3.AccessTokenValidation NuGet软件包以在WebApi中验证您的ID4令牌。请参阅下面的示例代码以获取更多详细信息:
Startup.cs
public void Configuration(IAppBuilder app)
{
IdentityServerBearerTokenAuthenticationOptions options = new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "Identity Server 4 base URL",
AuthenticationType = "Bearer",
RequiredScopes = "Scopes (space separated)"
};
app.UseIdentityServerBearerTokenAuthentication(options);
}
注意:UseIdentityServerBearerTokenAuthentication
中间件将验证您的请求。希望这可以帮助您解决问题。