如何使用Owin实现授权码流程

问题描述 投票:0回答:1

我正在使用 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

asp.net oauth-2.0 owin identityserver4 openid-connect
1个回答
0
投票

在启动时添加此代码 使用此客户端 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"];
});
© www.soinside.com 2019 - 2024. All rights reserved.