2017-01-11 11 views
0

私は、Azure中国のアクティブディレクトリとWebアプリケーションを統合し、紺碧の中国の環境に展開しています。エンドポイントは、紺碧の中国では通常の紺碧の環境とはまったく異なります。 Web APIにAADInstance https://login.chinacloudapi.cn/を指定する方法を知りたいですか?Web APIに別のAADInstanceを指定する方法は?

ウェブアピStartup.Auth.cs

app.UseWindowsAzureActiveDirectoryBearerAuthentication(
    new WindowsAzureActiveDirectoryBearerAuthenticationOptions 
    { 
     Tenant = ConfigurationManager.AppSettings["ida:Tenant"], 
     TokenValidationParameters = new TokenValidationParameters 
     { 
      ValidAudience = ConfigurationManager.AppSettings["ida:Audience"] 
     }, 
    }); 

ウェブアピのWeb.Config

<add key="ida:Tenant" value="directoryname.partner.onmschina.cn" /> 
<add key="ida:Audience" value="https://directoryname.partner.onmschina.cn/AppName" /> 
<add key="ida:ClientID" value="…" /> 
<add key="ida:Password" value="…" /> 

これは、MVCアプリケーションのため

MVCを行うことができますStartup.Auth.cs

ApplicationDbContext db = new ApplicationDbContext(); 

app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); 

app.UseCookieAuthentication(new CookieAuthenticationOptions()); 

app.UseOpenIdConnectAuthentication(
    new OpenIdConnectAuthenticationOptions 
    { 
     ClientId = clientId, 
     Authority = Authority, 
     PostLogoutRedirectUri = postLogoutRedirectUri, 

     Notifications = new OpenIdConnectAuthenticationNotifications() 
     { 
      // If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away. 
      AuthorizationCodeReceived = (context) => 
      { 
       var code = context.Code; 
       ClientCredential credential = new ClientCredential(clientId, appKey); 
       string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value; 
       AuthenticationContext authContext = new AuthenticationContext(Authority, new ADALTokenCache(signedInUserID)); 
       AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(
       code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId); 

       return Task.FromResult(0); 
      } 
     } 
    }); 

MVCのWeb.Config異なる主権クラウドを使用するアプリケーションについて、ここで注意すべき

<add key="ida:ClientId" value="…" /> 
<add key="ida:AADInstance" value="https://login.chinacloudapi.cn/" /> 
<add key="ida:ClientSecret" value="…" /> 
<add key="ida:Domain" value="directoryname.partner.onmschina.cn" /> 
<add key="ida:TenantId" value="…" /> 
<add key="ida:PostLogoutRedirectUri" value="https://localhost:44300/" /> 
+0

ああ、私はあなたが今尋ねているものを見ます。表示する例では、2つの非常に異なるパッケージを使用しています。 1つはトークン(Web Api)を作成するためのもので、もう1つはトークン(MVC)を検証するためのものです –

答えて

0

いくつかのこと:

  1. 各ソブリンクラウド(中国、米国県知事、ドイツ、Worldwide)は、AADの独自のインスタンスです。アプリケーションをトークンエンドポイントに認証するには、その環境用に個別に登録されたアプリケーションが必要です。世界中に登録され、「https://login.microsoftonline.com」と呼ぶことができるアプリケーションは、一般に、「https://login.chinacloudapi.cn」のような他のエンドポイントに対して認証することはできません。
  2. クライアントアプリケーションでは、認証しようとしている環境のすべての正しいパラメータを使用してトークンを要求する必要があります。
    • 正しいログインエンドポイントを使用しています(たとえば、中国のAAD Graph APIにトークンを取得する場合は、 https://login.chinacloudapi.net
    • 、あなたが正しい回答のURLを使用している環境
    • のために登録されている正しいクライアントIDを、使用
    • https://graph.chinacloudapi.cn/(その環境用の正しいリソース識別子を使用して、その環境のために登録されている他の構成
  3. ウェブAPIとして、受信しているアクセストークンがそのAAD環境に対応する署名鍵で署名されていることを確認する必要があります。各AAD環境には独自の署名キーがあり、OWINのようなライブラリを使用してトークンの内容を確認する場合は、正しいメタデータエンドポイントを指すようにOWINの設定を更新する必要があります。

これは、あなたの質問に答えるのに役立ちます。さらに具体的なフォローアップの質問がある場合は、下記にコメントしてください。

+0

あなたの問題を解決できてうれしいです:) –

+0

ありがとう、ありがとうございます。私はあなたの助けに感謝します。 – Venky

0

はい、メタデータのエンドポイントを設定する必要があります。 WindowsAzureActiveDirectoryBearerAuthenticationExtensions.csで説明したように、私はweb.config の項目を追加し、Startup.AuthでMetadataAddressを設定しました。cs MetadataAddress = $ "https:// {ConfigurationManager.AppSettings" "ida:AADInstance"}}/{ConfigurationManager.AppSettings ["ida:Tenant"]}/federationメタデータ/ 2007-06/federationmetadata.xml "

これで機能します。

関連する問題