ASP.NET Core Angular Authentication with Identity & EF Core

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

КОМЕНТАРІ • 46

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

    Really heplful. Love your .NET Core series. As a frontend developer was strugling to implement proper auth with Identity on my project, this series really helped a lot to wrap my head around it.

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

      Also, your way of explaining things is great

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

    6:56 the software engineers mindset, love that! amazing videos as always

  • @a_ghoul
    @a_ghoul 11 місяців тому +1

    im about to start a job where I am gonna be doing this. Thanks for the tutorial!!!! Likely gonna be coming back to ask a question lol

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

    This was very helpful. By following this video, I was able to add authentication to a React + .NET Web API application.

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

    As I've seen from TS developer, he returns Observable from HttpClient

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

      seems to be the right approach!

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

    Angular + .NET = ❤

  • @jeheecheon8397
    @jeheecheon8397 Рік тому +3

    👍👍 Can you make another version of this video with React please?

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

    Excellent video, very well explained. But man, that keyboard sound! What is it?

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

      It’s a keychron keyboard with brown switches

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

      ​@@RawCoding I am guessing it is the Q1? It sounds awesome! It gives such a nice vibe to your videos. Still, it is your excellent explanations and tutorials that brought me here, thank you so much for all the efforts you put into making these videos.

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

    Спасибо большое за видео, как раз то, на чем я делаю проект) Ты крут)

  • @АртемДенисенко-к9я

    it's great, but i has next problem whats don't know how fix. On deploy angular has other adress with .net deplot proj, i can send request on backend but his not return cookie auth, but i know 100% whats backend put me that in frontend? baecause if i use httpclient on localhost without write baseurl he s return me a cookie every try

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

    LET'S GOO, NG + IDENTITY!

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

    Thanks for that video - it was really helpful.
    I am just wondering - if I am using a JWT auth - is there a possibility to connect it through SignInManager ?

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

      yes, at SignIn....() method it's possible to pass auth properties where you can specificy the authnetication schema or authentication method. which will trigger the appropriate handler

  • @sergeylebedev1052
    @sergeylebedev1052 10 місяців тому

    Спасибо большое!

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

    How do I in this approach modify cookie expiration time, rename cookie, enable SlidingExpiration ? I believe when adding cookie through "AddIdentity" method we cannot do this, am i right ?

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

      great question! you'd use ConfigureApplicationCookie after registering AddIdentity
      learn.microsoft.com/en-us/aspnet/core/security/authentication/identity-configuration?view=aspnetcore-7.0#cookie-settings

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

      @@RawCoding Thanks :)

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

    I feel this fresh look api in dotnet kinda like laravel

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

    Hell yeah!!! I'm surprised that you're not Angular kind of guy, considering dotnet background. But you swim rather smoothly in it... Either that, or editing this video was a bitch.

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

      it was alright, I like vanilla js over TS and Angular is TOO much boilerplate, dependency injection & observer http client like why?

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

      @@RawCoding Hehe. Those are the main reasons I like it. Angular has by far the best, most simple and elegant solution for state management. Thus, it scales ridiculously well compared to other libs/frameworks. Everything is done via RxJs (basically pub/sub). That is why HttpClient works with observables, so you can easily hook those results up to everything else.
      But yeah, for proof of concept stuff, it can be pain in the...

  • @kaseabernathy3642
    @kaseabernathy3642 9 місяців тому

    does anyone know why I get a 405 on all my POSTS but not GETS? I'm assuming it's a CORS issue, but I'm not sure. Any help would be appreciated.

    • @kaseabernathy3642
      @kaseabernathy3642 9 місяців тому

      never mind, had to sleep on it to let me figure out i'm a moron

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

    Nice explanation. Can you please do a video about user impersonation using JWT/Identity. Thanks

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

      will take a look!

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

      @@RawCoding Thank you

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

      You can implement this yourself, or rather, ask chatgpt.
      1- Create an endpoint with parameter username or userId, that checks if you are admin, if so, create a token(guid) on the user with said username or userid from parameters, add it to a database table that has columns: string guid,string username or userid, bool used.
      2- return url with token(guid) attached to it this url is an endpoint that makes you login with that token, on that returned endpoint, get the username or userid with the guid you get, login the user, set token to used = 1, do whatever authentication you do on your server to the user, since you already know that this token was generated by admin. If this token is used again, check If used = 1, If so, return 403, else, continue..

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

      @@adamfarmer7665 100% don't ask chatgpt to implement something you don't understand. And your explanation is suffering from the curse of knowledge.

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

    Doesn't dotnet Identity saves a cookie as encrypted And if cookie get encrypted then do we need a separate api to get user info and save it may be on local storage.

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

      that's exactly what we do in this video

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

    Now we need nuxt version with gated serverside content

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

    Is there a source code?

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

      only for patreon supporters.

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

      @@RawCoding the irony of having tutorials for open source framework behind paywall, while also encouraging audience to contribute in the comments with their knowledge. imagine going to stackoverflow and there are just patreon links. gl in ur endeavours i guess...

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

      If this was stackoverflow I’d tell you to get fucked for leaving stupid comments, but this is my comment section so I’ll answer politely and explain the situation because I care about us growing. There needs to be a value exchange for the work I put in - if you watch the video you get value of the idea for free and you can copy the code for free, you pay for convenience and more than that to support the work I do. Also I’m not directly affiliated with Microsoft or Google so there is no irony.

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

    This is what 10x looks like

  • @shadmansudipto7287
    @shadmansudipto7287 Рік тому +3

    I thought you were about to commit a sin. Good thing you don't do angular.

  • @Kosa39
    @Kosa39 Рік тому +4

    12:07 I suggest viewers to use httpClient better :D
    Namely:
    Services are places where communication with api's happens but also they are responsible for holding the state
    so sample AuthService could look like this:
    @Injectable({ providedIn: 'root' } // By doing so we don't need to specify this service in the providers array, it will become singleton, and we can inject it everywhere in the app
    export class AuthService {
    user: User | null // this can be either User class directly or Subject/ReplaySubject , by making this a subject we can later in the app wire things up reactively
    login(login: string, password: string): Observable {
    return this._http.post(url, { body }).pipe(
    tap((user) => this.user = user)); // rxjs tap operator is for producing side effects, so it is perfect to assign our user property of the service
    )
    logout(): Observable {
    return this._http.post(...).pipe(
    tap(() => this.user = null)
    )
    }
    }
    }
    Then in the component you can use it like this: this._authService.login("anton", "iLikeCookies").subscribe((user) => { ..Whatever you want to do with that user })
    If you need to access user data later on, you can do this by reffering to the user property of AuthService. I was writing this without IDE so there could be mistakes

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

      I disagree with you, cause we want to use the AWAIT operator :D

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

      So I would put it this way:
      Imagine that u need a list of users:
      so in service would be:
      async getAll() {
      const url = `${this.apiBaseURL}/user/list`;
      const result = await firstValueFrom(
      this.http.get(url)
      );
      return result as User[];
      }
      and in component:
      try {
      this.userList = await this.userService.getAll();
      } catch (error: any) {
      this.feedbackSevice.error(error.message);
      } finally {
      this.loadingService.setOff();
      }