2017-06-12 14 views
0

私は、Azure Web Appとして、ノードの赤いインスタンスを設定して、選択したAPI Webサービスを作成しました。現在のところ、これはActive Directoryによって保護されており、シンプルで効果的です。しかし、最終的には、一部のAPIを(マイクロソフトのアカウントを介して)公に利用できるようにしたいと考えています。つまり、ウェブアプリケーションへのアクセスをある程度まで開く必要があるため、私は緊張します。Azureのリバースプロキシ/デーモン

私がしたいのは、リバースプロキシサービスのように、制限された一連のURLパスにコールを転送することです。さらに、非ADアカウントへのWebアプリケーションアクセスを提供する必要を避けるために、サービスアカウントに代わって呼び出しを行うデーモンサービスをプロキシに提供したいと考えています。

私はこのような機能がAzure API Managementの一部であることを望んでいましたが、そこではすべてのAPIコールをバックエンドに転送して認証することができます。

上記を達成するための提案を探しています。

答えて

0

2つのAADアプリケーションを作成します。ノード赤のバックエンドWebアプリケーションの場合は1つ、APIMの場合は1つです。バックエンドのアプリケーションURI IDは、 "https://****webappid****.azurewebsites.net/.auth/login/aad/callback"の形式である必要があります。

APIMでは、以下のようにインバウンドポリシーを追加し、環境に関連する値を挿入します。

<policies> 
    <inbound> 
     <!--   Authenticate as the "Azure API Management Service" app in AD and get token to authenticate with backend   --> 
     <!--  Active Directory tenant  --> 
     <set-variable name="tenantid" value="****your AD tenant id here****"/> 
     <!--  Application id of APIM Service app in Active Directory  --> 
     <set-variable name="clientid" value="*** your application id here****"/> 
     <!--  Key from APIM Service app in Active Directory  --> 
     <set-variable name="key" value="*** your application key here****"/> 
     <!--  App ID UR for the backend app in Active Directory  --> 
     <set-variable name="audience" value="https%3A%2F%2F****your backend web app id here****.azurewebsites.net%2F.auth%2Flogin%2Faad%2Fcallback"/> 
     <send-request mode="new" response-variable-name="reply" timeout="10" ignore-error="false"> 
      <set-url>@("https://login.microsoftonline.com/"+context.Variables.GetValueOrDefault<string>("tenantid")+"/oauth2/token")</set-url> 
      <set-method>POST</set-method> 
      <set-header name="Content-Type" exists-action="override"> 
       <value>application/x-www-form-urlencoded</value> 
      </set-header> 
      <set-body>@("grant_type=client_credentials&client_id="+context.Variables.GetValueOrDefault<string>("clientid")+"&client_secret="+context.Variables.GetValueOrDefault<string>("key")+"&resource="+context.Variables.GetValueOrDefault<string>("audience"))</set-body> 
     </send-request> 
     <!--   Extract token from reply   --> 
     <set-variable name="accesstoken" value="@((String)((IResponse)context.Variables["reply"]).Body.As<JObject>()["access_token"])"/> 
      <!--   Add authentication token to request   --> 
      <set-header name="Authorization" exists-action="override"> 
       <value>@("Bearer " + context.Variables.GetValueOrDefault<string>("accesstoken"))</value> 
      </set-header> 
     </inbound> 
     <backend> 
      <forward-request/> 
     </backend> 
     <outbound/> 
    </policies> 
1

APIMには、さまざまなことを行うためのポリシーエンジンがあります。そのうちの1つは、クライアント要求処理の一部として第三者サービスへの呼び出しを行うことです。したがって、SendRequest(https://docs.microsoft.com/en-us/azure/api-management/api-management-advanced-policies#SendRequest)ポリシーをリクエスト処理パイプライン内で使用して、AADを取得してAADトークンを取得することができます。もう少し多くのポリシー式を使用してレスポンスから抽出し、バックエンドにリクエストするために添付します。

+0

実績のある計画です。私はAPIMポリシーを使ってバックエンドで検証される署名付きリクエストトークンを生成することをお手伝いしてきましたが、これは理想的ではないバックエンドインターフェイスを開くことを意味します(有効なトークンなしで何も返さないとしても)。私はあなたのアイデアが好きです。 –

関連する問題