-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Support Blazor .Net 8 Microsoft.Identity.Web client for Azure clients #51374
Comments
I am really struggling with this, as well. There is no good documentation to implement Azure AD in the new template. I have tried using the structure for Blazor Server in NET7 and pulling specific pieces from the NET8 Individual Account solution. I don't want individual accounts, however. I just want to protect the application using single org Entra ID. The closest I have gotten is getting the calls to operate, but now I get a persistent Correlation Error, cookie not found. The cookies exist in the browser set to Strict, even though I set up the project to put Correlation and Nonce cookies to SameSite None with Secure to Always. If the project is running localy, and I change a piece of code, hot reload is triggered, and the app reloads properly with executing the signin. If I shut down and restart, I get the correlation error again. I am posting this here since it seems to be related, but I thought about opening a new issue. Code (HIDDEN for security): DI Extension: `private static void AddAuthentication(IServiceCollection services, ConfigurationManager configuration)
}` Program.cs snippets:
builder.Services.AddCascadingAuthenticationState(); builder.Services.AddMicrosoftIdentityConsentHandler();` app.UseCookiePolicy(new() app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseAntiforgery(); app.UseAuthorization(); app.MapRazorComponents() app.MapControllers(); app.UseStatusCodePagesWithRedirects("/StatusCode/{0}"); app.Run(); |
We just added the sample for OIDC with Microsoft Entra (Azure AD) ... does this get you what you are looking for/need? |
Is the Aspire portion required?
|
What package is this extension in? AddHttpForwarderWithServiceDiscovery
I'm still getting the same error (I have tried on Chrome & Firefox):
An unhandled exception occurred while processing the request.
AuthenticationFailureException: Correlation failed.
Unknown location
AuthenticationFailureException: An error was encountered while handling the remote login.
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()
* Stack
* Query
* Cookies
* Headers
* Routing
*
AuthenticationFailureException: Correlation failed.
*
Show raw exception details
*
AuthenticationFailureException: An error was encountered while handling the remote login.
*
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler<TOptions>.HandleRequestAsync()
*
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
*
SeeEye.Toolbox.Infrastructure.Extensions.PipelineExtensions+<>c__DisplayClass0_0+<<UseSecurityHeaders>b__0>d.MoveNext()
*
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
|
OK, so I figured out the cookie issue. The problem was in my effort to make my app secure. I set the Referrer-Policy to "strict-origin-when-cross-origin" which apparently messed everything up. I will re-test your new OIDC example with this change in mind. |
I tested the new sample implementation, and it worked well. I think it is a big step forward, but the documentation still needs to be updated. A couple things I noticed:
|
Thanks for the example. I tried this and it does not work for me. After the authentication is complete, the client AuthenticationStateProvider gets updated with no state (after a small delay) and the authenticated session is reset. Greetings Damien |
Is this something you see while running the BlazorWebOidc sample without modification? Do you have a stack trace for whatever is constructing the client's |
Hi @halter73 Thanks for your reply. Almost. I just switched out the OpenID Connect client to use a local STS and removed the aspire stuff. I create the trace later. |
@halter73 Got around to looking at this. I did not disable the Microsoft claims mappings. When the claims renaming is disabled, everything works. I will create a PR to update the docs |
@halter73 @mikekistler Is this basically a duplicate of #51202? |
Yes. I'll close it. @damienbod let us know if you disagree. |
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
I would like to implement a secure client Microsoft.Identity.Web (no ASP.NET Core Identity) using the new Blazor features.
In RC2, this does not work due to Blazor 8 State Management, required duplicate components and persisting the user state which is stored in a cookie on the client.
Would it be possible to support this for the different rendering modes
Describe the solution you'd like
The application authenticates against Microsoft Entra ID using the Web flow and requires a secret or a certificate. (Single Azure App registration)
OIDC Code flow with PKCE is used, not implicit flow which is the default using Microsoft.Identity.Web
The authentication session is stored in a HTTP only secure cookie.
All Blazor components in the different rendering modes have access to the authentication claims and the user session.
The Anti-forgery cookie is used to access APIs or any post, delete, put requests to the same site server. This can be added to the request using a html component in the form or a HTTP request header using a HttpClient.
No unsecure inline scripts are used in the client.
ASP.NET Core Identity is not used.
UI components can be displayed checking the authorized state
Logout form request uses the Anti-forgery cookie
Additional context
No response
The text was updated successfully, but these errors were encountered: