使用 msgraph-sdk-java 列出 azure 广告

List azure ad using msgraph-sdk-java

我正在尝试将当前用户从 azure 活动目录中引入如下:

            final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
                .clientId("client_id")
                .clientSecret("secret")
                .tenantId("tenat_id")
                .build();

        final TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(Arrays.asList("https://graph.microsoft.com/User.Read.All"), clientSecretCredential);

        final GraphServiceClient graphClient =
          GraphServiceClient
            .builder()
            .authenticationProvider(tokenCredentialAuthProvider)
            .buildClient();

        final User me = graphClient.me().buildRequest().get();

我收到以下错误:

java.io.IOException: java.util.concurrent.ExecutionException: com.microsoft.aad.msal4j.MsalServiceException: AADSTS70011: The provided request must include a 'scope' input parameter. The provided value for the input parameter 'scope' is not valid. The scope openid profile offline_access https://graph.microsoft.com/User.Read.All is not valid. Trace ID: b035aaec-9c8a-4728-a237-6d63738adb00 Correlation ID: de389e03-9d91-4f4b-aacf-449aa8fac460 Timestamp: 2021-04-05 21:44:43Z

知道我可能遗漏了什么吗?????

您正在使用此处的 client credential flow

The value passed for the scope parameter in this request should be the resource identifier (application ID URI) of the resource you want, affixed with the .default suffix.

scope 在你的问题中应该是 https://graph.microsoft.com/.default