Blazor Authentication with JSON Web Tokens

preview_player
Показать описание
We've seen a ASP.NET backend with an Angular frontend. What if we want C# all the way through? Here's how we do it in Blazor.

Topics include:
- Creating HttpClient through an HttpClientFactory
- Accessing Session Storage with the Blazored.SessionStorage package
- Decomposing JWTs in .NET
- Using events to update the DOM in Blazor
- Using a DelegatingHandler to augment HTTP requests
- Avoiding cyclic dependency injection
Рекомендации по теме
Комментарии
Автор

Which front end do you prefer - Angular or Blazor? Let me know.
And if you liked the video, click the 👍.

CodingTutorialsAreGo
Автор

Great stuff, thanks! Just moving from Angular to Blazor so this helps alot :)

hollandrisley
Автор

Thanks for the video. I never knew that I can get the token from the class again. I always have written a custom parser for that. Thanks for showing that. Also l have a question. Instead of using DelegatingHandler for auth state, can't we use use the AuthenticationStateProvider for that as that also directly control the blazor AuthorizeView component

syedhasnadjami
Автор

huge help. i'll be implementing something like this. thank you

smc_onetwo
Автор

Where would you normally keep that JWT token? Keeping it in the session be easily found and decrypted to extract information from it.
Is there a way to keep it only in memory completely invisible (using WASM)?

DimasMessias-klic
Автор

I am assuming that you're designing this for Client side and not Server side? If it's running server side you created your authorization service as a singleton, which from my understanding is global to ALL connected clients. Would that not mean the JWT token would be accessible to all the users since you are caching it in the Service?

Arcadenut
Автор

Thanks. This all makes sense to me, which in itself is a minor miracle!! Would there be a lot of difference if using Blazor Server rather than WASM?

AthelstanEngland
Автор

thanks. is there any video for auth on blazor web server ??

italhaayt
Автор

Thanks
Can you add Refresh Token ?
Thanks

cissemy
Автор

Yes to download the code. Is this for .net 8 or .net 7?

waynehawkins