5

我有一個應用程序,我們將其命名爲'Apple',它在Azure AD上註冊並擁有Azure Management API應用程序的委派權限。當被請求這個應用程序時,它會創建天藍色的資源。存儲帳戶自動和這工作正常。應用程序之間的Azure AD身份驗證

我有另一個應用程序是MVC應用程序,它也註冊了相同的AD租戶。第二個應用程序使用以下代碼檢索訪問令牌:

var clientCredentials = new ClientCredential(ConfigurationManager.AppSettings["AD_ClientID"], ConfigurationManager.AppSettings["AD_Client_AccessKey"]); 
var authContext = new AuthenticationContext(string.Format(ConfigurationManager.AppSettings["AD_Tenant_Login_Url"], ConfigurationManager.AppSettings["AD_Tenant_Id"]));    
var result = authContext.AcquireTokenAsync(ConfigurationManager.AppSettings["AD_Resource"], clientCredentials); 
if (result == null) 
{ 
    throw new InvalidOperationException("Could not get the token"); 
} 
return result.Result; 

結果是具有不同屬性的訪問令牌。現在,第二個應用程序會檢索訪問令牌,並訪問資源蘋果,然後將其傳遞到授權標頭中的Apple應用程序。

Authorization:bearer TokenString 

Apple應用程序將Authorize屬性添加到控制器。 應用程序配置了Owin通過OAuth應用程序與下面的代碼

public void ConfigureAuth(IAppBuilder app) 
    { 
     app.UseWindowsAzureActiveDirectoryBearerAuthentication(
      new WindowsAzureActiveDirectoryBearerAuthenticationOptions 
      { 
       Tenant = ConfigurationManager.AppSettings["ida:Tenant"], 
       TokenValidationParameters = new TokenValidationParameters 
       { 

        ValidAudience = ConfigurationManager.AppSettings["ida:Audience"] 
       }, 
      }); 
    } 

請注意,訪問令牌是從第二個應用程序利用自身的AppId和祕密密鑰檢索;而另一個(Apple)應用程序使用其自己的AppId和密鑰來驗證令牌。

所以我的問題是,蘋果應用總是返回401未授權代碼

+0

雖然我沒有收到任何回覆,我應該更換標籤,建議嗎? –

+0

我在[這裏]關注此主題(https://social.msdn.microsoft.com/Forums/azure/en-US/af1f1ddc-649b-4b35-9e16-ced582380e6c/azure-ad-authentication-between-applications ?forum = WindowsAzureAD),請讓我知道你是否有任何問題。 –

+0

@費雪,謝謝你再次捕捉到我......我回復了你的回答... –

回答

0

上述之外,問題的答案是,在第二令牌的確認過程中的資源ID(令牌請求期間)和目標對象ID(應用程序)不匹配。保持這些解決了問題。

然後,我遇到了另一個問題,這是我所描述here

看來,如果我有新的Azure的門戶網站(目前還處於預覽版)工作,AD token不包括JWT令牌"Roles"場。如果我在舊門戶中按照相同的步驟配置應用程序,則AD在JWT令牌和場景中包含"Roles"字段,並按預期執行。

我應該避免至少使用Azure新的入口預覽功能!

相關問題