Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] LogsQueryClientBuilder.queryWorkspace fails to acquire token: scope null/.default openid profile offline_access is not valid #33062

Closed
3 tasks done
Bestyan opened this issue Jan 18, 2023 · 3 comments · Fixed by #33200
Assignees
Labels
Azure.Identity Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@Bestyan
Copy link

Bestyan commented Jan 18, 2023

Describe the bug
Using the LogsQueryClientBuilder to build a LogsQueryClient with any TokenCredential throws a MsalServiceException when querying the workspace via queryWorkspace(...)

Exception or Stack Trace

[Correlation ID: 1cb53550-f27d-437f-baf1-5d03ed9ad57e] Execution of class com.microsoft.aad.msal4j.AcquireTokenByClientCredentialSupplier failed.

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 null/.default openid profile offline_access is not valid.
Trace ID: 7c828f9f-b5fd-411d-87f9-5f6051674200
Correlation ID: 1cb53550-f27d-437f-baf1-5d03ed9ad57e
Timestamp: 2023-01-18 07:17:23Z
	at com.microsoft.aad.msal4j.MsalServiceExceptionFactory.fromHttpResponse(MsalServiceExceptionFactory.java:45)
	at com.microsoft.aad.msal4j.TokenRequestExecutor.createAuthenticationResultFromOauthHttpResponse(TokenRequestExecutor.java:103)
	at com.microsoft.aad.msal4j.TokenRequestExecutor.executeTokenRequest(TokenRequestExecutor.java:34)
	at com.microsoft.aad.msal4j.AbstractClientApplicationBase.acquireTokenCommon(AbstractClientApplicationBase.java:128)
	at com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier.execute(AcquireTokenByAuthorizationGrantSupplier.java:63)
	at com.microsoft.aad.msal4j.AcquireTokenByClientCredentialSupplier.acquireTokenByClientCredential(AcquireTokenByClientCredentialSupplier.java:86)
	at com.microsoft.aad.msal4j.AcquireTokenByClientCredentialSupplier.execute(AcquireTokenByClientCredentialSupplier.java:49)
	at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:69)
	at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:18)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run$$$capture(CompletableFuture.java:1768)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760)
	at java.base/java.util.concurrent.ForkJoinTask.doExec$$$capture(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java)
	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)

To Reproduce
Create a LogsQueryClient object using the LogsQueryClientBuilder and try to query the workspace. Authentication will fail.

Code Snippet

LogsQueryClient client= new LogsQueryClientBuilder()
                    .credential(new DefaultAzureCredentialBuilder().build())
                    .buildClient();
client.queryWorkspace(
                        "my-workspace-id",
                        "my-query",
                        new QueryTimeInterval(Duration.ofDays(1));

Expected behavior
LogsQueryClientBuilder builds the client in such a way that it is able to acquire a BearerToken.

Setup (please complete the following information):

  • OS: Windows 10
  • IDE: IntelliJ IDEA
  • Library/Libraries: com.azure:azure-monitor-query:1.1.0
  • Java version: 17
  • App Server/Environment: Tomcat
  • Frameworks: Spring Boot 2.7.7

Additional context
I've had a look into AzureLogAnalyticsImplBuilder and the issue is the host attribute being set after the call to createHttpPipeline(). In version com.azure:azure-monitor-query:1.0.12 the host attribute is set before, avoiding the null scope issue.

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

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jan 18, 2023
@joshfree joshfree assigned g2vinay and srnagar and unassigned srnagar Jan 19, 2023
@joshfree joshfree added Client This issue points to a problem in the data-plane of the library. Azure.Identity labels Jan 19, 2023
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jan 19, 2023
@joshfree
Copy link
Member

@g2vinay could you please assist @Bestyan with this github issue?

@Fabio1988
Copy link
Contributor

Fabio1988 commented Jan 23, 2023

This is related to a recently change in the SDK. It was working before updating to 1.1.0

It's the same issue for the MetricsQueryClientBuilder.

Found the issue, it's related to the fallback of host not set.

on this line it's defaulting to https://management.azure.com... But for the policy it uses the null value of host, not the default:

policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, String.format("%s/.default", host)));

My previous implementation:

MetricsQueryClientBuilder()
.credential(getTokenCredential())
.buildClient();

changed to:

MetricsQueryClientBuilder()
.endpoint("https://management.azure.com")
.credential(getTokenCredential())
.buildClient();

@srnagar
Copy link
Member

srnagar commented Jan 27, 2023

@Bestyan and @Fabio1988 thank you for reporting this issue. I have a PR to fix this and it should be released early Feb.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Azure.Identity Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants