ASP.NET Core JWT Authentication and role-based authorization

Sdílet
Vložit
  • čas přidán 30. 01. 2023
  • 💻Get the source code: go.dotnetacademy.io/howtoprot...
    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/courses
    🗺️Get My Free .NET Backend Developer Roadmap: juliocasal.com/roadmap
    Join me on Patreon: / juliocasal
    Follow me on LinkedIn: / juliocasal
    Follow me on X: x.com/julioc
    #dotnet #aspnetcore #aspnet

Komentáře • 26

  • @praveenverma7470
    @praveenverma7470 Před 21 dnem +1

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

  • @vinaysoni4363
    @vinaysoni4363 Před rokem +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. ❤️

  • @Kibinas
    @Kibinas Před 9 měsíci +1

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

  • @messenja2547
    @messenja2547 Před rokem

    Love ur explanation Julio, thanks for sharing

  • @rohitnaiksawal6925
    @rohitnaiksawal6925 Před měsícem

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

  • @abdurrehman-bx1yo
    @abdurrehman-bx1yo Před 7 měsíci +1

    Thanks, very much helpful 👌

  • @sidisidahmed755
    @sidisidahmed755 Před rokem

    Thank you

  • @EldonElledge
    @EldonElledge Před rokem +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.

  • @awaisshabir9169
    @awaisshabir9169 Před rokem

    Great content

  • @user-rd4oo1jg5g
    @user-rd4oo1jg5g Před 11 měsíci +1

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

    • @juliocasal
      @juliocasal  Před 11 měsíci

      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.

  • @abdurrehman-bx1yo
    @abdurrehman-bx1yo Před 5 měsíci +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  Před 5 měsíci

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

  • @geraldsonperez6287
    @geraldsonperez6287 Před rokem

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

    • @juliocasal
      @juliocasal  Před rokem

      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

  • @flash7919
    @flash7919 Před 12 dny

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

    • @juliocasal
      @juliocasal  Před 12 dny +1

      dotnet new blazor -au Individual

    • @flash7919
      @flash7919 Před 12 dny

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