我試圖以編程方式將應(yīng)用程序角色添加到Azure Active Directory中的應(yīng)用程序注冊中,我使用以下Microsoft文章作為參考:https : //developer.microsoft.com/zh-cn/graph/docs/api-reference/ beta / api / application_update這是我的代碼:string bearer = "Bearer <token>";string appId = "<guid>";string appEndPoint = "https://graph.microsoft.com/beta/applications/{0}";HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format(appEndPoint, appId));request.Headers.Add("Authorization", bearer);request.Method = "PATCH";request.ContentType = "application/json";string jsonBody = "{\"appRoles\":[{\"allowedMemberTypes\":[\"User\"],\"description\":\"This is a test role\",\"displayName\":\"Test Role\",\"id\":\"fb3d0a97-b19e-4132-bb62-4a0213b37178\",\"isEnabled\":true,\"origin\":\"Application\",\"value\":\"Test\"}]}";request.ContentLength = Encoding.ASCII.GetBytes(jsonBody).Length;using (var streamWriter = new StreamWriter(request.GetRequestStream())){ streamWriter.Write(jsonBody); streamWriter.Flush(); streamWriter.Close();}var responce = request.GetResponse(); // throws 403 Forbiddenvar responseStr = new StreamReader(responce.GetResponseStream()).ReadToEnd();這就是我獲取承載令牌的方式:string domain = "my.domain.com";string appId = "<guid>";string clientSecret = "<secret>";AuthenticationContext authContext = new AuthenticationContext(string.Format("https://login.windows.net/{0}/oauth2/token", domain));ClientCredential creds = new ClientCredential(appId, clientSecret);AuthenticationResult result = await authContext.AcquireTokenAsync("https://graph.microsoft.com/", creds);string bearer = result.AccessToken;我已為我的應(yīng)用程序注冊授予Microsoft文章中指定的所有必需權(quán)限,但我一直收到403響應(yīng)。我還嘗試向我的應(yīng)用程序注冊授予所有可用的權(quán)限,但仍然獲得403,有人知道我在這里做錯了嗎?
https://graph.microsoft.com/beta/applications
慕的地6264312
2021-05-07 15:57:37