auth0-blog / secure-blazor-wasm-quiz-manager

41 stars 13 forks source link

Client never appends bearer token #3

Open alexkibler opened 2 years ago

alexkibler commented 2 years ago

I followed the tutorial, and ended up with this repo: https://github.com/alexkibler/GameTrackerBlazor (keys are removed from appsettings, so it won't currently build).

Whenever I run it though, the injected HTTP Client never appends my bearer token. I tried it both with my repo and also by cloning yours and then putting in my Auth0 values.

I thought maybe it was an issue with something in .NET 6 (since that's how I built my repo), but cloning this one in .NET 5 isn't working either :/ Any idea what the issue could be?

Thanks!

flicwin commented 2 years ago

Similar issue to @alexkibler. Cloned repo to VS2022, updated Auth0 app details and even added Facebook social login. Am able to create, login, logout with individual, Google and Facebook logins, successfully. After every successful login of each type, I receive the 401 error shown below in every instance. I have checked my Auth0 App settings and the only thing changed in the .Net app is the appsettings file in both Client and Server projects.

Auth0 Error

m-GDEV commented 3 months ago

@alexkibler @flicwin

Hello, I followed this guide recently and found a solution. It might be helpful.

In Program.cs you need to use an AuthorizationMessageHandler instead of a BaseAddressAuthorizationMessageHandler as suggested in the blog post.

The former allows you to attach tokens to bearer authentication when making requests to external URLs. The latter only appends the bearer token when making requests to the same hostname.

The later was causing an issue for me where my server and client were running on different ports.

There are two ways you can use the latter: AuthorizationMessageHandler

I'm in no way an expert but this worked for me so I thought I'd share it.

I'm using .NET 8 by the way.