Policy-based Authorization in ASP.Net Core (with Custom Authorization Handler)

Поділитися
Вставка
  • Опубліковано 15 жов 2024

КОМЕНТАРІ • 43

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

    my friend, you saved my life with a current project. You're amazing

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

    can you kindly tell me how to write authorization handler to keep user with same role i.e. user from editing or deleting each others records

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

    Great video, thanks!

  • @nuwan099
    @nuwan099 6 місяців тому

    Great content! thank you!

  • @xposedcadabiola.o111
    @xposedcadabiola.o111 4 роки тому

    Excellent explanation. Thank you very much.

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

    Suggestion: Video for when to use Transient, Scoped and Singleton would be really helpful. (on you realworld project experience :) )

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

      @Saurabh Chauhan, thanks for watching, and thanks for the suggestion!

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

    Excellent lesson, thank you very much.

  • @Yusuf-777-YM
    @Yusuf-777-YM 4 роки тому +2

    great works! Keep it up.

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

    good vide , but i have question , what if my Roles are created on the running of the Application , it should not be hard coded here specially when you are using RequireRole function

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

      @Osama ALSHABANi, thanks for watching!
      For your question, roles are usually decided as part of the requirement gathering process, not so much as a part of runtime code.
      But if you have a scenario where roles are created dynamically, in that case, you cannot use it this way for sure.

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

    thanks for sharing, great video!!

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

    great vid. but unrelated question, what 's the name of the extension that you're using to get when the code was committed last and by whom?

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

      It comes by default in visual studio pro and enterprise, it's called git blame

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

      @@KunalMukherjee3701 aha that's why I don't have it, I use community. Thanks for the reply!

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

    Thank you very much. Can you also make a video on how to change the user claim after the user is logged in. Need a flexibility to refresh the claims of the user without asking him to log out and login again.

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

      @yoges waran, thanks for watching the video!
      If I understand your requirement correctly, what you are looking for is the refresh token implementation. I have done a video on the same here: ua-cam.com/video/7JP7V59X1sk/v-deo.html
      Please take a look and let me know if this serves your purpose.

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

    First of all, great video.
    Got a quick question, at 16:58, you replaced the previous policy "AdminAndPowerUser" with the new one "EmployeeWithMoreThan20Years".
    What if I want to keep the previous one as well, so a user who is an Admin but has worked less than 20 years can still have the access?
    Could you please help to explain how to implement that? Thanks very much.

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

      @Chenru Yan, I am not 100% sure, I will have to try it out, but the easiest solution I can think of is creating a new policy to cover all the scenarios.

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

      @@DotNetCoreCentral Thanks for your reply. For the new policy, does that mean a new handler will be created to check if the user belongs to Admin or PowerUser or has worked more than 20 years? That feels like repeating what already have been done in the other two policies. Just curious is possible in the Startup.cs file, do something such as
      options.AddPolicy("Combined", policy => policy.Add("AdminAndPowerUser", "EmployeeWithMoreThan20Years"));
      I am quite new to ASP.NET, please bear with all my naive questions.

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

      @@yanchenru This post in stack overflow should help you with your requirement: stackoverflow.com/questions/35609632/asp-net-5-authorize-against-two-or-more-policies-or-combined-policy

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

      @@DotNetCoreCentral Thank you for the information, it is very helpful.

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

      @@yanchenru you are welcome!

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

    very helpful

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

    how can we fetch roles from db and use in handler

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

      @saveen gs, it should be just like any other place where you access the database. You do it from the middleware for authentication.

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

      @@DotNetCoreCentral thankq

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

    Really tnx

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

    My friend it's authorization not authentication.
    You can authenticate yourself with bearer token, cookie etc. - just to tell who you are.
    You can authorize yourself with policies or roles - check if you're allowed to do something.

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

    Thank you!

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

      @Karen D, thanks for watching!

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

      @@DotNetCoreCentral It was very straight forward and to the point, answered exactly what I was looking for!

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

      @@karenj5880 glad this video could help!