目前,我们的cookie 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从持有者令牌获取授权码?
发布于 2017-08-30 11:22:35
正如你所提到的,你正在使用OpenID连接ASP.NET中间件和ADAL .NET来使用Azure AD进行登录,然后在OnAuthorizationCodeReceived OpenID连接通知中调用登录用户身份下的web API。
在这种情况下,您可以使用授权码将其交换为特定资源的访问令牌。
另一方面,当客户端应用程序使用azure AD承载令牌访问您的系统时,没有授权码。在此场景中,如果您希望使用该访问令牌将其交换到另一个资源访问令牌,例如Microsoft Graph,则可以使用OAuth 2.0 On-Behalf-Of flow。OAuth 2.0代表流程服务于应用程序调用服务/web的用例,而服务/web又需要调用另一个服务/web。
有关协议在此方案中如何工作的更多信息,请参阅Authentication Scenarios for Azure AD和On-Behalf-Of flow tutorial。当然,您也可以使用ADAL.NET来执行代表流程,请参阅this code sample。
https://stackoverflow.com/questions/45948827
复制相似问题