2017-09-10 16 views
2

このチュートリアル(https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications)に従うことで、Azureクラウドサブスクリプションに新しいユーザーを追加するためのOAUTH用アプリケーションを作成します。Active Directoryアプリケーションの統合:アクセストークンが無効

チュートリアルで述べたように、私は自分のアプリケーションを作成し、権限を割り当て、秘密鍵を作成しました。

私がやっていることはかなり「標準的」であり、それでも動作していません。私が成功しに行くに

https://login.microsoftonline.com/common/oauth2/authorize?client_id=[CLIENTID]&response_type=code&redirect_uri=[REDIRECT_URI]&prompt=admin_consent 

ログ:

私は手順をお見せしましょう

受諾後Permission Request

これは私が私が私の「最終段階」を構成する私のサービスを取得トークンを取得するための認証

  var content = new StringContent(
      "grant_type=authorization_code" + 
      "&client_id=" + Connectors.Azure.AzureHelper.ID + 
      "&client_secret=" + Connectors.Azure.AzureHelper.Secret + 
      "&code=" + code + 
      "&resource=" + Connectors.Azure.AzureHelper.ID + 
      "&redirect_uri=" + Request.Url.AbsoluteUri.Split('?')[0], 
      Encoding.UTF8, "application/x-www-form-urlencoded"); 

      var resp = await client.PostAsync("https://login.microsoftonline.com/common/oauth2/token", content); 
      var text = await resp.Content.ReadAsStringAsync(); 

      var token = JsonConvert.DeserializeObject<Connectors.Office365.AuthResp>(text); 

token.access_token私は「整形式」のトークンを持っています。私はまた、のような「付与された権限」をたくさん持っているtoken.Scopesで

Directory.AccessAsUser.All Directory.Read.All Directory.ReadWrite.All Group.Read.All Group.ReadWrite.All Member.Read.Hidden User.Read User.Read.All User.ReadBasic.All 

をしかし、私は次のように、最も単純な操作を実行しようとした場合:それはようなものだ

Error on get users

私は有効なトークンを取得していますが、能力はありません! 何が間違っている可能性がありますか?

[コード確認]の[リソース]フィールドに、自分のアプリケーションのIDを入力します。あれは正しいですか? 他に何を試すことができますか?

答えて

0

おそらく私は間違っていたことを知ります。すべては、トークンの要求内の「リソース」フィールドに関するものです。 CODE検証で、私は同じリソースを要求し、その後

https://login.microsoftonline.com/common/oauth2/authorize?client_id=[ID]&response_type=code&redirect_uri=[URL]&prompt=admin_consent&resource=https%3A%2F%2Fgraph.windows.net 

var myUrl = "https://login.microsoftonline.com/common/oauth2/authorize?client_id=" + AzureHelper.ID + "&response_type=code&redirect_uri=" + baseUrl + "/Account/OAuth&prompt=admin_consent&resource=" + Uri.EscapeDataString("https://graph.windows.net"); 

私にこのURLを与える:

は今私のログインURLは、私が https://graph.api.netのトークンをしたいことを指定します

  var content = new StringContent(
      "grant_type=authorization_code" + 
      "&client_id=" + Connectors.Azure.AzureHelper.ID + 
      "&client_secret=" + Connectors.Azure.AzureHelper.Secret + 
      "&code=" + code + 
      "&resource=" + Uri.EscapeDataString("https://graph.windows.net")+ //Connectors.Azure.AzureHelper.ID + 
      "&redirect_uri=" + Request.Url.AbsoluteUri.Split('?')[0], 
      Encoding.UTF8, "application/x-www-form-urlencoded"); 

      var resp = await client.PostAsync("https://login.microsoftonline.com/common/oauth2/token", content); 
      var text = await resp.Content.ReadAsStringAsync(); 

      var token = JsonConvert.DeserializeObject<Connectors.Office365.AuthResp>(text); 

すべてがチャームのように機能します。

私の具体的な問題は、最初のテストで、URLエンコーディングを行わずにRequestパラメータを入れようとしたためです。

奇妙な事実は「REDIRECT_URI」あなたは「要求」

+1

のためにそれを必要としているときに特定のエンコーディングを必要としないため、そのリソースURI 'https://graph.windows.net注意してくださいということです'はAzure AD Graph API用で、' https:// graph.microsoft.com'はMicrosoft Graph API用です。 – juunas

関連する問題