想知道Azure Active Directory/Angular 2/Adal專家是否可以提供幫助。Angular 2 SPA Azure Active Directory JWT問題
我的設置如下:有三個應用程序註冊的Azure Active Directory。一個用於Web API,一個用於WPF應用程序,另一個用於Angular 2應用程序。
用於Web API的配置看起來相當標準:
<add key="ida:Tenant" value="<tenant>" />
<add key="ida:Audience" value="<ResourceURI>" />
爲WPF應用程序(這是工作)的配置
<add key="ida:AADInstance" value="https://login.windows.net/{0}"/>
<add key="ida:Tenant" value="<tenant>" />
<add key="ida:RedirectUri" value="<some redirect>" />
<add key="ida:ClientId" value="<client id as configured in Azure>" />
<add key="ApiResourceId" value="<The WEB API resource URI>"/>
<add key="ApiBaseAddress" value="<The base address of the Web API>"/>
這裏是角2配置與NG2阿達爾和ADAL.js
public get adalConfig(): any {
return {
instance: 'https://login.windows.net/',
tenant: '<tenant>',
clientId: '<client id configured for Angular App in Azure AD>',
redirectUri: '<Angular 2 app Url>',
extraQueryParameter: 'nux=1',
postLogoutRedirectUri: '<Angular 2 app Url>',
cacheLocation: 'localStorage',
loginResource: '<Web API Resource Uri>',
};
angular和WPF都能夠在AAD中登錄並獲得一個令牌。
問題在於Angular 2應用程序。
WPF應用程序(有效)可以正確登錄到Azure Active Directory,並且Web API應用程序接受JWT(令牌),其餘服務可以成功調用。
當WPF應用程序經由microsoft.online.com/xxxxxxx登錄其提供一個令牌,其包括這樣的權利要求:
Header
{
typ: "JWT",
alg: "RS256",
x5t: "_UgqXG_tMLduSJ1T8caHxU7cOtc",
kid: "_UgqXG_tMLduSJ1T8caHxU7cOtc"
}
Payload
{
aud: "<web api resource uri>",
iss: "https://sts.windows.net/1afea43f-3f0b-4a86-ad29-d444b80d2c91/",
iat: 1488889876,
nbf: 1488889876,
exp: 1488893776,
acr: "1",
aio: "NA",
amr: [
"pwd"
]
}
而對於此之一 - AUD參數是Web API資源URI 。和它完美的作品
我使用NG2阿達爾這是一個包裝周圍adal.js對角2.所以當它的角2個應用程序日誌收到令牌,看起來像這樣:
Header
{
typ: "JWT",
alg: "RS256",
x5t: "_UgqXG_tMLduSJ1T8caHxU7cOtc",
kid: "_UgqXG_tMLduSJ1T8caHxU7cOtc"
}
Payload
{
aud: "<angular app client id>",
iss: "https://sts.windows.net/1afea43f-3f0b-4a86-ad29-d444b80d2c91/",
iat: 1488888955,
nbf: 1488888955,
exp: 1488892855,
amr: [
"pwd"
]
}
所以主要區別 - ,我想爲什麼我得到錯誤是在WPF應用程序令牌中的aud參數包含正確的受衆並且正在接受,而Angular應用程序正在從其令牌返回客戶端ID它與Web API中的資源URI不匹配,因此給我一個401錯誤 - 授權有蜜蜂n拒絕此請求
有誰知道如何配置NG2-ADAL(adal.js)以使Azure活動目錄發出包含JWT的aud參數中的資源URI的令牌?
我已經嘗試了loginResource參數和端點集合,但沒有運氣。
非常感謝......
不確定爲什麼我被投票下來。我試圖清楚地說明我所嘗試過的,有效的,我認爲的問題以及潛在的解決方案。 –