[英]OAuth bearer token authentication authorisation code
目前,我們的ASP.NET MVC系統使用OpenIdConnect和cookie身份驗證進行保護。 我們使用azure活動目錄啟用了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從持有人令牌獲取授權碼?
如您所述,您使用OpenID Connect ASP.NET中間件和ADAL .NET來使用Azure AD進行登錄,然后在OnAuthorizationCodeReceived
OpenID Connect通知中以登錄用戶身份調用Web API。
在此方案中,您可以使用授權代碼將其交換為特定資源的訪問令牌。
另一方面,當客戶端應用程序使用azure AD承載令牌訪問您的系統時,沒有授權代碼。 在這種情況下,如果要使用該訪問令牌將其交換到另一個資源的訪問令牌(如Microsoft Graph),則可以使用OAuth 2.0 On-Behalf-Of流 。 OAuth 2.0 On-Behalf-Of流服務於應用程序調用服務/ Web API的用例,而服務/ Web API又需要調用另一個服務/ Web API。
有關協議如何在此方案中工作的詳細信息,請參閱Azure AD和On-Behalf-Of流教程的 身份驗證方案 。 當然,您可以使用ADAL.NET來執行On-Behalf-Of流程,請參閱此代碼示例 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.