我正在使用 azure java SDK,我需要对 azure AAD 进行身份验证,因为项目的业务需要通过两种方式进行身份验证:客户端密码和用户名密码。我已经使用了客户端机密。通过用户名密码进行身份验证时,我遇到此错误:
com.microsoft.aad.msal4j.MsalInteractionRequiredException:AADSTS65001:用户或管理员未同意使用名为“yyy”的 ID 为“xxx”的应用程序。为此用户和资源发送交互式授权请求。 我在 google 上搜索了这个问题,但找不到任何正确的解决方案来解决这个问题。有没有办法解决这个问题?或者我需要为此客户端授予其他权限:
以下是我的示例代码。
public static void main(String[] args) {
SpringApplication.run(StorageApplication.class, args);
AzureResourceManager azure = AzureResourceManager
.authenticate(buildUsernamePasswordCredential(), buildAzureProfile()).withDefaultSubscription();
showContainers(azure);
}
public static UsernamePasswordCredential buildUsernamePasswordCredential() {
return new UsernamePasswordCredentialBuilder().clientId(YOUR_CLIENT_ID).tenantId(YOUR_TENANT_ID)
.username(YOUR_USERNAME).password(YOUR_PASSWORD).build();
}
public static AzureProfile buildAzureProfile() {
return new AzureProfile(AzureEnvironment.AZURE);
// return new AzureProfile(YOUR_TENANT_ID, YOUR_SUBSCRIPTION_ID, AzureEnvironment.AZURE);
}
public static void showContainers(AzureResourceManager azure) {
// TODO
}
下面是使用rest API时的错误 enter image description here