在具有内置身份验证的 Azure 应用服务中运行的 Java Web 应用中获取用户显示名称

问题描述 投票:0回答:0

所以我设置了一个 azure 应用程序服务,带有 tomcat 的 java,启用了身份验证(因此它为我创建了一个应用程序注册)。构建我的 hello world Java Web 应用程序 war 文件并将其部署到应用程序服务。站点工作正常,可以登录并查看我的 hello world。现在我想打印出经过身份验证的用户的显示名称。所以我在 Java 应用程序中包含了 Microsoft graph 和 msal4j ...有人可以指点我一个可行的代码示例吗?我在 java 中复制了这个 node example 并且得到了

com.microsoft.aad.msal4j.MsalInteractionRequiredException: AADSTS50013: Assertion failed signature validation. [Reason - Key was found, but use of the key to verify the signature failed

final String tenantId = System.getenv("WEBSITE_AUTH_OPENID_ISSUER").split("/", 5)[3];

final IClientCredential credential = ClientCredentialFactory
    .createFromSecret(System.getenv("MICROSOFT_PROVIDER_AUTHENTICATION_SECRET"));

final ConfidentialClientApplication clientApplication = ConfidentialClientApplication
    .builder(System.getenv("WEBSITE_AUTH_CLIENT_ID"), credential)
    .authority("https://login.microsoftonline.com/" + tenantId)
    .build();

final Set<String> scopes = new HashSet<>(Arrays.asList("https://graph.microsoft.com/.default"));

final String accessToken = request.getHeader("x-ms-token-aad-access-token");

final OnBehalfOfParameters params = OnBehalfOfParameters
    .builder(scopes, new UserAssertion(accessToken)).build();

final CompletableFuture<IAuthenticationResult> future = clientApplication.acquireToken(params);

final IAuthenticationResult authenticationResult = future.get();

return authenticationResult.accessToken();
azure-web-app-service msal
© www.soinside.com 2019 - 2024. All rights reserved.