使用 Microsoft Graph 创建应用程序时 - 权限不足,无法完成操作

While creating an application using Microsoft Graph - Insufficient privileges to complete the operation

我正在尝试使用图表 API 在目录中创建应用程序,但出现以下错误 -

Exception in thread "main" com.microsoft.graph.http.GraphServiceException: Error code: Authorization_RequestDenied
Error message: Insufficient privileges to complete the operation.

POST https://graph.microsoft.com/v1.0/applications
SdkVersion : graph-java/v5.6.0
SdkVersion : graph-java/v5.6.0
[...]

403 : Forbidden
[...]

这是我用来创建图形服务客户端的代码,我将使用它来调用图形 APIs...

private static GraphServiceClient<Request> createGraphClient() {
       
         
        ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
                .clientId(clientId)
                .clientSecret(clientSecret)
                .tenantId(b2cDirectory)
                .build();

        TokenCredentialAuthProvider tokenCredentialAuthProvider = 
            new TokenCredentialAuthProvider(scopes, clientSecretCredential);
        
        GraphServiceClient<Request> graphClient = GraphServiceClient.builder()
                .authenticationProvider(tokenCredentialAuthProvider)
                .buildClient();
        
        return graphClient;
    }

图形客户端已成功创建,现在当我尝试使用以下代码创建应用程序时出现错误,我在上面分享过...

private static void createApplication(GraphServiceClient<Request> graphClient) {
        
        System.out.println("Creating application...");
        
        Application application = new Application();
        application.displayName = "Test v3";
        application.publicClient = new PublicClientApplication();
        
        String appId = graphClient.applications()
                .buildRequest()
                .post(application)
                .appId;
        
        System.out.println("App ID: " + appId);
    }

我非常确定这与授予目录权限以允许图形调用和创建应用程序有关,但是 portal.azure.com UI 我无法从哪里找到它完成了...

有什么建议吗

转到 Azure AD B2C,然后从列表中选择 select 一个随机应用程序,然后转到 API 权限...

Select 我在屏幕截图中显示的那个,然后单击“授予管理员...”并尝试调用 API。