.NET 7 Web API 🔒 Role-Based Authorization with JSON Web Tokens (JWT) & the dotnet user-jwts CLI

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2024

ความคิดเห็น • 43

  • @PatrickGod
    @PatrickGod  ปีที่แล้ว +2

    🚀 Join the .NET Web Academy with a 30% discount - closing soon!
    👉 www.dotnetwebacademy.com/courses/academy?coupon=dnwas23yt

  • @joaogabrielv.m328
    @joaogabrielv.m328 ปีที่แล้ว +7

    Great video, Patrick! Any chances to have a video teaching the basics of Identity Framework with MVC?

  • @UserUser5-c4c
    @UserUser5-c4c ปีที่แล้ว +5

    Your videos are 5-stars :)
    Just a hint about issue with invalid SignInKey while using user-jwts generated token (20:36 in video), in the application instead of decoding key into UTF8 it is required to docode it as base64 and it will work.

    • @jzn007x
      @jzn007x ปีที่แล้ว

      Could you give us the example?

    • @UserUser5-c4c
      @UserUser5-c4c ปีที่แล้ว +4

      @@jzn007x here is raw example:
      in Patrick's example in program.cs file, under AddAuthentication modify part where he is declaring IssuerSignInKey with =>
      new SymmetricSecurityKey(Convert.FromBase64String("HereYouShouldPasteSigningKeyGeneratedByUseJwts"))

  • @akbaralimajeed
    @akbaralimajeed ปีที่แล้ว +6

    Hi, if anyone gets the error while create jwt token as "dotnet : No project found at `-p|--project` path or current directory.", make sure you run above command inside the project folder not on the root folder (solution level), it requires to be in the same project file folder; hope this helps ):

  • @ynkdqe
    @ynkdqe ปีที่แล้ว +2

    Your tutorials are very helpful and easy to understand

    • @PatrickGod
      @PatrickGod  ปีที่แล้ว

      Glad you think so! Thanks so much!

  • @abdulhakimawad
    @abdulhakimawad ปีที่แล้ว +1

    Id do every thing like you, but the lock in the weather methode stills opened & return unauthorized error, why??

  • @SportProgramming
    @SportProgramming ปีที่แล้ว +2

    I cannot get it to accept the token, no matter what i do in jwt if i enable the secret code.

  • @ivandrofly
    @ivandrofly ปีที่แล้ว +1

    Nice... I didn't know u could gen keg with dotnet command

  • @elishamisoi
    @elishamisoi 8 หลายเดือนก่อน

    Thank you so much Patrick.

  • @Avster9
    @Avster9 ปีที่แล้ว +3

    Great video! Can you make a video with simple CQRS implementation?

  • @ndrcreates_per
    @ndrcreates_per ปีที่แล้ว

    I've done all of the auth completly in my app. my problem is i want to make my client app to send authorization into the server api, so i wont ,manually copy and past token bearer in swagger. how can i fix this? what is the name of this topic? i'm new in the field. thanks.

    • @ndrcreates_per
      @ndrcreates_per ปีที่แล้ว

      i have done
      httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", loginResponse.Token);
      but it wont work. please create a tutorial on this topic, its the final result of an auth and its a waste that it's not finalized.

  • @thegamer1599
    @thegamer1599 ปีที่แล้ว

    can someone tell me what patrick did at 11:04 coz im not using swagger from start, are there any other possible ways to do that?

  • @augustusdevree5434
    @augustusdevree5434 ปีที่แล้ว +1

    Is the signiture key was not found [@20:32] not the result of confronting the the token generated by the CLI with it's signing key "6ffvSugNwB6..." [@20:12] and your signing key specified in AppSettings:Token key "my top secret key" [@19:35]?

    • @Klayperson
      @Klayperson ปีที่แล้ว +1

      that's what i was thinking. for a second he did paste in the configuration path to the key from the CLI, but he didn't save it that way

    • @ArmedMob
      @ArmedMob ปีที่แล้ว

      @@Klayperson Threw me for a loop in my app as I did not see him not save that. I did find as long as both are the same it works.

  • @jesusnaun1981
    @jesusnaun1981 ปีที่แล้ว +1

    Someone help me please. when I execute dotnet user-jwts create in console, this show me that error: dotnet : No project found at `-p|--project` path or current directory.
    At line:1 char:1
    + dotnet user-jwts create
    + ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (No project foun...rent directory.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

    • @akbaralimajeed
      @akbaralimajeed ปีที่แล้ว

      Hi, make sure you run above command inside the project folder not on the root folder (solution level), it requires to be in the same project file folder; hope this helps ):

    • @SANGCAOHOAI
      @SANGCAOHOAI 11 หลายเดือนก่อน

      "cd" to the folder which have Container foler there

  • @ViktorTy
    @ViktorTy ปีที่แล้ว

    I just watched and implemented the .NET 6 Web API Authorization and now I see there is a new one haha what are the chances

  • @thomasdevelopment
    @thomasdevelopment ปีที่แล้ว +1

    Once a user is logged in how is the token being stored to maintain the user state?

    • @jamisonr
      @jamisonr ปีที่แล้ว

      The front end developer must handle it. One such way using Angular is to take the key from the login response and store it in the browser's application settings, then using an HttpInterceptor, all requests have the correct authentication header added with the stored jwt as the value. No doubt all popular web frameworks have similar mechanisms.

  • @tanishbansal5767
    @tanishbansal5767 ปีที่แล้ว

    I get an error while using the dotnet user-jwts create and the error I get is :
    dotnet : No project found at `-p|--project` path or current directory.
    At line:1 char:1
    + dotnet user-jwts create
    + ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (No project foun...rent directory.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
    Can you please tell me the solution for this ?

    • @PunisherSamo
      @PunisherSamo ปีที่แล้ว +1

      It might be that you are not with Package Manager Console in right folder ? Try to navigate into folder where you have another folders of youre API -> like bin, Controllers, Migrations, Models, Properties and so on. Navigate there through Package Manager Console (cd "path") and check content of folder by typing command dir to be sure that you are really there. It might be because you are also trying command on already running API. Another special cases of this error I found on stack overflow go ahead and check it as well.

    • @akbaralimajeed
      @akbaralimajeed ปีที่แล้ว +1

      Hi, make sure you run above command inside the project folder not on the root folder (solution level), it requires to be in the same project file folder; hope this helps ):

    • @SANGCAOHOAI
      @SANGCAOHOAI 11 หลายเดือนก่อน

      @@PunisherSamoIt's so wonderful for me, witt lots of thanks, hope you earn lots of money tomorow

  • @BlackGrinch-dl9qz
    @BlackGrinch-dl9qz ปีที่แล้ว +1

    Awesome buddy!

  • @rezach7536
    @rezach7536 ปีที่แล้ว

    Make more videos about authentication please. Thanks

  • @godizord
    @godizord ปีที่แล้ว

    Hey, great video, sadly my generated token still generates 401 error, any ideas?

    • @LovePeaceBeer
      @LovePeaceBeer ปีที่แล้ว

      How do you expect people to give you ideas without looking at your code? We can't use our Jedi powers unfortunately.

    • @sutinpoonking4104
      @sutinpoonking4104 ปีที่แล้ว +1

      try add audience , fix issue for me.
      Example:
      - in method CreateToken :
      var token = new JwtSecurityToken(
      issuer: _config["JWT:ValidAudience"],
      audience: _config["JWT:ValidAudience"],
      claims: claims,
      expires: DateTime.Now.AddDays(1),
      signingCredentials: creds
      );
      - in Program.cs:
      builder.Services.AddAuthentication().AddJwtBearer(options =>
      {
      options.TokenValidationParameters = new TokenValidationParameters
      {
      ValidateIssuerSigningKey = true,
      ValidateAudience = true,
      ValidateIssuer = true,
      ValidAudience = builder.Configuration["JWT:ValidIssuer"],
      ValidIssuer = builder.Configuration["JWT:ValidIssuer"],
      IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration.GetSection("Appsettings:Token").Value!)),
      };
      });

    • @nickgendron9187
      @nickgendron9187 ปีที่แล้ว

      @@sutinpoonking4104 fixed for me, thanks!

  • @dindjarin332
    @dindjarin332 ปีที่แล้ว

    Hi teacher can you cover OpenIddict library in detail?

  • @esdegan7176
    @esdegan7176 ปีที่แล้ว +2

    how about refresh token?

    • @christinemcdaniel9299
      @christinemcdaniel9299 ปีที่แล้ว +1

      Yes please

    • @leftjabrighthook
      @leftjabrighthook 7 หลายเดือนก่อน

      Amen. There are 2993753 tutorials on .net jwt. Not one about refresh that isn’t total jank.

  • @vishalsinghal6719
    @vishalsinghal6719 ปีที่แล้ว

    how to create token based on new login?

    • @vishalsinghal6719
      @vishalsinghal6719 ปีที่แล้ว

      trying to ask, how i can create token that u made using CLI

  • @alisayed7210
    @alisayed7210 ปีที่แล้ว

    stop sayin jesus !!!