c# - 基本身份验证停用 MS Graph
问题描述
有人可以告诉我,在 2020 年 10 月 13 日之后是否仍然可以使用 MS Graph 的以下身份验证方法?
public static async Task<string> GetUserAccessTokenAsync()
{
String APIToken = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX";
String LoginMail = "xxx@xxx.be";
String LoginWachtwoord = "xxxxxxxxxxx";
UserPasswordCredential userPasswordCredential = new UserPasswordCredential(LoginMail, LoginWachtwoord);
AuthenticationContext authContext = new AuthenticationContext("https://login.microsoftonline.com/diekeure.be");
//Console App for Microsoft Graph
AuthenticationResult token = await authContext.AcquireTokenAsync("https://graph.microsoft.com/", APIToken, userPasswordCredential);
return token.AccessToken;
} /* GetUserAccessTokenAsync */
public static GraphServiceClient GetAuthenticatedClient()
{
GraphServiceClient graphClient = new GraphServiceClient(
new DelegateAuthenticationProvider(
async (requestMessage) => {
string accessToken = await GetUserAccessTokenAsync();
// Append the access token to the request.
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
}));
return graphClient;
} /* GetAuthenticatedClient */
-> await graphClient....
Nuget 包:Microsoft.IdentityModel.Clients.ActiveDirectory v3.19.8
我也不确定这是否行不通
解决方案
您的示例未使用基本身份验证,而是使用 OAuth 密码授权。虽然不是一种非常安全的身份验证机制(因为您必须存储密码),但它与基本身份验证完全不同。
您引用的电子邮件也特定于Exchange Web 服务 (EWS) 等遗留服务。Microsoft Graph不是旧版 API,它是 Microsoft 服务的推荐/现代 REST API。
推荐阅读
- node.js - BCRYPT - 从 Alpine:node 上的源代码构建,并在使用此 docker 文件时导致段错误
- elasticsearch - 在单个请求的同一列中进行弹性搜索多个正则表达式搜索?
- java - eclipse - 包 org.testng 不存在
- angular - Angular 2:自定义管道破坏
- gradle - Intellij Idea 上的一个模块中缺少 Gradle 多模块项目 Source Sets
- javascript - 如何在javascript中的RSA-OAEP算法中使用publicExponent作为65537
- java - 两个java日期之间的区别
- mysql - 实体框架 (MySQL) - 使用两个 dbcontexts 将数据从一个数据库移动到另一个数据库
- c++ - 更好的单元测试方法,耗时太长
- sql - 使用序列插入