我按照本教程(https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications)創建OAuth應用程序以將新用戶添加到我的Azure雲訂閱。Active Directory集成應用程序:訪問令牌無效
正如本教程所述,我創建了我的應用程序,分配了權限並執行了創建的密鑰。
我在做什麼是相當「標準」,但它仍然不起作用。
讓我告訴步驟:
https://login.microsoftonline.com/common/oauth2/authorize?client_id=[CLIENTID]&response_type=code&redirect_uri=[REDIRECT_URI]&prompt=admin_consent
登錄我成功地去:
此驗收後,我讓我的服務,我撰寫我的「最後一步」,在代碼驗證以檢索令牌
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);
In 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
但如果我嘗試以執行類似操作最簡單:
這就像我正在檢索有效令牌,但沒有功能! 什麼可能是錯的?
在「代碼確認」的資源字段中,輸入了我的應用程序的ID。那是對的嗎? 我還可以嘗試什麼?
待辦事項需要特定的編碼,資源URI'https://graph.windows.net '適用於Azure AD Graph API,而'https:// graph.microsoft.com'適用於Microsoft Graph API。 – juunas