CrahunGit / Auth0BlazorWebAppSample

MIT License
27 stars 5 forks source link

Thx for this sample #1

Closed fdonnet closed 8 months ago

fdonnet commented 10 months ago

Could be great to have the scenario when we need to call an API outside of the project and use the token provided by the oauth flow. Where to store token? (Server part + caching.disttributed ?) and token rotation/refresh and how to share with the client components ?

You are the first who provides something usefull for net 8 because on the official doc it was a complete mess, so ty.

fdonnet commented 9 months ago

I did something cool with token management based on your example. But now I have an issue when I make an API call in OnInitializedAsync(). In you example, in the counter page could you try to call the SayHello() func in OnInitializedAsync(). I think it will fail but I don't know why. On my side it gives me a 302 response... and if I call on the button click it works perfectly.

Very strange.

CrahunGit commented 9 months ago

Yes, it's strange but the walkaround is to await authenticationState. Seems that after redirect to login happens Auth is not in correct state. I've uploaded new version with this, calling SayHello on initialized.

fdonnet commented 9 months ago

yes, seems to work on my side too. yes await the thing and was forced to use a facade like explained by bcheung4589 https://github.com/dotnet/aspnetcore/issues/51468 and now it's working... inital call is made from server and after that from wasm.

But this 2 calls cause flickering... finally this automode is not really usable.

fdonnet commented 9 months ago

On my side it doesn't work if i don't use a facade even with the await authenticationState.

Maybe because I make a real api call server side to an external api not only an simple hello. It causes a weird 302 (maybe middleware related or other stuff).

With the facade (call server endpoint when client, direct server call when server side it works)

Only remain this flickering dues to prerendering... I think this auto mode is not really usable.

When interactive prerender = flickering When prerender=false = it waits the wasm load and it works but what's the goal of automode in this case :)

EDIT, it's working now with https://learn.microsoft.com/en-us/aspnet/core/blazor/components/prerendering-and-integration?view=aspnetcore-7.0&viewFallbackFrom=aspnetcore-8.0&pivots=server (usage of Persistent application state)