Azure客户端凭据提供程序抛出错误“/me请求只能使用委派身份验证流
创始人
2024-09-29 20:00:46
0

该错误通常是因为尝试使用客户端凭据进行Microsoft Graph API调用时使用了错误的身份验证流程。客户端凭据只能与应用程序的令牌进行身份验证,而不能使用用户令牌。因此,必须更改代码以使用正确的身份验证流程。

以下是一个示例,演示如何使用Microsoft Graph SDK和客户端凭据进行身份验证:

string clientId = "";
string clientSecret = "";
string tenantId = "";

ConfidentialClientApplication app = new ConfidentialClientApplication(
    clientId,
    $"https://login.microsoftonline.com/{tenantId}/",
    new ClientCredential(clientSecret),
    null,
    null);

ClientCredentialProvider authProvider = new ClientCredentialProvider(app);

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

var user = await graphClient.Me.Request().GetAsync();

请注意,上述代码使用ClientCredentialProvider类而不是DelegateAuthenticationProvider类。这是因为我们使用的是客户端凭据进行身份验证,而不是用户令牌。

如果您正在使用自己的HTTP请求调用Microsoft Graph API,则需要在请求标头中包括身份验证标记。下面是一个示例:

string clientId = "";
string clientSecret = "";
string tenantId = "";

string authUrl = $"https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token";

HttpClient client = new HttpClient();

List> postData = new List>();
postData.Add(new KeyValuePair("client_id", clientId));
postData.Add(new KeyValuePair("client_secret", clientSecret));
postData.Add(new KeyValuePair("grant_type", "client_credentials"));
postData.Add(new KeyValuePair("scope", "https://graph.microsoft.com/.default"));

FormUrlEncodedContent content = new FormUrlEncodedContent(postData);

HttpResponseMessage

相关内容

热门资讯

有挂透视!aapoker插件下... 有挂透视!aapoker插件下载,德州透视是真的假的,手段教程(有人有挂)-哔哩哔哩1、不需要AI权...
详细透视!werplan怎么作... 详细透视!werplan怎么作必弊!其实有辅助插件(有挂解惑)-哔哩哔哩暗藏猫腻,小编详细说明wer...
了解透视!德州局怎么透视,wp... 了解透视!德州局怎么透视,wpk官网下载链接,策略教程(有挂透视)-哔哩哔哩1、wpk官网下载链接免...
总结透视!德州局透视脚本免费版... 总结透视!德州局透视脚本免费版下载手机版!原来一直都是有辅助教程(有挂教学)-哔哩哔哩德州局透视脚本...
开挂透视!德普之星辅助工具如何... 开挂透视!德普之星辅助工具如何设置,aapoker真的假的,积累教程(存在有挂)-哔哩哔哩1、德普之...
分享透视!cloudpoker... 分享透视!cloudpoker外开挂!切实是真的有辅助教程(有挂技巧)-哔哩哔哩暗藏猫腻,小编详细说...
推荐透视!pokermaste... 推荐透视!pokermaster辅助器,wepoker有插件吗,积累教程(有挂猫腻)-哔哩哔哩运po...
详情透视!拱趴大菠萝有什么挂!... 详情透视!拱趴大菠萝有什么挂!其实是有辅助软件(有挂分享)-哔哩哔哩1、超多福利:超高返利,海量正版...
详情透视!wepoker游戏安... 详情透视!wepoker游戏安装教程,wejoker透视方法,手册教程(存在有挂)-哔哩哔哩1、许多...
解迷透视!wepoker透视有... 解迷透视!wepoker透视有吗!原来真的是有辅助方法(有挂方略)-哔哩哔哩1、wepoker透视有...