gpt4 book ai didi

c# - 使用 AAD 帐户以外的 ms live 帐户时,Azure AD 身份验证失败

转载 作者:行者123 更新时间:2023-12-03 04:50:38 25 4
gpt4 key购买 nike

我尝试从他们的 Microsoft 实时帐户读取用户数据。我写的代码如下:

    public void GetUserData(){
var authContext = new AuthenticationContext("https://login.microsoftonline.com/common/");
var result = _authenticationContext
.AcquireTokenAsync("https://graph.microsoft.com", "<my client/app ID>", "<redirect URI>", new PlatformParameters(PromptBehavior.RefreshSession))
.Result;
var accessToken = result.AccessToken;

var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer",accessToken);
var userResponse = httpClient.GetStringAsync("https://graph.microsoft.com/beta/me/").Result;

//DO SOMTHING WITH DATA
}

当我使用我的 AAD 凭据时,我的代码工作正常,但当我使用我的个人帐户时,它会出现以下错误。

AADSTS50020: User account '[email protected]' from identity provider 'live.com' does not exist in tenant 'Default Directory' and cannot access the application 'XXXXXXXXXXXXXXXXX' in that tenant. The account needs to be added as an external user in the tenant first. Sign out and sign in again with a different Azure Active Directory user account.

这是屏幕截图:

enter image description here

类似于this question 。有人可以帮我吗?

最佳答案

v1 端点要求用户是目录中的成员。

您可能应该为此使用 v2.0 端点:https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-appmodel-v2-overview

如果您希望只有消费者 MS 帐户登录,您可以将授权 URL 指定为:

https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize

关于c# - 使用 AAD 帐户以外的 ms live 帐户时,Azure AD 身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47587560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com