.NET 6 Blazor 🔥 Authentication & Role-Based Authorization (using JWT & AuthenticationStateProvider)

Поделиться
HTML-код
  • Опубликовано: 26 янв 2025

Комментарии • 80

  • @PatrickGod
    @PatrickGod  3 года назад +13

    ▶ Part 2/2: ruclips.net/video/kOnMMKxwm3I/видео.html

  • @R4z0R229
    @R4z0R229 2 года назад +7

    Acutally there is built in way to read token from string, no need for custom parser
    var tokenHandler = new JwtSecurityTokenHandler();
    var parsedJwt = tokenHandler.ReadJwtToken(token);
    also with this you can other things from token not just claims, like exp date whick is important so you dont put expired token in your header

  • @alainl8069
    @alainl8069 3 года назад +8

    For everyone out there, there are plenty of videos showing you how to implement JWT server-side -- and Patrick covers that too in another video -- but this is the first time I see a video that shows you how to apply it in a Blazor client app. In this video Patrick shows you how to use CustomAuthenticationProvider and the component to apply role-based authentication in a Blazor client app. Great stuff. Well done.

    • @PatrickGod
      @PatrickGod  3 года назад +1

      Thank you so much for your feedback! 😊 Here's the JWT video: ruclips.net/video/v7q3pEK1EA0/видео.html

    • @eduardrivas6964
      @eduardrivas6964 Год назад

      @@PatrickGod Do you have a Blazor Server video? I haven't seen this but since I'm not interested on WASM, it may not be useful for my purposes.

  • @talkathiriify
    @talkathiriify 3 года назад +9

    Thank you very much Patrick for sharing this with us.
    It would be very kind of you if you make part 2 of this, and show the whole picture of it.

  • @ndy77
    @ndy77 2 года назад +4

    hello there, i've same problem @ 13:22 'string token ="" ' how can have it?

    • @berlin2750
      @berlin2750 2 года назад

      eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTUxMiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiVG9ueSBTdGFyayIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6Iklyb24gTWFuIiwiZXhwIjozMTY4NTQwMDAwfQ.IbVQa1lNYYOzwso69xYfsMOHnQfO3VLvVqV2SOXS7sTtyyZ8DEf5jmmwz2FGLJJvZnQKZuieHnmHkg7CGkDbvA

  • @Mimi-qd1vu
    @Mimi-qd1vu 2 года назад

    Thank you Patrick! Hope you have a wonderful day!

  • @neeftgamer
    @neeftgamer 3 года назад +2

    Thank for the clear explanation! One of the few I found with .net 6 example. Keep up the good work!

    • @PatrickGod
      @PatrickGod  3 года назад

      Thank you so much, will do! 😊

  • @GergiH
    @GergiH 2 года назад +3

    Thank you so much! I was looking for such a tutorial everywhere. Very clean and understandable and covers most part of the auth process. Now I only need to understand how to handle JWTs on an enterprise level.

    • @PatrickGod
      @PatrickGod  2 года назад

      Thank you so much for your feedback! Happy to help! 😊

  • @MichaelBond
    @MichaelBond 3 года назад +7

    I too would like to see a part 2 and put the whole thing together.

    • @PatrickGod
      @PatrickGod  3 года назад +1

      Here it is: ruclips.net/video/kOnMMKxwm3I/видео.html 😊

  • @moritzfesseler8460
    @moritzfesseler8460 Год назад +2

    I have one question to the token: Where does this specific token originally come from ? And why does it work ? if i changr the letters in it, it does not work anymore, but why is that ? I hope you can answer my question :) .

  • @hieribu
    @hieribu 2 года назад

    Excellent video, I had previous experience with Razor and I am trying to learn Blazor, your videos it is helping a lot, thank you very much!

  • @MgMG-ig4qg
    @MgMG-ig4qg 2 года назад +1

    What I'm missing is how the jwt token can be parsed if it does not have the secret key. Or does it and did i miss something?

  • @HoussamAsaad
    @HoussamAsaad 2 года назад +2

    Where can I find tokens on the app? thanks

  • @way_no6810
    @way_no6810 3 года назад +1

    Can I see this from the server side of things. Thanks for simplifying this feature.

  • @devdev-mr2ng
    @devdev-mr2ng 2 года назад +1

    keep it up , best content on blazor

  • @baltazarramirez2946
    @baltazarramirez2946 3 года назад +2

    First of all, great video!
    Can you show us how to use this custom AuthenticationStateProvider and Azure MSAL authentication in a single Blazor WebAssembly? Or do you have any reference where i can take a look? Thank you!

  • @captkalik
    @captkalik 2 года назад +1

    I put in a jwt token that was expired and it still says authorized, is there something special that needs to be done to have it not say authenticated for an expired jwt token

  • @hunterwebapps5091
    @hunterwebapps5091 2 года назад +1

    JWT usually should not be handled on client. Most people use it for authenticating with their 1:1 API. Then it should be HttpOnly Cookies.
    Thanks for sharing how to enforce on the client!

  • @Udodisgustme
    @Udodisgustme 3 года назад +3

    Hi Patrick! Thanks for great content! Sorry for stupid question but how does the app know that given jwt is valid? I know in this example it's just to show proof of concept, but in real life scenario, where would this validation occur? Is there a video related to that?

  • @alamgirkabir9983
    @alamgirkabir9983 2 года назад +1

    Do you have any course on ASP.NET Core 6.00+ MVC?

  • @AbhishekJaiswal-s5g
    @AbhishekJaiswal-s5g Год назад

    Thank You So much brother !! I was trying to do role management programmatically, but it was not working. You save my lots of time. Thank You Very Much !!!

  • @_dev_insight
    @_dev_insight 2 года назад +1

    Awesome tutorial. Will you create tutorial Blazor WebAssembly with ASP.NET Core hosted using authentication type Azure AD B2C (AddMsalAuthentication) and show how to use user flows whiting Blazor app? E.g. I know how to use sign_up_in, reset_password, but I’ve had a little problem with profile editing using the Blazor app. Have you done such a thing before? I think there are no course which shows how to use profile editing user flow (or your custom user flow) within Blazor WebAssembly app in .NET 6.

  • @Elonsovich
    @Elonsovich 10 месяцев назад

    Is this tutorial good for blazor server app too?

  • @PedalsizBerkay
    @PedalsizBerkay Год назад

    THANKS GOD REALLY !!!

  • @charlessmith2469
    @charlessmith2469 Год назад

    Hi, I followed along some of your Blazor vids but in my controller I found that the route attribute say of “id” wouldn’t work in a post, I had to specify the method and action name too.

  • @MrDinakdakan
    @MrDinakdakan 2 года назад

    sir Patrick, I have a token signed by an api, whats the best way to parse the token

  • @mrasoft7184
    @mrasoft7184 3 года назад +2

    Well done 👍🏻 I would like to see how the client will use the JWT web token on making requests to the Web API. Part of a part 2 ? 😉
    I think the client will send the JWT web token with each request towards a Web API and the Web API doing all kinds of checks with the JWT web token it receives to make sure the token is not tampered with and the client authorized to make the request.

    • @PatrickGod
      @PatrickGod  3 года назад

      You already know that, but for all the others, here's part 2: ruclips.net/video/kOnMMKxwm3I/видео.html 😊

  • @moatasemkremed5395
    @moatasemkremed5395 2 года назад

    When the account has only one role, things are fine
    but User with multiple roles fails authorization ??
    Great video keep it up

  • @fleedum
    @fleedum 2 года назад

    Great video! I already started just storing jwt token in local storage, using that to get the current user on the MainLayout, if null -> redirect to /Login, else -> /Index. Simple, custom implementation with a force reload hack since I don't have a way to subscribe to the auth state. The built-in solution is a bit too magical for me at this moment.

  • @rhuanbarros
    @rhuanbarros 2 года назад +1

    thank you clear explanation

  • @adabsaidmirzoev4134
    @adabsaidmirzoev4134 6 месяцев назад

    Hello! Thank you so much for your effort and for this video - it was very clear and informative! If it's not too much trouble, could you create a tutorial on this topic using .NET 8, focusing on JWT authentication? I appreciate it in advance and look forward to your new videos!

  • @nicolahu1692
    @nicolahu1692 Год назад

    You did not show a login page for authorization.

  • @fedoga72
    @fedoga72 2 года назад

    Excellent video, but what if there are multiple roles per user?
    Do you have an example of this please?

  • @jamesscott6864
    @jamesscott6864 2 года назад +1

    Hi Patrick, I have the user adding phone number during register to the database. i understand context user Identity name provides the user's username. but what if I as well want to get the user's phone number as well, how can I get that ?

    • @ViralityG
      @ViralityG 2 года назад

      Did you figure this out?

    • @jamesscott6864
      @jamesscott6864 2 года назад

      @@ViralityG unfortunately nope. I read the documentation of the context user and it happens you can only get the username. I use dapper and stored procedures, so the plan is to create a stored procedure to get the phone number of the context user from the database.

  • @manuelmq2043
    @manuelmq2043 Год назад

    Hi How to solve this problem. Microsoft.AspNetCore.Authorization.DefaultAuthorizationService
    Authorization failed. These requirements were not met:
    DenyAnonymousAuthorizationRequirement: Requires an authenticated user

  • @ryanb55
    @ryanb55 Год назад

    You've done a number of videos on Web API Authentication and Blazor Web Assembly authentication, but nothing with blazor server. In fact I can't find any good video on this from anyone. Any chance you could make one?

  • @mohammed2709
    @mohammed2709 Год назад

    It does working for blazor server bro ?

  • @tanzib82
    @tanzib82 Год назад

    Hello Patrick, I love your videos and followed you tutorials on Udemy for one of you projects.
    I wanted to ask a question on authentication using JWT in Blazor WASM.
    How would I check when a user is logged in in one device and attempts to login in another. I want to prevent multiple sessions by one user. At the point of 2nd Login attempt how can I give an option to log out form all logged in sessions. Like Google dose. If you can make a video on this topic i will greatly appreciate it.

  • @sylinxstark3882
    @sylinxstark3882 3 года назад +1

    Hello can i use this steps in server app ?

    • @majormartintibor
      @majormartintibor 3 года назад

      Exactly what I wanted to ask myself

    • @sylinxstark3882
      @sylinxstark3882 3 года назад +1

      @@majormartintibor It is working by changing some code lines. Its very usefull you can use if you have a project

  • @mohammadalhayani5932
    @mohammadalhayani5932 Год назад

    thank you a lot,Perfect explanation

  • @davidstraarupfabricius4203
    @davidstraarupfabricius4203 Год назад

    I have a problem with the roles part, when debugging i can see that the state that is being returned contains a role with administrator, but for some reason when using it does not seem to work, i have tried to redo the whole tutorial in a new project.. Has anybody experienced the same? anyway i will clone his project and see if i can figure something out

  • @rankarat
    @rankarat 2 года назад +1

    Great video! Thanks.

    • @PatrickGod
      @PatrickGod  2 года назад +1

      Glad you liked it! Thank you for your feedback! 😊

  • @mpumi1024
    @mpumi1024 2 года назад

    Awesome video

  • @saroshwadia
    @saroshwadia 3 года назад +2

    Please make part 2 to get a complete real life app. thx

    • @PatrickGod
      @PatrickGod  3 года назад

      Here it is: ruclips.net/video/kOnMMKxwm3I/видео.html 😊

  • @aymenfayadhi3694
    @aymenfayadhi3694 2 года назад

    Sir, Does this work with Blazor server app?

  • @emircs2442
    @emircs2442 3 года назад

    Bro, are you gonna make a video about ASP.NET MVC too?

  • @kylegivler8372
    @kylegivler8372 2 года назад

    Thanks for sharing

  • @macram4042
    @macram4042 2 года назад

    Hi Patrick, Thank you for this tutorials it so nice, but the source code in the GitHub for this is not like in your video. Hope you can find time to update the sourcecode(GitHub). Thank you in advance...

  • @rc2893
    @rc2893 3 года назад +2

    Please, please fix the video zoom changing every few seconds.

    • @grahamea
      @grahamea 3 года назад

      Didn’t even got a minute into it… too many jumps!

    • @PatrickGod
      @PatrickGod  3 года назад

      @@grahamea Thanks for the feedback. I changed it in the next video. Hope that's better now. Cheers! 😅

  • @golljhjkahsdah2817
    @golljhjkahsdah2817 9 месяцев назад

    good

  • @LukeAvedon
    @LukeAvedon 3 года назад +1

    Part 2 please!!!!!

    • @PatrickGod
      @PatrickGod  3 года назад +1

      Here it is: ruclips.net/video/kOnMMKxwm3I/видео.html 😊

  • @luisfernandodeolazabalsche3317
    @luisfernandodeolazabalsche3317 2 года назад

    Gracias.

  • @nove1398
    @nove1398 3 года назад +1

    Iron Man perhaps😄

  • @حسامالشمراني-ج2ت
    @حسامالشمراني-ج2ت 3 года назад

    فاسي ولا هو كذا؟
    🩲

  • @skuffd-semicolon
    @skuffd-semicolon 2 года назад

    Iron man????

  • @danielmuhlig7097
    @danielmuhlig7097 2 года назад +3

    Instead of using a hardcoded token, use following:
    var claims = new List { new Claim(ClaimTypes.Name, "Daniel")};
    var identity = new ClaimsIdentity(claims, "jwt");