-
Notifications
You must be signed in to change notification settings - Fork 10k
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
BlazorBFFOidc and DevTunnel - Auth to MS Entra works for swagger SPA and nearly working for Blazor website #55537
Comments
Thanks for contacting us. It looks like there are a few issues here, so let's address those in order:
Let us know how this goes? |
Thanks @mkArtakMSFT Re: Issue 1: I made the .Authority change as you indicated so now it is: And when I click login the site gives this error
(It is adding a The Azure AppRegistration : Endpoints tab shows the following as the proper metadata url: EDIT: I just figured this was something to do with the MS Entra for Customers being in preview still? |
So this is interesting. On a whim I tried the authority to this: That works to get me past that metadata error. I no longer have to set the meta data url: Now for Issue 2.
Notice the query string variable "redirect_uri" is MS Auth works and MFA works...but obviously when redirected back to localhost it blows up. Here is my Azure AppRegistration redirect URL (from manifest):
EDIT: Remember my swagger page is authorizing and redirecting just fine. I notice it sends the correct I wonder if this "TODO" is the culprit: private static AuthenticationProperties GetAuthProperties(string? returnUrl)
{
// TODO: Use HttpContext.Request.PathBase instead.
const string pathBase = "/"; |
Update: I tried changing the minimal API in several ways and no matter what I do the querystring variable So just for giggles...I manually copied the correct value to that variable sent to microsoft: Hit enter. It did the auth. Then MFA. Then redirected back to my site and I get this error:
So it looks like on the way out AND on the way in, the site OIDC is always using localhost instead of the devtunnel. |
It even ignores setting the querystring variable sent to MS even if I do this! return new AuthenticationProperties
{
RedirectUri = "https://xxxxxxxx-7237.usw3.devtunnels.ms/"
}; I'm baffled. |
This works! Manual set value in blazor Program.cs. This makes auth work front to back (which proves my AppRegistration was set correctly): oidcOptions.Events = new OpenIdConnectEvents()
{
OnRedirectToIdentityProvider = context =>
{
context.ProtocolMessage.RedirectUri = "https://xxxxxxxx-7237.usw3.devtunnels.ms/signin-oidc";
return Task.FromResult(0);
}
}; |
@mkArtakMSFT (sorry for many messages as I figured this out) Issue 2 - Summary OIDC to MS Entra works fine using aspire localhost link to the blazor app. But when I try same using a DevTunnel - the OIDC engine doesn't use the base path, but rather continues using localhost. True for both the "to MS" and the "back from MS" parts. The only way I have gotten OIDC in blazor to FULLY work with devtunnel is to manually set BOTH of these uri: FIRST (in program.cs of blazor server): oidcOptions.Events = new OpenIdConnectEvents()
{
OnRedirectToIdentityProvider = context =>
{
context.ProtocolMessage.RedirectUri = "https://xxxx-7237.usw3.devtunnels.ms/signin-oidc";
return Task.FromResult(0);
}
}; SECOND (in LoginLogoutEndpointRouteBuilderExtensions.cs): return new AuthenticationProperties
{
RedirectUri = "https://xxxx-7237.usw3.devtunnels.ms/"
}; |
@mkArtakMSFT ... Based on Steve's comment 👇, I'll hold and watch 👁️. |
We discussed, and are not sure these workarounds should be required. We think it should just work without these workarounds, hence marking for investigation. |
Agreed @SteveSandersonMS. The workaround proved it "can" and "should" work which is comforting. I'm on I set a breakpoint here:
Then walked backwards up the callstack - to here:
Very strange that |
After some further discussion on this topic, we think the workaround you've landed on is indeed required. |
@mkArtakMSFT ... Does this rise to the level of placing a Troubleshoot section in the article with the full workaround guidance described by @swegele above ☝, or should I just add a cross-link to this PU issue in the existing Additional Resources section? If taking either approach for coverage, I see this is explicitly discussing OIDC to MS Entra. Is this only a concern for the BWA+OIDC article? |
Is there an existing issue for this?
Describe the bug
First let me say a big YAY! With https://localhost/ I got Aspire/Blazor/API auth working with MS Entra for Customers (preview).
Thank you so much for this sample code and docs!
Side note: For the curious - after using this authority:
oidcOptions.Authority = "https://-mydomain-.ciamlogin.com/-tenantid-/oauth2/v2.0/authorize";
...the code automatically tries to get OIDC meta-data from the wrong url.
So I had to do this manually:
oidcOptions.MetadataAddress = "https://-mydomain-.ciamlogin.com/-tenantid-/v2.0/.well-known/openid-configuration";
Anyway, now I have setup a dev-tunnel with 2 ports to reach BOTH the WebAPI swagger page AND the Blazor web site when I fire up Aspire. I start the dev-tunnel in aspire AppHost program.cs like so:
var mydevtunnel = builder.AddExecutable("my-dev-tunnel", "c:/tools/devtunnel.exe", builder.AppHostDirectory, "host");
Credit to @SteveSandersonMS comment here
Works great!. I can navigate to the devtunnel from a browser:
WebAPI
Blazor Website
No matter what I try, after coming back from Microsoft, I always end up seeing that the url/path got changed somehow back to
https://localhost:7327
even though it start ashttps://xxxxx-7182.usw3.devtunnels.ms/
when went to MS for auth.Thus the
signin-oidc
page/middleware kicks out a 500 error saying "failed to correlate".I have quadruple checked all the combinations of Azure AppRegistration Redirect URLs - those are all fine.
I think it is related to how the code does the redirect to auth and back via the following:
LoginLogoutEndpointRouteBuilderExtensions
and
app.MapGroup("/authentication").MapLoginAndLogout();
But I can't figure it out.
I think this would be REALLY cool to prove/show that the dev Inner-Loop with Aspire can include DevTunnels.
I'm half way there with it working for the WebAPI swagger/OpenAPI site.
cc: @guardrex dotnet/blazor-samples#288
Expected Behavior
Just like it works with Swagger index.html page...the Blazor Website and DevTunnel should also work leaving me logged in to the site with the proper url after coming back from auth against MS entra.
Steps To Reproduce
See above
Exceptions (if any)
Authorization failed - failed to correlate
.NET Version
8.0.300-preview.24203.14
Anything else?
No response
The text was updated successfully, but these errors were encountered: