【问题标题】:OAuth bearer token authentication authorisation codeOAuth不记名令牌认证授权码
【发布时间】:2018-02-07 11:37:06
【问题描述】:

目前我们的 ASP.NET MVC 系统使用 OpenIdConnect 和 cookie 身份验证来保护。我们使用 azure Active Directory 启用了 oauth 身份验证流程。

    public void ConfigureAuthOpenIdConnect(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        var cookieAuthenticationOptions = new CookieAuthenticationOptions()
        {
           //...
        };

        app.UseCookieAuthentication(cookieAuthenticationOptions);

        var notifications = new OAOpenIdConnectAuthenticationNotifications();
        var openIdConnectAuthenticationOptions = new OpenIdConnectAuthenticationOptions()
        {
            //...
            Notifications = notifications
        };

        app.UseOpenIdConnectAuthentication(openIdConnectAuthenticationOptions);

        app.UseWindowsAzureActiveDirectoryBearerAuthentication(
           new WindowsAzureActiveDirectoryBearerAuthenticationOptions
           {
               Tenant = ConfigHelper.ClientSettings.TenantName,
               TokenValidationParameters = new TokenValidationParameters
               {
                   ValidAudience = ConfigHelper.ClientSettings.ClientId
               }
           });
    }

现在,当我们通过 OpenIdConnect 进行身份验证时,我们使用 OpenIdConnectAuthenticationOptions 选项上的自定义 Notifications 检索授权代码,这使我们能够使用 ADAL 请求和缓存资源令牌。

当尝试使用 azure AD 不记名令牌访问我们的系统时会出现问题,这种获取和缓存资源令牌的工作流程不存在。

所以我的问题是,如何使用不记名令牌启用此功能?如何像使用 OpenIdConnect 一样请求额外的资源令牌?是否可以使用 ADAL 从不记名令牌中获取授权码?

【问题讨论】:

    标签: c# asp.net oauth azure-active-directory adal


    【解决方案1】:

    正如您所提到的,您正在使用 OpenID Connect ASP.NET 中间件和 ADAL .NET 来使用 Azure AD 进行登录,然后在 OnAuthorizationCodeReceived OpenID Connect 通知中以登录用户的身份调用 Web API。

    在这种情况下,您可以使用授权代码将其交换为特定资源的访问令牌。

    另一方面,当客户端应用程序使用 azure AD 不记名令牌访问您的系统时,没有授权代码。在这种情况下,如果您想使用该访问令牌将其交换为另一个资源的访问令牌,例如 Microsoft Graph,您可以使用OAuth 2.0 On-Behalf-Of flow。 OAuth 2.0 On-Behalf-Of 流程服务于应用程序调用服务/Web API,而后者又需要调用另一个服务/Web API 的用例。

    有关协议在这种情况下如何工作的详细信息,请参阅Authentication Scenarios for Azure ADOn-Behalf-Of flow tutorial。 当然,您可以使用 ADAL.NET 来执行 On-Behalf-Of 流程,请参阅 this code sample

    【讨论】:

    • 代表工作流程是我所需要的。非常感谢!
    猜你喜欢
    • 2016-12-04
    • 1970-01-01
    • 2018-09-22
    • 2018-12-11
    • 2021-01-01
    • 2020-07-09
    • 1970-01-01
    • 2014-12-16
    • 2017-07-25
    相关资源
    最近更新 更多