我正在使用 IdentityServer4 并尝试连接 MVC 应用程序进行身份验证。我目前正在使用隐式流程进行工作,但我遇到了我的访问令牌即将过期并且没有对隐式流程的刷新令牌支持的问题。我今天还读到,implicit 是在浏览器变得良好之前为 js 应用程序设计的,并且它不如授权代码流那么安全。
那么。我想让我的应用程序使用授权代码流程。我无法使用 owin 找到任何一种简单的解决方案。我认为有一种很好的、广泛自动化的方法可以让 owin 负责将代码交换为访问令牌等等。经过在线广泛研究后,我发现这段代码似乎在谈论我正在做的事情:
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
...
TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name",
RoleClaimType = "https://schemas.quickstarts.com/roles"
}
...
});
有人有关于让 owin 完成这一切的任何示例或其他信息吗?
相关信息: 身份服务器4 客户端是.Net Framework 4.6
在启动时添加此代码 使用此客户端 GrantTypes
public static ICollection<string> CodeAndClientCredentials => new string[2] { "authorization_code", "client_credentials" };
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme).AddOAuth2Introspection("token", (options) =>
{
var authorityUrl = Configuration["AUTHORITY_URL"];
options.IntrospectionEndpoint = authorityUrl + "/connect/introspect";
options.ClientId = string.IsNullOrEmpty(this.Configuration["AUTH_API_NAME"]) ? "identity_api" : this.Configuration["AUTH_API_NAME"];
options.ClientSecret = string.IsNullOrEmpty(this.Configuration["AUTH_API_SECRET"]) ? "secret" : this.Configuration["AUTH_API_SECRET"];
});