ASP.NET Core SSO with Cookie Authentication (.NET 7 Minimal Apis C#)

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

КОМЕНТАРІ • 91

  • @themt.oceans
    @themt.oceans Рік тому +1

    I just subscribed! I love how clearly and quickly you get down to the details and skip all the talking and unnecessary (off topic) code. Well done!

  • @allinvanguard
    @allinvanguard 2 роки тому +8

    Neat tutorial man. I recently went through that exact same issue as well, so it's good for me to see that I did it the right way. It's pretty straight forward once you know about dataprotection and schemes, but man, I wish that dotnet Identity made it a little bit easier to get through the whole scheme constants and setup mess.
    Not to mention that some extension methods are severly bloated, and there's no real "minimal" setup method if you don't do it yourself. If you add scheme X, then it suddenly automatically overwrites scheme Y under the hood, which you setup with another previous method etc. ... Debugging it is hell, and no way you can do it without constantly looking into the framework sources

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

    Lol this is pretty funny timing. About a month ago I asked how to do this specific thing on your Do you need IdentityServer? video. And now when I finally sat down today to do it you came out with this video. Nice.

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

      it was meant to be :)

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

    Your explanation is always fluent and smooth. Helped a lot!

  • @Sad-Lemon
    @Sad-Lemon Рік тому +1

    Thanks Anton! Have a great day!

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

      Sad lemon thank you, hope you become happy lemon

    • @Sad-Lemon
      @Sad-Lemon Рік тому +1

      @@RawCoding It's just an anagram :) It only takes one cookie to make me smile :D

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

    Exactly the thing I needed. Thinking about migration from .NET framework to .NET 6 and running both apps behind reverse proxy with shared cookies. Thank you!

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

    This is my 4th video from your channel and none was able to disappoint! Security concepts are important and you explained them very nicely. Subscribing for such clean presentations!

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

    You won a subscriber, AMAZING tutorial

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

    great show man! very clear, hard work, great knowledge sharing!

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

    Awesome video. I used IdentityServer3 one to secure 3 apis on the same domain, and this method is much more simpler.

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

    This is exactly what I needed. Didn’t know about caddy but it looks like it’ll solve my local setup 👌🏻
    Anyway, love your videos, keep them coming

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

    Best thumbnail ever

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

    One interesting observation... The amount of views you get baffled me for quite some time. Rare are the channels that deep dive into specifics. Actually, this is the only one I know of. Pretty much everyone just wants easily digestible, short content with a dumb thumbnail and a clickbait title. ADD bastards...
    Keep up! Cheers for another good video ;)

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

    bro, you are flowless. Thank you.

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

    This was great. Thanks!
    4:50 I have a question: So after you logged into Identity -> 'localhost:7094/login' and tried to hit your app -> 'localhost:7240/protected', it redirected you to 'localhost:7240/account/login' where login isn't implemented. So is there a way to just redirect the user to the login endpoint of Identity app when they try to hit protected endpoint in the app?

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

    So are the persistent keys just pointers to cookies? What's the point of storing a keyring?
    I have two apps sharing cookies and all I had to do was call: AddDataProtection().SetApplicationName()

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

      Persisting keys means cookie works after app restart. It’s about creating the cookie using the keys.

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

    If we have projects say in Python and DotNet. How can we use SSO. One way i see is like in your YARP video. Use Dotnet project as reverse proxy. Is this the best way or is there any other way.

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

      if you want to authenticate a python app, I'd say best put it behind a YARP proxy.

  • @teseract7442
    @teseract7442 2 роки тому +2

    Sorry for ignorance., this is to emulate the handling of different cookies in localhost with different domains even if the application is the same? is it an approximation?

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

      This is a simulation of what if your auth component and spa lived on the same domain

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

      @@RawCoding Thanks! =)

  • @r0man0v-r0man
    @r0man0v-r0man 2 роки тому

    Best, as usually!!!👍

  • @deven.k93
    @deven.k93 2 роки тому +2

    I followed the exact steps, but when using the host url i am getting when trying an error while accessing the iis hosted application over a reverse proxy.
    Bad Request - Invalid Hostname
    HTTP Error 400. The request hostname is invalid.

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

      Don’t use iis can’t help

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

    I got a question here. As we are already using reverse proxy to map app.company.lcoal to localhost:port, do we need to add the app.company.local entry to hostfile explicitly? My understanding is any of that would work. Either hostfile or reverse proxy?

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

    Very nice, simple and easy to follow video. One question when to use AspNetCore Identity can you please elaborate use cases for identity. And if we have mobile version. Can we use two schemes in one project. like JWT and Cookie.

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

      Identity is user representation, and yes you can have multiple schemes in 1 project

  • @bilal-elmursi
    @bilal-elmursi 2 роки тому +2

    How can I use this approach (cookie-based authentication) with other apps that are using token-based authentication, such as SPA (JWT-based authentication) all under SSO umbrella?

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

      I don’t know what your situation is

    • @bilal-elmursi
      @bilal-elmursi 2 роки тому

      @@RawCoding Thank You!

  • @joshem32
    @joshem32 2 роки тому +2

    Just to make sure, when using cookies we’ll need to add some sort of security on top of that to avoid any xss or csrf attack, right?

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

      If you’re using razor pages no there’s and anti forgery token that gets generated, otherwise if it’s a spa then yes

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

      @@RawCoding what about Blazor server?

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

      Yes

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

    In my company we would like to migrate a set of applications from windows form to .NET Core Web app hosted in a local server. Since our PC belongs to a domain network, my idea was to structure the new infrastructure as you show in this video. So one app (IdentityServer) will be responsible to ask the user credentials and forward them via LDAP to the AD server that manages our domain credentials. When it authorizes the user, the identityserver looks for his permissions in our SQL db and then authorizes/non authorize the user to access the specific app resources… Could work?

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

    Thanks for the video and explained very well clearly. It is very helpful to everyone.
    I would like to take some suggestions from you, I am thinking create a reusable single sign-on (SSO) component can allow users to authenticate once and gain access to multiple applications without having to sign in again. This component can be designed to work with different SSO protocols, such as SAML, OAuth2, or OpenID Connect, and can provide APIs for integrating with different identity providers, such as Active Directory, Google, or Facebook.
    Is it good idea or not?
    Is it useful if someone wants to implement SSO in their applications?

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

    Hey man, im getting this error
    'IServiceCollection' does not contain a definition for 'AddAuthorization' and the best extension method overload 'MvcCoreMvcCoreBuilderExtensions.AddAuthorization(IMvcCoreBuilder, Action)' requires a receiver of type 'IMvcCoreBuilder' RestfulApi

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

      Paste piece of code

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

      @@RawCoding ​ @Raw Coding
      Thanks for replying I appreciate this.
      //Authentication
      builder.Services.AddAuthentication();
      builder.Services.AddAuthorization(CookieAuthenticationDefaults.AuthenticationScheme)
      .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme);

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

      Add cookie and scheme specification goes into he AddAuthentication method

  • @alfonsdeda8912
    @alfonsdeda8912 5 місяців тому

    Amazing tutorial!
    How can i share logged user between multiple blazor apps using identity in .net 8?

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

    Official dotnet template for SPAs was a mistake. They forced IdentityServer on everyone's throat even though it is a simple system with one SPA client. Probably the biggest reason people started misusing IdentityServer. Hey, if template says this is good then why not use it. Not to mention that client side code in that template, especially in react, is outdated af.

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

      I’ll bundle this mistake in to the “stop using the run button” category

    • @awmy3109
      @awmy3109 2 роки тому +2

      Cookies is not the right way to do SSO. Do your research on why it is bad.

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

      "Do your research." aka "I don't really understand"

    • @awmy3109
      @awmy3109 2 роки тому +2

      @@RawCoding It means you're suffering from Dunning Kruger. You and this person somehow think you know better than the dotnet team made of people with more experience. SSO is more complicated than you think, don't have the time to write a full essay on it here when a couple minutes of dropping your dunning Kruger and doing some research online will be of more benefit and help you get the point.

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

      I don’t know a Mr Kruger mate, but as if to prove my point you came back to say that you don’t know but now in the form of don’t want to write an essay.

  • @naveenpujari8996
    @naveenpujari8996 6 місяців тому +1

    order of authentiction and authrization matters or not.? you mention aurthrization first in piple line service.addauthrization

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

      Yes it does, authN authentication is about WHO ARE YOU? authZ authorization is about ARE YOU ALLOWED?
      If we dont know who you are, we cant start answering are you allowed…

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

      @@RawCoding so yours viideo clip should be updated or you may need to drop a disclaimer and for users . as you have mentioned order viseversa.

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

    Hey there! Nice video. I have a question, is it possible to use the same steps to protect MVC applications? I've been struggling to make my SSO application work. It would be nice if someone could share some code! Thanks in advance.

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

      Yes you can, just adapt the solution make sure you can’t cross site attack the login endpoint if you post from spa

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

    Awesome

  • @awmy3109
    @awmy3109 2 роки тому +2

    How will your mobile apps, other native apps or other apps not written in .net core or deployed on different servers use your "SSO"?. This shouldn't be done in real world apps for SS0.

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

      There's isn't an SSO solution out there that doesn't use cookies. To extend this solution to Native apps you use auth flow, and store the tokens on the backend, meanwhile the Native app still get's a cookie.

    • @awmy3109
      @awmy3109 2 роки тому +2

      @@RawCoding You're not getting the point. Shared Cookies between apps won't scale for SSO. Infact, that isn't SSO. The standard for SSO is either SAML or OpenId.

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

      Yea what I mean by auth flow is openid, auth code flow with pkce to be specific. And it’s an extension on the solution in the video.

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

      @@RawCoding Okay.

    • @hero3616
      @hero3616 2 роки тому +2

      @@awmy3109 correct

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

    Can we use this method with multiple angular frontends to make sso ?

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

      As long as they are all on the same domain

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

      @@RawCoding they are like this
      Apps.domain/app1
      Apps domain/app2
      They are sub applications on iis on same domain domain

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

      Sound good

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

    Do you have to use redis?

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

      If you’re on about the data protection api, nope you can use file system .

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

    I m ur new subscriber stay connected

  • @nove1398
    @nove1398 2 роки тому +2

    Suppose you don't want to persist the login beyond a session?

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

      Is that like the login session having an out of body experience?

  • @bluecup25
    @bluecup25 6 днів тому

    rediz nutz ha

  • @bramburn
    @bramburn 2 роки тому +2

    i saw a car

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

      Haha but did you hear it :D

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

      @@RawCoding no i didn't was there suppose to be sound?

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

      There was a car driving outside my window at that point so yeah :D