Skip to content

[Bug] WithAuthority override ignored for GetAuthorizationRequestUrl #2929

Closed
@michaeltreynolds

Description

@michaeltreynolds

Which version of MSAL.NET are you using?
Latest

Platform
.NET 4.7.2

What authentication flow has the issue?

  • Desktop / Mobile
    • Interactive
      Integrated Windows Authentication
      Username Password
      Device code flow (browserless)
  • Web app
    • Authorization code
      On-Behalf-Of
  • Daemon app
    • Service to Service calls

Other?

Is this a new or existing app?
Existing app new scenario within the app.

Repro
We setup an app to use the "common" endpoint. However, there is a scenario where we want to silently get their consumers* login and we create the following URL:

        Uri authorizationRequestUrl = confidentialClientApplication
            .GetAuthorizationRequestUrl(new List<string> { BaseScope})
            .WithExtraQueryParameters(extraQueryParameters)
            .WithLoginHint(identity.Email) // Note email is primary sign in name (email or phone)
            .WithAuthority(AzureCloudInstance.AzurePublic, "consumers")
            .WithRedirectUri(GetCompleteSignInUrl(authorizationContext.HttpContext.Request.Url.Host).ToString())
            .ExecuteAsync()
            .ConfigureAwait(false)
            .GetAwaiter()
            .GetResult();

Also tried:

        Uri authorizationRequestUrl = confidentialClientApplication
            .GetAuthorizationRequestUrl(new List<string> { BaseScope})
            .WithExtraQueryParameters(extraQueryParameters)
            .WithLoginHint(identity.Email) // Note email is primary sign in name (email or phone)
            .WithAuthority(AadAuthorityAudience.PersonalMicrosoftAccount)
            .WithRedirectUri(GetCompleteSignInUrl(authorizationContext.HttpContext.Request.Url.Host).ToString())
            .ExecuteAsync()
            .ConfigureAwait(false)
            .GetAwaiter()
            .GetResult();

Expected behavior
Expected this to generate a URL for the consumers endpoint.

Actual behavior
Generates URL for the common endpoint.

Possible solution
Perhaps the options specified here are not being used if provided originally in the app? Maybe support this or throw if it isn't supported.

Additional context / logs / screenshots
So the app was originally setup with 'common' via code similar to this:

	ConfidentialClientApplicationOptions applicationOptions;
	applicationOptions = new ConfidentialClientApplicationOptions();
	applicationOptions.ClientId = "fakeId";
	applicationOptions.AadAuthorityAudience = AadAuthorityAudience.AzureAdAndPersonalMicrosoftAccount;
	applicationOptions.Instance = "https://login.microsoftonline.com/common";
	applicationOptions.RedirectUri = "https://example.com";

	var confidentialClientApplicationBuilder = ConfidentialClientApplicationBuilder.CreateWithApplicationOptions(applicationOptions)
		.WithCertificate(someCert);

Activity

bgavrilMS

bgavrilMS commented on Oct 4, 2021

@bgavrilMS
Member

Yes, good bug. MSAL ignores the WithAuthority at the request level for GetAuthorizationRequestUrl

The workaround for now is to specify WithAuthority at the app level, smth like:

 var app = ConfidentialClientApplicationBuilder
                   .Create(TestConstants.ClientId)
                   .WithClientSecret("secret")
                   .WithAuthority(AzureCloudInstance.AzurePublic, "consumers")
                   .Build();
added this to the 4.38.0 milestone on Oct 4, 2021
changed the title [-][Bug] [/-] [+][Bug] WithAuthority override ignored for GetAuthorizationRequestUrl[/+] on Oct 4, 2021
michaeltreynolds

michaeltreynolds commented on Oct 6, 2021

@michaeltreynolds
Author

In response to:

The workaround for now is to specify WithAuthority at the app level, smth like:

 var app = ConfidentialClientApplicationBuilder
                   .Create(TestConstants.ClientId)
                   .WithClientSecret("secret")
                   .WithAuthority(AzureCloudInstance.AzurePublic, "consumers")
                   .Build();

This workaround does not seem to work for our case. We actually use the "Instance" property to integrate with the PPE version of this as well. I find that I cannot both use the "Instance" property and specify "consumers". I'll continue to use a string.Replace on the resulting URL for my workaround.

loginUri = loginUri.Replace("/common/oauth2/v2.0/authorize", "/consumers/oauth2/v2.0/authorize")

The following did not work for me:

            ConfidentialClientApplicationOptions applicationOptions;
            applicationOptions = new ConfidentialClientApplicationOptions();
            applicationOptions.ClientId = msalAuthenticationConfig.ClientId;
            applicationOptions.AadAuthorityAudience = AadAuthorityAudience.PersonalMicrosoftAccount;
            applicationOptions.Instance = msalAuthenticationConfig.STSInstance; // Can be "-ppe" or regular url.

            var confidentialClientApplicationBuilder = ConfidentialClientApplicationBuilder.CreateWithApplicationOptions(applicationOptions)
                    .WithCertificate(certificate);
modified the milestones: 4.38.0, 4.39.0 on Nov 19, 2021
modified the milestones: 4.39.0, 4.40.0 on Nov 29, 2021
removed this from the 4.40.0 milestone on Jan 11, 2022
added this to the 4.41.0 milestone on Jan 13, 2022
self-assigned this
on Jan 28, 2022
removed this from the 4.41.0 milestone on Feb 8, 2022

2 remaining items

self-assigned this
on Feb 1, 2023
moved this from Triage to Estimated/Committed in MSAL Customer Truston Feb 1, 2023
moved this from Estimated/Committed to In Progress in MSAL Customer Truston Feb 2, 2023
linked a pull request that will close this issueUpdated doc for consumers authority #3946on Feb 10, 2023
moved this from In Progress to Fixed in MSAL Customer Truston Feb 13, 2023
bgavrilMS

bgavrilMS commented on Feb 13, 2023

@bgavrilMS
Member

Fixed. Will release with MSAL 4.50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Relationships

None yet

    Participants

    @bgavrilMS@michaeltreynolds@trwalke@pmaytak@SameerK-MSFT

    Issue actions

      [Bug] WithAuthority override ignored for GetAuthorizationRequestUrl · Issue #2929 · AzureAD/microsoft-authentication-library-for-dotnet