4

「パブリック (認証済み)」としてマークされた Azure API アプリがあり、「API アプリの保護」で説明されているように、関連付けられたゲートウェイで Azure Active Directory ID を設定しています。

次に、同じ Azure Active Directory テナントにネイティブ アプリケーションを作成し、委任されたアクセス許可でゲートウェイにアクセスするためのアクセス許可を追加しました。

ADAL と次のコードを使用すると、認証に成功してアクセス トークンを取得できますが、それを使用して API アプリにアクセスする方法がわかりません。

string Tenant = "[xxx].onmicrosoft.com";
string Authority = "https://login.microsoftonline.com/" + Tenant;
string GatewayLoginUrl = "https://[gateway].azurewebsites.net/login/aad";
string ClientId = "[native client id]";
Uri RedirectUri = new Uri("[native client redirect url]");

async Task<string> GetTokenAsync()
{
  AuthenticationContext context = new AuthenticationContext(Authority);
  PlatformParameters platformParams = new PlatformParameters(PromptBehavior.Auto, null);
  AuthenticationResult result = await context.AcquireTokenAsync(GatewayLoginUrl, ClientId, RedirectUri, platformParams);

  return result.AccessToken;
}

Chrome で取得したものを手動で入力して API アプリをテストしましたが、x-zumo-auth header動作しますが、ADAL を使用して取得したトークンでは動作しません。サンプル コードに記載されているブラウザ フォームも試してみましたが、これは機能しますが、リフレッシュ トークンは得られません。

TokenCacheAPI アプリで ADAL を使用できるようにするには、認証コードをどのように設定する必要がありますか?

4

2 に答える 2

0

AppServiceClient を使用してユーザーを認証し、保護された API アプリ エンドポイントを呼び出すことができます。Microsoft.Azure.AppService SDK (-pre) Nuget パッケージをクライアント プロジェクトにインストールします。

詳細については、GitHub の AzureCards サンプル ( https://github.com/Azure-Samples/API-Apps-DotNet-AzureCards-Sample ) を参照してください。

于 2015-06-02T13:54:30.247 に答える