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] Using PublicClientApplicationBuilder and WithAuthority(string cloudInstanceUri, string tenant, bool validateAuthority) throws exception when acquiring token #1270

Closed
Crazyconv opened this issue Jul 15, 2019 · 3 comments
Assignees
Labels
Milestone

Comments

@Crazyconv
Copy link

Crazyconv commented Jul 15, 2019

Which Version of MSAL are you using ?
MSAL 4.1.0

Platform
net45

What authentication flow has the issue?

  • Desktop / Mobile
    • Username Password

Is this a new or existing app?
This is a new app

Repro

string tenantId = "<tenantId";
string username = "<username>";
string password = "<password>";
string clientId = "<clientId>";

string[] permissions = new[] {"<permission>"};
IPublicClientApplication app = PublicClientApplicationBuilder.Create(clientId).WithAuthority("https://login.microsoftonline.com", tenantId).Build();
AuthenticationResult result = await app.AcquireTokenByUsernamePassword(permissions, username, this.ToSecureString(password)).ExecuteAsync();

Expected behavior
An AuthenticationResult result is returned.

Actual behavior
Exception is thrown.
Microsoft.Identity.Client.MsalServiceException: "AADSTS90002: Tenant 'v2.0' not found. This may happen if there are no active subscriptions for the tenant. Check with your subscription administrator.\r\nTrace ID: 024c3425-f6b7-4f00-a95b-8b0a14325400\r\nCorrelation ID: d2d97559-d4ab-4517-9a3f-bec02f562a50\r\nTimestamp: 2019-07-15 07:33:33Z"

Possible Solution
In this line, string.Format(CultureInfo.InvariantCulture, "{0}/{1}/", cloudInstanceUri, tenant) produces https://login.microsoftonline.com//<tenantId>, and so CanonicalAuthority of the AuthorityInfo object becomes https://login.microsoftonline.com//.

Updating the line to string.Format(CultureInfo.InvariantCulture, "{0}{1}/", cloudInstanceUri, tenant) should fix the issue. However I am not sure about other possible urls that can be passed into the method so not sure whether it will break other user cases.

@henrik-me henrik-me added this to the 4.3 milestone Jul 18, 2019
@henrik-me henrik-me added the bug label Jul 18, 2019
@trwalke
Copy link
Member

trwalke commented Jul 23, 2019

Hi @Crazyconv I believe I have a working solution for you. Do you have an email where I can send a preview nuget for you to verify the fix?

@Crazyconv
Copy link
Author

@trwalke Thanks for the quick response. My email is conanconv@gmail.com.

@trwalke trwalke added Fixed and removed Investigate labels Jul 29, 2019
@jennyf19
Copy link
Collaborator

jennyf19 commented Aug 8, 2019

Included in 4.3.0 release

@jennyf19 jennyf19 closed this as completed Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants