ฉันกำลังพยายามอ่านคุณสมบัติผู้ใช้จากกราฟ ms ภายในฟังก์ชัน Azure สำหรับการตรวจสอบสิทธิ์ ฉันใช้คลาส DefaultAzureCredential จาก Azure.Identity
การเข้าถึงด้วย Shared Token Cache Credential ในเครื่องและ Managed Identity Credential ใน Azure นั้นไม่มีปัญหา! ฉันต้องการใช้ Visual Studio Code Credential แต่ฉันได้รับ Authorization_RequestDenied! สิทธิ์ไม่เพียงพอที่จะดำเนินการข้อความแสดงข้อผิดพลาดให้เสร็จสิ้นเมื่อฉันเรียกใช้กราฟ API
ดูเหมือนว่าปัญหาจะเป็นโทเค็นการเข้าถึงที่ฉันได้รับพร้อมกับ VS Code Credential บัญชีผู้ใช้เป็นบัญชีเดียวกับที่ฉันใช้กับ Shared Token Cache Credential
มีความคิดอะไรบ้าง? ขอบคุณ
รหัส:
DefaultAzureCredentialOptions options = new DefaultAzureCredentialOptions();
options.VisualStudioCodeTenantId = Environment.GetEnvironmentVariable("Debug_VisualStudioCodeTenantId");
var credential = new DefaultAzureCredential(options);
token = credential.GetToken(
new Azure.Core.TokenRequestContext(
new[] { "https://graph.microsoft.com/.default" }));
accessToken = token.Token;
var graphServiceClient = new GraphServiceClient(
new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage
.Headers
.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
return Task.CompletedTask;
}));
var users = await graphServiceClient.Users.Request().GetAsync(); // throw the forbidden exception
ข้อยกเว้น: รหัส: Authorization_RequestDenied\r\nข้อความ: สิทธิ์ไม่เพียงพอที่จะดำเนินการให้เสร็จสิ้น\r\nข้อผิดพลาดภายใน:\r\n\tข้อมูลเพิ่มเติม:\r\n\tวันที่: 2021-04-20T08: 02:23\r\n\trequest-id: ...\r\n\tclient-request-id: ...\r\nClientRequestId: ...\r\n
https://graph.microsoft.com/User.Read.All
เป็นขอบเขตแทน .default ได้ นั่นอาจจบลงด้วยข้อผิดพลาด:\ - person juunas   schedule 20.04.2021