我在嘗試在沒有用戶的情況下獲取 ms 圖形訪問令牌時遇到問題。
我使用快速入門提供的設定從代碼登錄
IConfidentialClientApplication app;
app = ConfidentialClientApplicationBuilder.Create("<application client ID>")
.WithClientSecret("<application secret>")
.WithAuthority(new Uri("https://login.microsoftonline.com/<tenant ID>"))
.Build();
var result = await app.AcquireTokenForClient(new List<string>() { "https://graph.microsoft.com/.default" })
.ExecuteAsync();
HttpClient sender = new HttpClient();
sender.DefaultRequestHeaders.Add(
"Authorization",
String.Format("Bearer " result.AccessToken)
);
HttpResponseMessage meResult = await sender.GetAsync("https://graph.microsoft.com/v1.0/users/<email adress>/photo/$value");
string context =await meResult.Content.ReadAsStringAsync();
Console.WriteLine("WAAA");
基本上問題是我可以在創建 HTTP 客戶端之前獲取令牌,但是當我想用它來獲取用戶照片時,回應是 401 :( 帶有訊息:401 - Unauthorized: Access is denied due to invalid credentialsAzure 應用程式已授予他們這些權限。

有人能發現我錯過了什么嗎?
uj5u.com熱心網友回復:
你對 Azure 門戶擁有哪些權限?我猜你現在Delegated permission只有。
你應該有User.Read.All Application permission和后記需要添加授予管理員同意。它應該如下所示:
您可以在我們的
設定權限后,您可以獲得以下輸出:
Output:

Postman Test Result:

Azure profile Pciture:

注意:您的背景關系是必需的,
Application permission但似乎您Delegated Permission只有。
希望這會有所幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/347646.html
