我正在使用客户端id和密钥进行身份验证。
String url = String.format("https://login.microsoftonline.com/%s/oauth2/token", tenantContext);
AuthenticationContext context = new AuthenticationContext(url, true, ForkJoinPool.commonPool());
AuthenticationResult result = context.acquireToken("https://graph.microsoft.com", new ClientCredential(clientId, clientSecret), null).get();
String token = result.getAccessTokenType() + " " + result.getAccessToken();
我的应用程序已经勾选了所有的权限框,有了上面的令牌,我可以列出用户并遍历他们的驱动器和文件夹。我可以从https://graph.microsoft.com/v1.0/drives/%s/items/%s/content访问内容,它在Location头中返回另一个URL。但是,当我尝试获取该URL时,它返回401未授权。
发布于 2016-12-21 07:11:32
另一个网址也在graph.microsoft.com上吗?如果不是,则需要为该URL获取一个新的身份验证令牌,然后在下载请求中使用它。
就像您已经对graph.microsoft.com执行的操作一样,但使用另一个服务器名称:
AuthenticationResult result = context.acquireToken("https://onedrive-server-name", new ClientCredential(clientId, clientSecret), null).get();
发布于 2016-12-28 11:34:18
请确保您已添加以下权限: Files.ReadAll或Files.ReadWriteAll撤消应用程序访问并重试(https://portal.office.com/account/#apps)
然而,"@microsoft.graph.downloadUrl“应该是开箱即用的,也许你在库设置中禁用了离线访问?
发布于 2017-01-05 15:30:20
我以管理员用户身份登录并从app authentication using Azure AD获取刷新令牌,从而成功地从用户下载了内容
然后可以使用adal4j兑换刷新令牌:
AuthenticationContext context = new AuthenticationContext(url, true, ForkJoinPool.commonPool());
AuthenticationResult result = context.acquireTokenByRefreshToken(refreshToken, new ClientCredential(clientId, clientSecret), "https://graph.microsoft.com", null).get();
String token = result.getAccessTokenType() + " " + result.getAccessToken();
使用此访问令牌,您可以通过:https://graph.microsoft.com/v1.0/drives/{driveid}/items/{itemid}/content
获取文件内容
有一个重要的额外步骤-管理员用户必须被添加为您要访问其内容的用户的站点集合所有者。这在this blog中有描述。
https://stackoverflow.com/questions/41246750
复制相似问题