【问题标题】:How to get Azure ad Group Information based on Access token in Spring boot?如何在 Spring Boot 中根据访问令牌获取 Azure 广告组信息?
【发布时间】:2019-10-02 16:46:48
【问题描述】:

我正在使用 Angular 8 和 Spring Boot,这两个应用程序都部署在 azure 应用服务中并使用广告身份验证。在 ui 中,我使用 adal-angular4 lib 来获取令牌详细信息。 使用它,我可以使用此方法获取访问令牌 .acquireToken('') 来访问我的 spring 应用程序。 它工作正常,我可以得到响应。但我想在 Spring 应用程序中使用该访问令牌获取 用户详细信息、组信息和角色详细信息。我不知道如何获得这些细节。请任何人帮助我。谢谢

【问题讨论】:

标签: azure spring-boot azure-active-directory


【解决方案1】:

如果要获取 Azure AD 组或 Azure AD 用户的详细信息,可以使用 Microsoft Graph API。例如

使用 Azure 门户注册新应用程序

  1. 使用工作或学校帐户登录 Azure 门户,或者 个人 Microsoft 帐户。

  2. 如果您的帐户允许您访问多个租户,请在右上角选择您的帐户,并将您的门户会话设置为您想要的 Azure AD 租户。

  3. 在左侧导航窗格中,选择 Azure Active Directory 服务,然后选择应用注册 > 新注册。

为您的应用程序配置所需的 Microsoft Graph 权限 [![在此处输入图片描述][3]][3]

代码

     # install package microsoft-graph, microsoft-graph-core, microsoft-graph-auth
        ClientCredentialProvider authProvider = new ClientCredentialProvider(CLIENT_ID, SCOPES, CLIENT_SECRET, TENANT_GUID, NATIONAL_CLOUD);

IGraphServiceClient graphClient = GraphServiceClient
                .builder()
                .authenticationProvider(authProvider)
                .buildClient();

# get group
Group group = graphClient.groups("object")
    .buildRequest()
    .get();
#
IUserCollectionPage users = graphClient.users()
    .buildRequest()
    .get();

更多详情请参考

https://docs.microsoft.com/en-us/graph/sdks/sdk-installation?context=graph%2Fapi%2F1.0&view=graph-rest-1.0

https://docs.microsoft.com/en-us/graph/overview-major-services

【讨论】:

    猜你喜欢
    • 2021-11-12
    • 2015-05-26
    • 1970-01-01
    • 2016-08-15
    • 2019-11-11
    • 1970-01-01
    • 2016-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多