2016-11-17 14 views
0

サンプルをMultitenant-saas-appと言います。グラフAPIにアクセスするためのアクセストークンを取得しようとしています。AzureAD multiteenant app - "Authorization_RequestDenied": "操作を完了するための十分な権限がありません。

、マルチテナントアプリ用/共通のエンドポイントで認証コードを取得し、認証コードをリダイレクト

private string resourceID = "https://graph.windows.net"; 

string authorizationRequest = String.Format(
       "https://login.microsoftonline.com/common/oauth2/authorize?response_type=code&client_id={0}&resource={1}&redirect_uri={2}&state={3}", 
       Uri.EscapeDataString(ConfigurationManager.AppSettings["ida:ClientID"]), 
       Uri.EscapeDataString("https://graph.windows.net"), 
       Uri.EscapeDataString(this.Request.Url.GetLeftPart(UriPartial.Authority).ToString() + "/Onboarding/ProcessCode"), 
       Uri.EscapeDataString(stateMarker) 
       ); 
return new RedirectResult(authorizationRequest); 

、(/オンボーディング/ ProcessCode)

ClientCredential credential = new ClientCredential(ConfigurationManager.AppSettings["ida:ClientID"], 
                    ConfigurationManager.AppSettings["ida:Password"]); 
       AuthenticationContext authContext = new AuthenticationContext("https://login.windows.net/common/"); 

       //Get token to access grapgh API 
       AuthenticationResult result = await authContext.AcquireTokenByAuthorizationCodeAsync(
        code, new Uri(Request.Url.GetLeftPart(UriPartial.Path)), credential, resourceID); 

       AuthenticationHelper.token = result.AccessToken; 

これは問題なく動作し、テナントのAzureADリソースにアクセスできるアクセストークンを取得します。

ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient(); 
       IPagedCollection<IUser> pagedCollection = await client.Users.ExecuteAsync(); 

ここで、トークンキャッシュからオフラインアクセスのトークンを取得しようとします。今回はテナント用のAuthenticationContextを作成します。 (私も試しました/よくあります) これは私に新しいアクトストークンを静かに聞き取ります。

string resourceID = "https://graph.windows.net"; 
      //Test 
      ClientCredential credential = new ClientCredential(ConfigurationManager.AppSettings["ida:ClientID"], 
                     ConfigurationManager.AppSettings["ida:Password"]); 

      AuthenticationContext authContext = new AuthenticationContext("https://login.microsoftonline.com/mytenant.net"); 

      var auth = await authContext.AcquireTokenAsync(resourceID, credential); 

      var newToken = auth.AccessToken; 
      //Set the token for this session 
      AuthenticationHelper.token = auth.AccessToken; 

その後

エラー= "Authorization_RequestDenied"、私は以前、

ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient(); 
       IPagedCollection<IUser> pagedCollection = await client.Users.ExecuteAsync(); 

としてAPIにアクセスしようと、私は次の例外を取得:完成 に「権限が不十分操作。"

ここで何か間違っていますか?ここで

は私のアプリの権限、

enter image description here

+0

マルチテナントアプリを使用している場合は、テナントの管理者がアプリケーションへのアクセスを許可する必要があります。多分それは問題ですか?それ以上のエラーメッセージの詳細はありますか? – RasmusW

答えて

0

は、AzureのADグラフRESTを使用してユーザーを一覧表示するには、我々は読むすべてのユーザーの基本的なプロフィールまたは読むにすべてのユーザーの完全なプロファイルを必要とあなたがテナントのグローバル管理者でない場合。

そして、あなたはテナントでグローバル管理アクセスもユーザーに残りAPIを一覧表示するには動作するはずのサインインのユーザーとしてディレクトリだった場合。

Azure ADグラフの詳細については、hereを参照してください。

キャッシュの問題では、カスタムキャッシュを提供していないため、プラットフォームに基づいたデフォルトのキャッシュが使用されます。たとえば、.Netアプリケーションを開発していた場合、キャッシュはメモリを使用してオブジェクトを格納しています。したがって、アプリケーションを再起動する前にのみ動作します。

関連する問題