azure-active-directory - 如何在安装在不同组织的 MS Teams Bot 中接收用户照片?
问题描述
根据文档https://docs.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-beta - 为了获取用户照片,我们需要执行 HTTP 请求https:// /graph.microsoft.com/beta/users/{userId}/photo/$value提供访问令牌和用户 ID。使用客户端凭据流,我可以接收特定组织(租户 ID)的访问令牌,例如:
public static String getAppAccessToken(String[] scopes) {
ConfidentialClientApplication cca;
try {
cca = ConfidentialClientApplication.builder(applicationId, ClientCredentialFactory.createFromSecret(applicationSecret))
.authority("https://login.microsoftonline.com/<<tenantId>>/")
.build();
} catch (MalformedURLException e) {
return null;
}
Set<String> scopeSet = Set.of(scopes);
ClientCredentialParameters clientCredentialParam = ClientCredentialParameters.builder(
scopeSet)
.build();
CompletableFuture<IAuthenticationResult> future = cca.acquireToken(clientCredentialParam);
return future.join().accessToken();
}
但是以这种方式接收的访问令牌只允许接收组织用户的照片,该组织的租户 ID 与在 Azure Active Directory 应用程序注册中注册的机器人应用程序的租户 ID 相同。是否可以使用客户端凭据流令牌从安装了我的机器人的其他组织接收用户的照片?在这种情况下,我收到:
{
"error": {
"code": "UnknownError",
"message": "{\"error\":{\"code\":\"NoPermissionsInAccessToken\",\"message\":\"The token contains no permissions, or permissions can not be understood.\",\"innerError\":{\"oAuthEventOperationId\":\"d90f2331-a22a-44d5-889e-c0c14ea9129e\",\"oAuthEventcV\":\"n+NecjM040KWn+2G+e5oFQ.1\",\"errorUrl\":\"https://aka.ms/autherrors#error-InvalidGrant\",\"requestId\":\"0b6bb579-94a7-47ac-8ff9-26ee893e5cb0\",\"date\":\"2021-01-28T00:57:52\"}}}",
"innerError": {
"date": "2021-01-28T00:57:52",
"request-id": "0b6bb579-94a7-47ac-8ff9-26ee893e5cb0",
"client-request-id": "0b6bb579-94a7-47ac-8ff9-26ee893e5cb0"
}
}
}
解决方案
我当然不是身份验证专家,但这里有两个建议可供参考,以防万一:
“https://login.microsoftonline.com/<>/” -> 使用“组织”而不是租户 ID
检查您正在使用的范围(您没有列出您正在尝试的内容,所以可能是这样)
推荐阅读
- c - 使用 \".*?\"(?!') 的正则表达式执行函数“regexec”时出现分段错误
- ruby-on-rails - Tinymce 无法在生产管理员中工作(rails)
- unit-testing - npm run serve 时 vue-cli jest 设置问题
- graphql - 如何通过 Websocket 协议处理 GraphQL 中的文件上传?
- c++ - 如何为类调试对 vtable 的未定义引用?
- python - 导入标签编码器 sklearn
- powershell - 显示来自 Get-Credentials 的值
- freerdp - 无法为 Linux 远程会话设置屏幕分辨率
- android - 如何将字符串转换为字节以传递到 byteArray
- unity3d - 如何将 Unity.Object 转换为泛型类成员?