Skip to content

Cannot use Bearer Token in new asp.net core identity API #31727

Closed
@SandroRiz

Description

@SandroRiz

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Following the sample published here:
https://github.com/dotnet/blazor-samples/tree/main/8.0/BlazorWebAssemblyStandaloneWithIdentity

And the documentation published here:
https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/standalone-with-identity?view=aspnetcore-8.0

I tried to setup the backend and the front end to use Bearer Token instead cookie but the WASM client doesn't login (but the Register endpoint works)

cc: @guardrex #31194

Expected Behavior

Change the Sample and /or the Documentation indicating

  • if the new asp.net core Identity API are suitable to be used eg. from a mobile client (that cannot use cookies)
  • the risk of using bearer token
  • if a WASM standalone client could use the token or only the cookies

Steps To Reproduce

Change line 9 of backend program.cs adding .AddBearerToken() instead to .AddIdentityCookies()
Change line 123 of frontend CookieAuthenticationStateProvider.cs putting false instead true

Exceptions (if any)

No response

.NET Version

8.0.0

Anything else?

I was able to call from Postman the new API with bearer token NOT including the

.AddAuthentication() but only the .AddAuthorization()

basically I copied what you obtain from the new Blazor 8 web app template when you choose to include identity... see attach

Program.zip

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions