Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.25k stars 1.93k forks source link

[QUERY] Authenticating Azure SDK for API management resource with free subscription #37631

Open adhithya-raja opened 7 months ago

adhithya-raja commented 7 months ago

Query/Question Authenticating Azure SDK for API management resource with free subscription results in error as below,

Why is this not a Bug or a feature Request? A clear explanation of why is this not a bug or a feature request? My hope is that authentication works fine with SDK. Maybe my setup has the issues. Attaching my build.gradle and authentication code for reference...

AzureProfile profile = new AzureProfile("d*************************6",
            "0********************3", AzureEnvironment.AZURE);
    TokenCredential credential = new DefaultAzureCredentialBuilder()
            .tenantId("d***********************************6")
            .authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
            .build();
    ApiManagementManager manager = ApiManagementManager
           .authenticate(credential, profile);
    System.out.println(manager.apis().get("apigee","adhigw","echo-api").description());

implementation ('com.azure.resourcemanager:azure-resourcemanager-resources:2.32.0')
implementation ('com.azure.resourcemanager:azure-resourcemanager:2.32.0')
implementation ('com.azure.resourcemanager:azure-resourcemanager-authorization:2.32.0')
implementation ('com.azure:azure-core-http-netty:1.13.9')
implementation ('com.azure.resourcemanager:azure-resourcemanager-mediaservices:2.3.0')

implementation ('com.azure.resourcemanager:azure-resourcemanager-apimanagement:1.0.0-beta.4')
implementation("com.azure:azure-core:1.39.0")
implementation("com.azure:azure-security-keyvault-secrets:4.6.1")
implementation("com.azure:azure-identity:1.10.4")
implementation("com.azure:azure-core-management:1.11.1")
implementation("com.azure.resourcemanager:azure-resourcemanager-apimanagement:1.0.0-beta.3")
implementation("com.azure.resourcemanager:azure-resourcemanager-authorization:2.26.0")
implementation("com.azure:azure-identity-providers-core:1.0.0-beta.1")
implementation("com.azure:azure-identity-extensions:1.1.3")

Setup (please complete the following information if applicable):

Error Message Exception in thread "main" com.azure.identity.CredentialUnavailableException: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/environmentcredential/troubleshoot WorkloadIdentityCredential authentication unavailable. The workload options are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/java/identity/workloadidentitycredential/troubleshoot Managed Identity authentication is not available. SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache. AADSTS50078: Presented multi-factor authentication has expired due to policies configured by your administrator, you must refresh your multi-factor authentication to access '797f4846-ba00-4fd7-ba43-dac1f8f63013'. Trace ID: 98afbd93-8e22-4607-ad59-3c10d8a44800 Correlation ID: 1da6d944-70b5-4c66-a271-b702acf019cf Timestamp: 2023-11-13 14:00:08Z AzureCliCredential authentication unavailable. Azure CLI not installed.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/azclicredential/troubleshoot Azure PowerShell authentication failed using defaultpowershell(pwsh) with following error: Unable to execute PowerShell. Please make sure that it is installed in your system. Azure PowerShell authentication failed using powershell-core(powershell) with following error: Az.Account module with version >= 2.2.0 is not installed. It needs to be installed to use Azure PowerShell Credential. AzureDeveloperCliCredential authentication unavailable. Azure Developer CLI not installed.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/azdevclicredential/troubleshootTo mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azure-identity-java-default-azure-credential-troubleshoot at com.azure.identity.ChainedTokenCredential.lambda$getToken$3(ChainedTokenCredential.java:107) at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:45) at reactor.core.publisher.Mono.subscribe(Mono.java:4490) at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onComplete(FluxSwitchIfEmpty.java:82) at reactor.core.publisher.MonoNext$NextSubscriber.onComplete(MonoNext.java:102) at reactor.core.publisher.FluxFlatMap$FlatMapMain.checkTerminated(FluxFlatMap.java:847) at reactor.core.publisher.FluxFlatMap$FlatMapMain.drainLoop(FluxFlatMap.java:609) at reactor.core.publisher.FluxFlatMap$FlatMapMain.innerComplete(FluxFlatMap.java:895) at reactor.core.publisher.FluxFlatMap$FlatMapInner.onComplete(FluxFlatMap.java:998) at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onComplete(Operators.java:2060) at reactor.core.publisher.Operators.complete(Operators.java:137) at reactor.core.publisher.MonoEmpty.subscribe(MonoEmpty.java:46) at reactor.core.publisher.Mono.subscribe(Mono.java:4490) at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:103) at reactor.core.publisher.FluxPeek$PeekSubscriber.onError(FluxPeek.java:222) at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:106) at reactor.core.publisher.Operators.error(Operators.java:198) at reactor.core.publisher.MonoError.subscribe(MonoError.java:53) at reactor.core.publisher.Mono.subscribe(Mono.java:4490) at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:103) at reactor.core.publisher.MonoPeekTerminal$MonoTerminalPeekSubscriber.onError(MonoPeekTerminal.java:258) at reactor.core.publisher.FluxPeekFuseable$PeekConditionalSubscriber.onError(FluxPeekFuseable.java:903) at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onError(Operators.java:2065) at reactor.core.publisher.Operators.error(Operators.java:198) at reactor.core.publisher.MonoError.subscribe(MonoError.java:53) at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:53) at reactor.core.publisher.Mono.subscribe(Mono.java:4490) at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onComplete(FluxSwitchIfEmpty.java:82) at reactor.core.publisher.MonoNext$NextSubscriber.onComplete(MonoNext.java:102) at reactor.core.publisher.FluxFlatMap$FlatMapMain.checkTerminated(FluxFlatMap.java:847) at reactor.core.publisher.FluxFlatMap$FlatMapMain.drainLoop(FluxFlatMap.java:609) at reactor.core.publisher.FluxFlatMap$FlatMapMain.innerComplete(FluxFlatMap.java:895) at reactor.core.publisher.FluxFlatMap$FlatMapInner.onComplete(FluxFlatMap.java:998) at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onComplete(Operators.java:2060) at reactor.core.publisher.Operators.complete(Operators.java:137) at reactor.core.publisher.MonoEmpty.subscribe(MonoEmpty.java:46) at reactor.core.publisher.Mono.subscribe(Mono.java:4490) at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:103) at reactor.core.publisher.MonoUsing$MonoUsingSubscriber.onError(MonoUsing.java:260) at reactor.core.publisher.MonoFlatMap$FlatMapMain.secondError(MonoFlatMap.java:192) at reactor.core.publisher.MonoFlatMap$FlatMapInner.onError(MonoFlatMap.java:259) at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:142) at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1839) at reactor.core.publisher.MonoFlatMap$FlatMapInner.onNext(MonoFlatMap.java:249) at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1839) at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:151) at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:82) at reactor.core.publisher.SerializedSubscriber.onNext(SerializedSubscriber.java:99) at reactor.core.publisher.FluxRepeatWhen$RepeatWhenMainSubscriber.onNext(FluxRepeatWhen.java:142) at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1839) at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:151) at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1839) at reactor.core.publisher.MonoCompletionStage.lambda$subscribe$0(MonoCompletionStage.java:100) at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:934) at java.base/java.util.concurrent.CompletableFuture$UniHandle.tryFire(CompletableFuture.java:911) at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510) at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1773) at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760) at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) Suppressed: com.azure.identity.CredentialUnavailableException: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/environmentcredential/troubleshoot WorkloadIdentityCredential authentication unavailable. The workload options are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/java/identity/workloadidentitycredential/troubleshoot Managed Identity authentication is not available. SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache. AADSTS50078: Presented multi-factor authentication has expired due to policies configured by your administrator, you must refresh your multi-factor authentication to access '797f4846-ba00-4fd7-ba43-dac1f8f63013'. Trace ID: 98afbd93-8e22-4607-ad59-3c10d8a44800 Correlation ID: 1da6d944-70b5-4c66-a271-b702acf019cf Timestamp: 2023-11-13 14:00:08Z AzureCliCredential authentication unavailable. Azure CLI not installed.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/azclicredential/troubleshoot Azure PowerShell authentication failed using defaultpowershell(pwsh) with following error: Unable to execute PowerShell. Please make sure that it is installed in your system. Azure PowerShell authentication failed using powershell-core(powershell) with following error: Az.Account module with version >= 2.2.0 is not installed. It needs to be installed to use Azure PowerShell Credential. AzureDeveloperCliCredential authentication unavailable. Azure Developer CLI not installed.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/azdevclicredential/troubleshootTo mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azure-identity-java-default-azure-credential-troubleshoot ... 63 more Suppressed: com.azure.identity.CredentialUnavailableException: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/environmentcredential/troubleshoot WorkloadIdentityCredential authentication unavailable. The workload options are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/java/identity/workloadidentitycredential/troubleshoot Managed Identity authentication is not available. SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache. AADSTS50078: Presented multi-factor authentication has expired due to policies configured by your administrator, you must refresh your multi-factor authentication to access '797f4846-ba00-4fd7-ba43-dac1f8f63013'. Trace ID: 98afbd93-8e22-4607-ad59-3c10d8a44800 Correlation ID: 1da6d944-70b5-4c66-a271-b702acf019cf Timestamp: 2023-11-13 14:00:08Z AzureCliCredential authentication unavailable. Azure CLI not installed.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/azclicredential/troubleshoot Azure PowerShell authentication failed using defaultpowershell(pwsh) with following error: Unable to execute PowerShell. Please make sure that it is installed in your system. Azure PowerShell authentication failed using powershell-core(powershell) with following error: Az.Account module with version >= 2.2.0 is not installed. It needs to be installed to use Azure PowerShell Credential. AzureDeveloperCliCredential authentication unavailable. Azure Developer CLI not installed.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/azdevclicredential/troubleshootTo mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azure-identity-java-default-azure-credential-troubleshoot ... 63 more Suppressed: com.azure.identity.CredentialUnavailableException: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/environmentcredential/troubleshoot WorkloadIdentityCredential authentication unavailable. The workload options are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/java/identity/workloadidentitycredential/troubleshoot Managed Identity authentication is not available. SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache. AADSTS50078: Presented multi-factor authentication has expired due to policies configured by your administrator, you must refresh your multi-factor authentication to access '797f4846-ba00-4fd7-ba43-dac1f8f63013'. Trace ID: 98afbd93-8e22-4607-ad59-3c10d8a44800 Correlation ID: 1da6d944-70b5-4c66-a271-b702acf019cf Timestamp: 2023-11-13 14:00:08Z AzureCliCredential authentication unavailable. Azure CLI not installed.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/azclicredential/troubleshoot Azure PowerShell authentication failed using defaultpowershell(pwsh) with following error: Unable to execute PowerShell. Please make sure that it is installed in your system. Azure PowerShell authentication failed using powershell-core(powershell) with following error: Az.Account module with version >= 2.2.0 is not installed. It needs to be installed to use Azure PowerShell Credential. AzureDeveloperCliCredential authentication unavailable. Azure Developer CLI not installed.To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/java/identity/azdevclicredential/troubleshootTo mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azure-identity-java-default-azure-credential-troubleshoot ... 63 more Suppressed: java.lang.Exception: #block terminated with an error at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:100) at reactor.core.publisher.Mono.block(Mono.java:1742) at com.azure.resourcemanager.apimanagement.implementation.ApisClientImpl.getWithResponse(ApisClientImpl.java:828) at com.azure.resourcemanager.apimanagement.implementation.ApisClientImpl.get(ApisClientImpl.java:845) at com.azure.resourcemanager.apimanagement.implementation.ApisImpl.get(ApisImpl.java:79) at org.example.Main.main(Main.java:41)

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

XiaofeiCao commented 7 months ago

@adhithya-raja Seems you'll need to set up proper environment variables.

Guide: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/README.md#authentication

adhithya-raja commented 7 months ago

@adhithya-raja Seems you'll need to set up proper environment variables.

Guide: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/README.md#authentication

The guide reference is having "AzureResourceManager" not "ApiManagementManager"... Also Can you help with a guide to set azure environment variables for sprint boot application?

XiaofeiCao commented 7 months ago

My bad... Here's the Authentication for ApiManagement: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/apimanagement/azure-resourcemanager-apimanagement#authentication