question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[OIDC] - Failed to authenticate - Regression after upgrading to .NET 7

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

My application is a Blazor WebAssembly that is hosted by an ASP.Net server.

I configured my app to get access token for my backend with:

builder.Services.AddOidcAuthentication(options =>
{
    options.ProviderOptions.Authority = settings.Authority;
    options.ProviderOptions.MetadataUrl = settings.MetadataUrl.ToString();
    options.ProviderOptions.ClientId = settings.ClientId;
    options.ProviderOptions.ResponseType = "code";

    options.ProviderOptions.DefaultScopes.Add(settings.Scope);
});

builder.Services.AddApiAuthorization();

builder.Services.AddHttpClient("api", (sp, client) =>
{
    client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress);
    client.DefaultRequestHeaders.Add("X-Version", "1.0");
}).AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();

builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("api"));

It is working fine with this authentication and authorization flow running in .NET 6.

But after upgrading to .NET 7, I observe that the app fails to authenticate the user. I receive the auth_code from the IDP and the client request after the token as expected:

image

N.B: if I disable the additional scope from the configuration. I can see that I have the ID_token, handled by the application, but failed to get token for requesting my backend (obviously)

Expected Behavior

My user should be authenticated. aht the access token handled by the app (as for .NET 6).

Steps To Reproduce

Configure the OIDC With adding an additional scope to the request and specify the authorization code flow:

    options.ProviderOptions.ResponseType = "code";
    options.ProviderOptions.DefaultScopes.Add(settings.Scope);

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:23 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
javiercncommented, Nov 21, 2022

@kbeaugrand It’s a bit tricky, but you can find the file in the sources (AuthenticationService.js).

Click the unminify button in Edge image And then search for completeSignIn or for completeSignIn-result inside the file.

1reaction
javiercncommented, Nov 21, 2022

@kbeaugrand thanks for the additional details.

Could you do it like this? https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/testassets/Wasm.Authentication.Client/Program.cs#L15

This should do it, and you should be able to filter then

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Invalid scope when trying to authenticate using ...
NET Core App for authentication. I have ran a test using Okta and everything was working fine but then when switching the details...
Read more >
iOS 12 Safari breaks ASP.NET Core 2.1 OIDC authentication
When authenticating with ASP.NET Core 2.0 with OpenID Connect, the Identity cookie doesn't seem to be set when returning back from IdP which...
Read more >
Web App Easy Auth with OIDC Provider
I am configuring Easy Auth with OIDC Provider on Web App Linux, and on Web App ... error of type 'invalid_request' occurred during...
Read more >
ASP.NET Core updates in .NET 7 Release Candidate 1
NET 7 Release Candidate 1 (RC1) is now available and includes many great new improvements to ASP.NET Core. Here's a summary of what's...
Read more >
Authentication Using Authorization Code Flow - TechDocs
The endpoint authenticates users to establish their identity, authorizes users, requests their consent, and then grants them access to the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found