ASP.NET Core JWT Authentication and role-based authorization

Поділитися
Вставка
  • Опубліковано 15 жов 2024
  • 💻Get the source code: go.dotnetacade...
    A solid REST API should make sure that its resources are protected so that only authorized users and clients can get access to them. And thanks to the latest innovations in ASP.NET Core, protecting your Web API could not be easier.
    Here I'll show you how to protect your ASP.NET Core Web API in just a few steps.
    Topics covered:
    00:28 Understanding Token-Based Authentication
    01:56 Creating a simple minimal API
    08:13 Using JWT authentication and requiring authorization
    13:02 Generating tokens with dotnet user-jwts
    14:50 Understanding Json Web Tokens (JWT)
    21:42 Implementing role based authorization
    24:43 Extracting user information via ClaimsPrincipal
    33:03 Evaluating user claims
    🔥Become a Senior C# Backend Engineer: juliocasal.com...
    🗺️Get My Free .NET Backend Developer Roadmap: juliocasal.com...
    Join me on Patreon: / juliocasal
    Follow me on LinkedIn: / juliocasal
    Follow me on X: x.com/julioc
    #dotnet #aspnetcore #aspnet

КОМЕНТАРІ • 35

  • @vinaysoni4363
    @vinaysoni4363 Рік тому +2

    This is the amazing explanation regarding Api authentication and authorisation process along with real action demonstration.
    I really appreciate your efforts to make this concept easy to understand and digest. ❤️

  • @damianjankov3343
    @damianjankov3343 2 місяці тому +1

    Finally a video where I understood the concept! Thanks

  • @Kibinas
    @Kibinas Рік тому +1

    Great tutorial, I appreciate simplicity and you deliver quality content without any cumbersome code

  • @praveenverma7470
    @praveenverma7470 3 місяці тому +1

    Great tutorial, learned a new way to test the API without switching to postman, swagger or using curl. 🙂

  • @RaWMajkeL
    @RaWMajkeL 21 день тому +1

    Thing of beauty, thanks for the video

    • @juliocasal
      @juliocasal  21 день тому +1

      Glad you enjoyed it

    • @RaWMajkeL
      @RaWMajkeL 21 день тому

      @@juliocasal maybe something about modular architecture in the future? 👀

    • @juliocasal
      @juliocasal  21 день тому

      @@RaWMajkeL Modular architecture?

    • @RaWMajkeL
      @RaWMajkeL 20 днів тому

      @@juliocasal I meant modular monolith pattern

  • @EldonElledge
    @EldonElledge Рік тому +2

    This was very well done and great content. I would like to call out that, it is best practice to use a Reference Token for communicating from the UI to an API, in place of a jwt token. Jwt tokens are still a valid choice to use between services.

  • @rohitnaiksawal6925
    @rohitnaiksawal6925 4 місяці тому

    You are simply Awesome Julio! Thank you for your efforts....

  • @abdurrehman-bx1yo
    @abdurrehman-bx1yo 9 місяців тому +1

    Thanks, very much helpful 👌

  • @abdurrehman-bx1yo
    @abdurrehman-bx1yo 8 місяців тому +1

    Hi, I Have a question. If we do not want to call RequireAuthorization on a endpoint (I just want the user to be authenticated for a specific endpoint and no other things needed like role etc.), it's not even validating the token. I mean, if token is not there it still returns result. What is happening here, could you please explain.

    • @juliocasal
      @juliocasal  8 місяців тому

      Without the RequireAuthorization call you basically have an anonymous endpoint. Call RequireAuthorization with no parameters instead.

  • @messenja2547
    @messenja2547 Рік тому

    Love ur explanation Julio, thanks for sharing

  • @testtest-c4z
    @testtest-c4z Рік тому +1

    What is the difference between Claim and Signature? what does each one reference?

    • @juliocasal
      @juliocasal  Рік тому

      Claims are the pieces of information being asserted about a subject (the user, typically). The signature is used to verify that the sender of the JWT is who it says it is and to ensure that the message wasn't changed along the way.

  • @flash7919
    @flash7919 3 місяці тому

    Thank you for this great tutorial
    How I can generate a code and make register page and login

    • @juliocasal
      @juliocasal  3 місяці тому +1

      dotnet new blazor -au Individual

    • @flash7919
      @flash7919 3 місяці тому

      @@juliocasal I wanna make a webapi and for front-end I wanna use reactjs
      how I can make this mix

  • @geraldsonperez6287
    @geraldsonperez6287 Рік тому

    How would I generate token for the users of my API with this package?

    • @juliocasal
      @juliocasal  Рік тому

      Geraldson, generating tokens for real users involves introducing an identity provider, either built by yourself or already built for you. I cover that in my .NET microservices program, here: dotnetmicroservices.com/building-microservices-with-dotnet

  • @sidisidahmed755
    @sidisidahmed755 Рік тому

    Thank you

  • @awaisshabir9169
    @awaisshabir9169 Рік тому

    Great content

  • @TranTien-kx2mj
    @TranTien-kx2mj 10 днів тому

    Bro should apply this into your Microservice course 🥲🥲

    • @juliocasal
      @juliocasal  10 днів тому

      New .NET Bootcamp coming soon!