私はadal-jsベースの認証を使用したASP.NET SPAとAzure Active Directory認証を使用したASP.NET Web API Webサイトを持っていますadal.jsと外部Web API(AAD認証付き)を使用したシングルページアプリケーション
両方のウェブサイトは、WebのAPI Webサイトの認証が
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
TokenValidationParameters = new TokenValidationParameters() { ValidAudience = ConfigurationManager.AppSettings["ida:Audience"] },
Tenant = ConfigurationManager.AppSettings["ida:Tenant"]
});
}
}
として設定されている
https://foo.azurewebsites.com/とhttps://fooapi.azurewebsites.com/
を、異なるホスト名に、Azureの上にホストされていると言っています
メインSPA adal.jsのように初期化される:
var config = {
instance: "https://login.microsoftonline.com/",
tenant: "mytenant",
clientId: "client id of foo registration",
postLogoutRedirectUri: "https://foo.azurewebsites.com/",
cacheLocation: "localStorage"
};
authContext = new AuthenticationContext(config);
// Check For & Handle Redirect From AAD After Login
var isCallback = authContext.isCallback(window.location.hash);
authContext.handleWindowCallback();
var errorMessage = authContext.getLoginError();
if (isCallback && !authContext.getLoginError()) {
window.location = authContext._getItem(authContext.CONSTANTS.STORAGE.LOGIN_REQUEST);
}
// Check if View Requires Authentication
if (!authContext.getCachedUser()) {
authContext.config.redirectUri = window.location.href;
authContext.login();
return;
}
テナントはfooとfooapiに対して同じである、クライアントIDは、(各アプリの登録のための1つの)異なります。
foo Webアプリケーションの認証フローは正常に実行されますが、fooapiへのすべてのhttp要求は不正な401を返します。
fooapiをfooの認証に成功させるにはどうすればよいですか?
は、IDトークンを受信し、API呼び出しが行われたときに認証ヘッダで送られるようにするには、AADで暗黙の助成金の流れを使用することができます任意のヒント