2017-07-22 3 views
2

MS Graphからアクセストークンを取得するために以下のサンプルをダウンロードしました。今度は、カスタムWeb APIからトークンを取得するようにコードを変更しました。 apps.dev.microsoft.comで私はクライアントアプリケーションとAPIを登録しました。私は、コードを実行するとMSALカスタムメッセージにアクセスするためのトークンを取得しようとしたときのエラーメッセージAADSTS65005

Client and server registration in AD

private static async Task<AuthenticationResult> GetToken() 
    { 
     const string clientId = "185adc28-7e72-4f07-a052-651755513825"; 

     var clientApp = new PublicClientApplication(clientId); 

     AuthenticationResult result = null; 

     string[] scopes = new string[] { "api://f69953b0-2d7f-4523-a8df-01f216b55200/Test" }; 

     try 
     { 
      result = await clientApp.AcquireTokenAsync(scopes, "", UIBehavior.SelectAccount, string.Empty); 
     } 
     catch (Exception x) 
     { 
      if (x.Message == "User canceled authentication") 
      { 

      } 
      return null; 
     } 
     return result; 
    } 

は、私は、ダイアログを経由してADにログインエンデバッガで次の例外を取得:

エラー:無効なクライアント メッセージ=「AADSTS65005:Application」をCoreWebAPIAzureADClientがリソースに存在しないスコープ「offline_access」を要求しました。アプリケーションベンダーに問い合わせてください。\ r \ nTrace ID:56a4b5ad-8ca1-4c41-b961-c74d84911300 \ r \ n相関ID:a4350378-b802-4364-8464 -c6fdf105cbf1 \ r ...

ヘルプ日間しようと感謝

Error message

...今日のよう

答えて

2

は、V2エンドポイントには、Microsoftグラフ以外のAPIへのアクセスをサポートしていません。 V2アプリモデルhereの制限事項をご覧ください。あなたが達成しようとしている特定のシナリオについては

Standalone Web APIs

You can use the v2.0 endpoint to build a Web API that is secured with OAuth 2.0. However, that Web API can receive tokens only from an application that has the same Application ID. You cannot access a Web API from a client that has a different Application ID. The client won't be able to request or obtain permissions to your Web API.

、あなたはV1アプリケーションモデル(https://portal.azure.comでアプリを登録)を使用する必要があります。

近い将来、V2アプリはMicrosoft Graph以外の他のAPIを呼び出すことができるようになるので、あなたのシナリオはサポートされますが、今日はそうではありません。このアップデートについては、ドキュメントに目を通す必要があります。

関連する問題