【发布时间】:2021-01-04 10:38:15
【问题描述】:
我正在尝试使用 microsoft graph api,我需要授权码才能使用它。 在我的应用程序中无法将应用程序重定向到 Microsoft 登录站点。
我需要调用它,为此我需要 authProvider:
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(authProvider)
.buildClient();
我正在使用它来创建 authProvider:
UsernamePasswordProvider authProvider = new UsernamePasswordProvider(CLIENT_ID,
Arrays.asList("https://graph.microsoft.com/user.read", "https://graph.microsoft.com/Mail.ReadWrite",
"https://graph.microsoft.com/Calendars.ReadWrite"),
USERNAME, PASSWORD, NationalCloud.Global,
TENANT, CLIENT_SECRET)
使用这个我得到错误:
OAuthProblemException{error='invalid_grant', description='AADSTS65001: The user or administrator has not consented to use the application with ID 'e2bfebf6-cc77-49ec-82a3-28756ad377e5' named 'Milpitas Communications'. Send an interactive authorization request for this user and resource.
跟踪 ID:a2b91757-4849-4680-a089-001831ef7b00 相关 ID:ae894060-a2ce-444c-9889-96fd3cdfaea7
我也尝试使用它来创建 authprovider:
AuthorizationCodeProvider authProvider = new AuthorizationCodeProvider(CLIENT_ID,
Arrays.asList("https://graph.microsoft.com/user.read", "https://graph.microsoft.com/Mail.ReadWrite",
"https://graph.microsoft.com/Calendars.ReadWrite"),
AUTHORIZATION_CODE, REDIRECT_URL, NationalCloud.Global, "common",
CLIENT_SECRET);
要运行上面我需要授权代码,谁能建议我如何在 Spring Boot 应用程序内部获取代码,因为我的应用程序不能有客户端输入(用于身份验证)?
或者是否有其他方法可以使用 IGraphServiceClient 来创建日历事件?
【问题讨论】:
-
请查看documentation,然后试一试。
-
您的用户是否启用了 mfa?您是以管理员身份登录的用户吗?
标签: java azure spring-boot microsoft-graph-api microsoft-graph-calendar