2016-11-11 16 views
0

私は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で暗黙の助成金の流れを使用することができます任意のヒント

答えて

0

リクエストが正常に行われるようにするには、Web APIで設定したリソースを使用してトークンを取得する必要があります。トークンをhereから渡して、audのクレームが値ida:Audienceと等しいかどうかを確認することができます。

また、テナント検証を無視していないため、Web APIプロジェクトで設定したテナントからトークンが発行されていることを確認してください。

0
Please configure your web point into endpoints and add it to initialization. 



var endpoints = {`enter code here` 
     "https://yourhost/api": "b6a68585-5287-45b2-ba82-383ba1f60932", 
    }; 
adalAuthenticationServiceProvider.init(
     { 
      // Config to specify endpoints and similar for your app 
      tenant: "52d4b072-9470-49fb-8721-bc3a1c9912a1", // Optional by default, it sends common 
      clientId: "e9a5a8b6-8af7-4719-9821-0deef255f68e", // Required 
      //localLoginUrl: "/login", // optional 
      //redirectUri : "your site", optional 
      endpoints: endpoints // If you need to send CORS api requests. 
     }, 
     $httpProvider // pass http provider to inject request interceptor to attach tokens 
     ); 
関連する問題