ASP.NET Core 3 - Authentication - Ep.3 Authorization (UPDATED: READ DESCRIPTION)

Поділитися
Вставка
  • Опубліковано 15 жов 2024
  • In this episode we dissect the mechanism behind Authorization - Policies. We explore the 3 main moving parts of Policies exposed to you:
    NOTICE - UPDATED PLAYLIST
    • ASP.NET Core Authentic...
    Patreon 🤝 / raw_coding
    Courses 📚 learning.raw-c...
    Shop 🛒 shop.raw-codin...
    Discord 💬 / discord
    Twitter 📣 / anton_t0shik
    Twitch 🎥 / raw_coding
    👉 Try Rider
    www.jetbrains....
    RD5K9-4TXXW-KMV3G-NYWSF-3ZSTP
    AuthorizationPolicy (Created by using an AuthorizationPolicyBuilder)
    IAuthorizationRequirement (This is your request for a specific type of authorization)
    AuthorizationHandler (This is the function which knows how to process the requirement)
    Roles are just claims. rant over. Why have them? the concept of a role is more familiar than a claim to a human. For example what is easier to understand? - "What is your Role?" or "What do you claim to be?"
    Source: github.com/T0s...
    #csharp #aspnetcore #auth

КОМЕНТАРІ • 150

  • @sh00termacg
    @sh00termacg 4 роки тому +28

    Brilliant, you're a very very clever guy. You know this stuff at a fundamental level and your delivery is top notch!

  • @drspyqwerty
    @drspyqwerty 4 роки тому +4

    THE BEST series. So much Info. I have watched it twice to get all the little details. Stick with it, absolutely worth it.

  • @KhanhNguyen-pq6kn
    @KhanhNguyen-pq6kn 4 роки тому +2

    Subcribed after 2 videos... the concept explaining was great, not as much as blindly practice out there... i'm looking for further of you.
    Once again... thanks mate!!

    • @RawCoding
      @RawCoding  4 роки тому

      Thank you, glad you liked it!

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

    I gone through most of the authentication and authorization stuff, its really good. Just one suggestion if possibly you put advertisements at start, as it breaks the rhythm if it comes while learning. Thanks for sharing great stuff in simplest possible way,

  • @tyge7927
    @tyge7927 4 роки тому +8

    Just wanna say even in August 2020, you're saving someone's ass (mine). Thank you very much and hope you're doing fine.

    • @RawCoding
      @RawCoding  4 роки тому +3

      It’s not even been a year :D

    • @gonaz
      @gonaz 3 роки тому +1

      @@RawCoding you don't even know how many people you're helping, nobody does videos about this, Devs sometimes assume that everyone knows this topics

  • @wolfvandenzegel6534
    @wolfvandenzegel6534 2 роки тому

    This series has helped me leaps and bounds in understanding this otherwise very poorly documented featureset, thank you very much!

  • @relativenormality
    @relativenormality 4 роки тому +1

    Another excellent video. I like the style - show the default and deconstruct it so you can understand what is going on - this gives you confidence. Been studying up on Identity during lockdown and this cuts through everything else I have looked at so far.

    • @RawCoding
      @RawCoding  4 роки тому

      Thank you for watching :)

  • @mahmutyldz371
    @mahmutyldz371 4 роки тому +18

    you are the best lecturer in the world ;)

  • @shilpamore4866
    @shilpamore4866 4 роки тому +1

    Complex concept explained so easily. Appreciate your effort.

  • @ShivamSingh-wy8om
    @ShivamSingh-wy8om 4 роки тому +2

    Thanks for sharing this, this is the best tutorial explaining Identity on internet i have come across so far.

    • @RawCoding
      @RawCoding  4 роки тому +1

      Thank you:)

    • @abcdeika
      @abcdeika 4 роки тому

      @@RawCoding that IS true. I've been pointlessly searching for guides, tutorials, videos and all of them are either useless aka (DOTHING METHOD) or out-of-date.
      Thank you. THANK YOU! Gonna watch all of the videos on the channel.

  • @kamuykaz01
    @kamuykaz01 3 роки тому +1

    Super video ! I am using your stuff to understand and implement identity to my project.

    • @RawCoding
      @RawCoding  3 роки тому

      Awesome, hope it works out!

  • @naveedkhanhome
    @naveedkhanhome 2 роки тому +1

    Nice and very concise and clear. Thanks

  • @FernandoJavierSosa
    @FernandoJavierSosa 3 роки тому +1

    I neved saw an explanation of Claims, Policies and Authorization as clear as this video.

  • @rolanddensonjr2464
    @rolanddensonjr2464 4 роки тому +1

    You have definitely gained a subscriber. Very nice video. Keep up the good content.

  • @jamesallen74
    @jamesallen74 4 роки тому +1

    VERY nice video. Very nice refresher on how to do configuration also.

    • @RawCoding
      @RawCoding  4 роки тому

      Cheers

    • @jamesallen74
      @jamesallen74 4 роки тому

      @@RawCoding LOL I posted this comment on the wrong clip. I meant to do this for the last video on the email verification.

  • @navarromal
    @navarromal 4 роки тому +1

    simply the best, man! you are very clear and concise...clever!

  • @anurag3487
    @anurag3487 3 роки тому +1

    amazing. you know these stuffs on a very granular level. I learnt a lot. Thanks

    • @RawCoding
      @RawCoding  3 роки тому +1

      Thank you for watching

  • @mateuszlesko5301
    @mateuszlesko5301 3 роки тому +1

    Keep going with uploading of solid quality materials !!

  • @hassysid9338
    @hassysid9338 2 роки тому

    Thanks dude ...awesometacular ...by the way which keyboard do you use...liked the clicks 😀

  • @pradeeppradyumna601
    @pradeeppradyumna601 3 роки тому +1

    Great tutorial bud ! Appreciate all the efforts

    • @RawCoding
      @RawCoding  3 роки тому

      Thank you for watching

  • @bertolimauro
    @bertolimauro 4 роки тому +7

    Congrats! Really well done videos! I think you are one of the best lectures on UA-cam! It's not easy to explain these concepts deeply as you are doing. Just out of curiosity... what's your background in asp.net core?

    • @RawCoding
      @RawCoding  4 роки тому +9

      Thank you, glad you enjoyed these! I've been doing dotnet professionally for about 3-4 years now. Wide variety of applications.

  • @satyamprakash6917
    @satyamprakash6917 4 роки тому +1

    Thanks for the video, you solved my problems in a few minutes. best lecture on .net core and authorization on youtube.

    • @RawCoding
      @RawCoding  4 роки тому

      Thank you for watching))

  • @mfundofalteni2620
    @mfundofalteni2620 4 роки тому +1

    Thank you for these wonderful videos. I am learning a lot.

  • @farisfajar6982
    @farisfajar6982 4 роки тому +1

    Dear Raw Coding, Thanks for the series. this comment may be small but your video tells bigger than that.

  • @benedictpardo6366
    @benedictpardo6366 4 роки тому +1

    Interesting! Now its Role-based vs Policy-based authorization were explained! Okay, this is epic!

    • @RawCoding
      @RawCoding  4 роки тому

      Glad you enjoying these

  • @fabienmolinet8491
    @fabienmolinet8491 4 роки тому +1

    Your videos are excellent, keep up the good work!

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

    Amazing course!

  • @sarvarthmonga5764
    @sarvarthmonga5764 4 роки тому +1

    Mind Blowing, Awesome work. I have a request can you also share/create a video in which you are explaining DependencyInjection lifetimes. Thanks

    • @RawCoding
      @RawCoding  4 роки тому

      I’ve made a video about that, I’ve also have a video about how it works ;)

    • @sarvarthmonga5764
      @sarvarthmonga5764 4 роки тому +1

      @@RawCoding I saw that, but i wanted to like have an idea, when to use which lifetime. If you can provide some resource that will be awesome too

    • @RawCoding
      @RawCoding  4 роки тому +1

      ua-cam.com/video/01C8selSVCY/v-deo.html have you watched this?

    • @sarvarthmonga5764
      @sarvarthmonga5764 4 роки тому +1

      @@RawCoding Bro you are awesome

    • @sarvarthmonga5764
      @sarvarthmonga5764 4 роки тому +1

      @@RawCoding Thanks so much

  • @stevemcqueen2887
    @stevemcqueen2887 3 роки тому +1

    I was with you until 16min in when you just if you want to make it an extension method then you can do this...
    1) whats an extension method?
    2) why would I want to?
    3) will it work without it?

    • @stevemcqueen2887
      @stevemcqueen2887 3 роки тому +1

      Extension method
      They allow you to add new methods to an existing class.
      This means we don't need to modify the original class to add these new methods.
      So you can have an existing library written by someone else and add your own custom code to it without modifying the library itself.
      It must be static.

    • @RawCoding
      @RawCoding  3 роки тому +1

      nice one

  • @k3vinshum
    @k3vinshum 3 роки тому +1

    Great video. Great series. One thing though about the roles. When you specify role in the attribute tag you can put that on a selection of methods and not all. The claims example you show of requiring the claim role would enforce on all methods with the authorized tag would it not?

    • @RawCoding
      @RawCoding  3 роки тому +1

      The claims example works with policies

    • @k3vinshum
      @k3vinshum 3 роки тому +1

      @@RawCoding but the policy is applied globally in the middleware setup is it not? Clearly I am missing something - could you please explain how to apply a different policy per endpoint?

    • @k3vinshum
      @k3vinshum 3 роки тому +1

      @@RawCoding think i got it now. You can AddPolicy and choose which one to use. You can also set the DefaultPolicy which is where I got confused. Awesome thanks

    • @RawCoding
      @RawCoding  3 роки тому +1

      You build the police in the ConfigureServices , and then you use it across your application when you need to

  • @ilovepandaypoe6056
    @ilovepandaypoe6056 4 роки тому +3

    The best tutorial! Thanks much

    • @RawCoding
      @RawCoding  4 роки тому

      Glad you enjoying these!

  • @MrShakir820
    @MrShakir820 4 роки тому +1

    Brilliant brother!

  • @WikkiOnIlluminati
    @WikkiOnIlluminati 3 роки тому +2

    @5:34 as Anton suggested to understand and learn claims and policies. I found these two articles having concept explained very well. At least for me
    Declarative Claims-Based Authentication in ASP.NET Core 3.0
    visualstudiomagazine.com/articles/2019/10/29/aspnet-authentication.aspx
    Working with Claims to Authorize Users in ASP.NET Core and Blazor
    visualstudiomagazine.com/articles/2019/11/06/working-with-claims.aspx

    • @RawCoding
      @RawCoding  3 роки тому +1

      Thank you for sharing

  • @浮尘-o4u
    @浮尘-o4u 2 роки тому +1

    Great job❤

    • @RawCoding
      @RawCoding  2 роки тому

      Don’t forget to check out the new videos !

  • @FernandoJavierSosa
    @FernandoJavierSosa 3 роки тому +1

    thank you, thank you!

    • @RawCoding
      @RawCoding  3 роки тому

      Think you for watching

  • @naveensellappan4016
    @naveensellappan4016 3 роки тому +1

    Hi
    Thank you so much for the lecture man,
    I have a doubt, the AuthorizationPolicyBuilderExtensions class you defined does not inherit an Interface or an abstract class, so how does the policy builder uses the RequireCustomClaim method in the AuthorizationPolicyBuilderExtensions ?

    • @RawCoding
      @RawCoding  3 роки тому

      it's a basic c# extension method, it doesn't need to inherit from an interface or an abstract class.
      docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods

    • @naveensellappan4016
      @naveensellappan4016 3 роки тому

      @@RawCoding Thanks man

  • @chenshang920
    @chenshang920 4 роки тому +1

    Thanks for the video.

    • @RawCoding
      @RawCoding  4 роки тому

      Thank you for watching!

  • @vahidjafari1369
    @vahidjafari1369 4 роки тому +2

    Thank you, it was amazing!!!

  • @rahimliparviz
    @rahimliparviz 3 роки тому +1

    Hello ,I just cannot understand why we should register this middleware "app.UseAuthorization()" on startap class.On my demo project I use Authorise filter without this middleware and with JWT authentication and everything works fine .So for what cases or for waht reason we have to use this middleware ?.If you have time please reply to me,thanks in advance.

    • @RawCoding
      @RawCoding  3 роки тому +2

      > UseAuthorisation
      look at HttpContext for a cookie / access_token in the header or query or anywhere in the request.
      > UseAuthorization
      look at the ClaimsPrincipal that has been added to the HttpContext and verify it's allowed based on the controller. It takes care of invoking the correct authorization handler for your [Authorize] attribute and checks the ClaimsPrincipal
      hope this helps.

  • @MedBouchenafa
    @MedBouchenafa 4 роки тому +1

    Again, a great tutorial
    Thanks a lot
    You have a new subscriber!!!

  • @ranadebpramanick469
    @ranadebpramanick469 3 роки тому +1

    hi,
    In your video when we get an access denied because of the absence of a claim , why does your browser show 404 status code? Shouldn't it be 403 unauthorized request?

    • @RawCoding
      @RawCoding  3 роки тому +1

      404 because the Access Denied page is not found.

  • @manisharma3068
    @manisharma3068 4 роки тому +1

    Noob question..sorry..
    How does injecting some services(like the Datacontext) into the authorizationHandler affect the decision of whether or not making it a scoped handler or a singleton?

    • @RawCoding
      @RawCoding  4 роки тому +1

      You should have it scoped off you are injecting. If you are making it a singleton you should resolve the DbContext through the IServiceProvider interface

    • @manisharma3068
      @manisharma3068 4 роки тому

      Ok, Thanks so much!

  • @swanandpangam
    @swanandpangam 3 роки тому +1

    I don't see any ctor for AuthorizationPolicyBuilder taking zero params in .NET 5.0. I was trying to see if I can overwrite the default policy with a new policy which doesn't call the RequireAuthenticatedUser() method and to see what happens. Thanks

    • @RawCoding
      @RawCoding  3 роки тому +1

      Looks like it, you'll need to specify the schema as well

  • @KunalMukherjee3701
    @KunalMukherjee3701 3 роки тому +1

    Hey Anton! Want to see a video on pagination with dapper

  • @developerRG
    @developerRG 11 місяців тому

    Thank you for your Greatest vedios on youtube, 🎉 bu i have question please , How you understand this topic to make it very easy to explain like piece of cake 😊?

  • @jamesbest2221
    @jamesbest2221 5 років тому +2

    Awesome! Than you!

  • @cyjbox
    @cyjbox 4 роки тому +1

    thank you, good tutorials.

    • @RawCoding
      @RawCoding  4 роки тому

      Thank you for watching :)

  • @cyjbox
    @cyjbox 4 роки тому +1

    the action's authorization and the authorize policy are written in code, can they be configured on runtime? hope you understand my horrible English.

    • @RawCoding
      @RawCoding  4 роки тому

      Yes they can be, however I’m not explaining the solution because it’s quite a hard one

  • @theguruman99
    @theguruman99 4 роки тому +1

    Hi - and thanks for a great tutorial. I've followed all the preceding tutorials and they are all great. I am looking into what you said about "Roles" - that you presume this is legacy code. I've been looking for more info on this on the internet but there is virtually nothing to back this up. "Roles" still feature very prominently in Authorization documentation and tutorials. Can you please point me in the right direction where it states categorically that Roles should no longer be used for Authorization. Many thanks in advance.

    • @RawCoding
      @RawCoding  4 роки тому

      Well that’s not correct roles are just a way to represent a real world model

    • @picflight
      @picflight 4 роки тому +1

      Raw Coding , is using the Claims rather Roles the preferred way?
      I too am wondering if Roles are legacy.

    • @RawCoding
      @RawCoding  4 роки тому

      @@picflight if you have the concept of Roles in your domain, use Roles.

    • @picflight
      @picflight 4 роки тому

      Raw Coding , thanks.

  • @ManavDIY
    @ManavDIY 4 роки тому +2

    Does this Authentication and Authorization work on .NET Core Web API? I'm planning to build Web API and leverage Vue.Js for the client-side.
    By the way, thanks for the great video. Well Explained!

  • @Patrick-il3uy
    @Patrick-il3uy 4 роки тому +5

    Great tutorials. Thank you for that.
    You very often scroll or jump too fast. I always have to pause the video or go back. Would be way more better if you add some little breaks (just 2-3 seconds).

    • @RawCoding
      @RawCoding  4 роки тому +1

      Thank you very much for your feedback

    • @LaurenceNairne
      @LaurenceNairne 3 роки тому +1

      Personally I think a lack of breaks is fine. The fact that you can pause to catch up and/or change the playback speed means that everybody can do it at their own pace. There's also the source if you need to see something that you missed because the author doesn't spend long enough looking at particular lines.
      My time to spend with videos is precious, if this one wasn't so concise and to the point, I'd have given up on it (like I have with many others).

    • @RawCoding
      @RawCoding  3 роки тому

      Thank you )

  • @serb1146
    @serb1146 4 роки тому +1

    Отличные уроки, спасибо.

  • @blackwhiteyang9533
    @blackwhiteyang9533 4 роки тому +1

    Thanks

    • @RawCoding
      @RawCoding  4 роки тому

      thank you for watching :)

  • @gevanjayasinghe2693
    @gevanjayasinghe2693 4 роки тому +1

    Superb

  • @kamarchand
    @kamarchand 4 роки тому +1

    Can you add to you list the windows authentication for people who design for an intranet website. regards

    • @RawCoding
      @RawCoding  4 роки тому

      I will see what I can do, because there are a couple of problems that arise with this. 1st is you lose the cross-platform feature 2nd is I don't have the infrastructure at home (win10 professional or Active Directory)

    • @kamarchand
      @kamarchand 4 роки тому +1

      @@RawCoding I understand. great video I really enjoying them. keep the good work.

  • @ripper9112
    @ripper9112 4 роки тому +1

    What is Trifecta ur talking about?
    I googled trifecta programming and trifecta ASP and theres no explanation.

    • @RawCoding
      @RawCoding  4 роки тому

      Can you give me a timestamp in the video where I say it? It's not a design pattern or anything like that, it only has meaning in the context that I say it in, probably just highlighting a trio of something, like three things that work together.

    • @ripper9112
      @ripper9112 4 роки тому +1

      @@RawCoding If its not design pattern or any concept, and u just meant 3 things thats enough for me, Thanks. If i remember corrently it was in Configuration in startup class.
      Theres a lot of people watching whos english is not native language like me, using as simple language as possible is very importatnt for clarity espetially for begginners.
      Not that you use overly thechnical language, but its good to be aware of that for u as content creator of this type.

    • @RawCoding
      @RawCoding  4 роки тому +1

      @@ripper9112 sorry about the confusion, thank you for taking the time to point this out.

  • @raghurambhagawatula7025
    @raghurambhagawatula7025 3 роки тому +1

    Hi, can someone point to me if there is a tutorial on setting up MFA using Email in this series

  • @phuocnguyen2201
    @phuocnguyen2201 3 роки тому +1

    I wouldn't fail the interview, if I found your video sooner. That sucks 😕.

    • @RawCoding
      @RawCoding  3 роки тому

      Better luck next time!

  • @yamildiaz9393
    @yamildiaz9393 4 роки тому +2

    If we use AD from Microsoft server, how can we give claims and policies to each user in our sql database?

    • @RawCoding
      @RawCoding  4 роки тому

      You have pass the windows authentication token. Once you do that you can inspect the IdentityPrinciple and the Claims that it has. The AD groups that the user is in should show up there.

    • @cybernet8656
      @cybernet8656 4 роки тому +1

      How do you pass a windows authentication token? Maybe have a tutorial on this!

    • @RawCoding
      @RawCoding  4 роки тому +1

      @@cybernet8656 I don't have a professional environment setup do demonstrate it to the level I'd like to. You can see the basics here: docs.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?view=aspnetcore-3.1&tabs=visual-studio it's pretty straight forward

  • @nareshnarasimhalu
    @nareshnarasimhalu 4 роки тому +1

    11:49, in CustomRequireClaim.cs file,
    i put foreach instead of =>
    var hasClaim = context.User.Claims.Any(x => x.Type == requirement.ClaimType);
    i.e line number 23.
    as
    foreach(var value in context.User.Claims)
    {
    if(value.Type == requirement.ClaimType)
    {
    hasClaim = true;
    }
    else
    {
    hasClaim = false;
    }
    }
    but when i viewed value.Type i am getting => nameidentifier and
    requirement.ClaimType => dateofbirth
    why its so. because of which i am getting AccessDenied

    • @RawCoding
      @RawCoding  4 роки тому

      Once you find the true condition you need to break the loop otherwise you override it.

  • @vandeljasonstrypper6734
    @vandeljasonstrypper6734 2 роки тому

    Can policy can be able to dynamic ?

  • @santukumar-om3by
    @santukumar-om3by 4 роки тому +1

    Please make a video on store encrypted password in database with hash + salt.

    • @RawCoding
      @RawCoding  4 роки тому +1

      It's done automatically by Identity. Do not roll your own. I will not be making a video on this.

    • @santukumar-om3by
      @santukumar-om3by 4 роки тому +1

      Is it possible to give any resources or video for encrypted password by identity.

    • @RawCoding
      @RawCoding  4 роки тому +1

      @@santukumar-om3by I show you how to do it in episode 2... The password hash is created when you create a user with the password. UserManager handles that, SignInManager also creates the hash to check if the entered password is correct. The hash is not reversable.

  • @dexterman6361
    @dexterman6361 4 роки тому +1

    Holy shit, this makes so much sense!. How does someone learn this, and understand something so well? Kudos to you for understanding it, and explaining it/articulating it well, and for free, on UA-cam. Damn. Mind Blown! Thank you very much for this series!
    P.S. Is there anywhere I can ask you a few questions on the developer journey? My email is alien243600@gmail.com Having recently graduated, I somehow feel I'm behind the industry expectations.

    • @RawCoding
      @RawCoding  4 роки тому

      cheers, join the discord channel