Это видео недоступно.
Сожалеем об этом.

JWT Refresh Token in ASP.Net Core (a deep dive)

Поделиться
HTML-код
  • Опубликовано: 14 авг 2024
  • The volume of the video is a little low, I apologize in advance. Please increase the volume of the device you are listening in. I will fix the issue before the next video recording.
    Today in the video I am going to go through what is JWT Refresh Token and how to create them in detail.
    JWT Refresh token is used for getting a new JWT token after the first token is expired. Instead of sending the user id and password every time when we renew a JWT token, we can use the refresh token for that purpose.

Комментарии • 77

  • @ksdvishnukumar
    @ksdvishnukumar 4 года назад +2

    It really helped me a lot to understand the JWT concepts and to implement the same... Hats off to you to make such a valuable video for better understanding...

    • @DotNetCoreCentral
      @DotNetCoreCentral  4 года назад

      VISHNU KUMAR thanks! I’m glad the video helped you.

  • @DevKumar-nh6vk
    @DevKumar-nh6vk Год назад +1

    For Refresh API, "do we need to pass anything in Header". For me evetime refresh API giving 401. Not able to get what is Wrong. As in Body already passing RefreshCred(jwt token & refreshToken).

  • @dfytq
    @dfytq Год назад

    Excellent tutorial boss. Please make a discussion on how to optimize dbcontext and configure connection pooling for entityframework core.

  • @birendrasahu5777
    @birendrasahu5777 3 года назад

    Awesome . Cleared my doubts. Thank you bro 🙏

  • @eliassal1
    @eliassal1 3 года назад

    Again, 2 fantastic , helpful and well explained videos (in spite of the fact that I got lost a little bit between the different objects :-) as this is very new to me ). Just to validate my understanding, so once we call the refresh api, to reauthenticate, 1 hour later, we should use the RefreshToken for reauthentificiation, am I correct or it is the original Jwtoken that will be extended by another hour?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 года назад

      @Salam Elias, you are correct, you need to provide the refresh token for refreshing and getting a new token.

  • @alihaydar3021
    @alihaydar3021 2 года назад

    Great job 👍 again)) but I think the expired of refresh token needs to be more than 1 hour this exactly the duty of refresh token but you copy paste the same time if jwt token

    • @DotNetCoreCentral
      @DotNetCoreCentral  2 года назад

      @Ali Haydar, thanks for watching! Yes, I copied and pasted without changing just for the interest of time, but yes refresh tokens are usually much longer-lived compared to a normal token.

  • @koushikdas5122
    @koushikdas5122 2 года назад

    System.InvalidOperationException: 'Action 'Auth.Demo.Controllers.NameController.Authenticate (Auth.Demo)' has more than one parameter that was specified or inferred as bound from request body. Only one parameter per action may be bound from body. Inspect the following

    • @koushikdas5122
      @koushikdas5122 2 года назад

      Pls sir look into this

    • @DotNetCoreCentral
      @DotNetCoreCentral  2 года назад

      ​@@koushikdas5122 can you share your code here, the part where you are getting error

  • @boredo7502
    @boredo7502 4 года назад +3

    Do you have Git repo for this? it was a nice video thanks!

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 года назад +3

      Yes I have. github.com/choudhurynirjhar/auth-demo

    • @shreeprasadlohar9564
      @shreeprasadlohar9564 2 года назад

      @@DotNetCoreCentral This is supposed tobe added in description. Anyways thanks..🙂🙂

  • @rahuljadhav6022
    @rahuljadhav6022 3 года назад

    Thank you Brother....!

  • @manasmalik9133
    @manasmalik9133 2 года назад

    After the expiry of the access token, a new access token is not generated even with the Refresh Token. public AuthResponse Refresh(RefreshCredential refreshCredential)
    {
    SecurityToken validatedToken;
    var tokenHandler = new JwtSecurityTokenHandler();
    var principal = tokenHandler.ValidateToken(refreshCredential.AccessToken, new TokenValidationParameters
    {
    ValidateIssuerSigningKey = true,
    IssuerSigningKey = new SymmetricSecurityKey(key),
    ValidateIssuer = false,
    ValidateAudience = false
    }, out validatedToken);

  • @anshulasati4778
    @anshulasati4778 2 года назад

    Hi, why does this code not refresh the expired JWT token.?

  • @carecovered1434
    @carecovered1434 3 года назад

    In a realistic world, Will user be sending us both JWTToken and Refresh token and on API we need to first check if JWTToken is valid(not expired too) if expired then to use RefreshToken to validate?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 года назад +1

      @Care Covered, in the real world scenario, ideally the caller should be sending refresh token only when the auth token is expired. And the caller finds it out based on the Auth error response from the service. That is the workflow that is what I have seen normally used.

  • @Stuntman5701
    @Stuntman5701 3 года назад

    im just kinda confused.
    why does a jwt token expire that quickly when i could regenerate a new one with the refreshkey anyways?
    if someone steals my cookies im fucked anyways

  • @Marv3Lthe1
    @Marv3Lthe1 3 года назад

    Why should I use refresh token instead of increasing the timeout of my original JWT token ?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 года назад

      @Marv3Lthe1, the reason you don't want to use a longer timeout is that if your token is stolen you will remain vulnerable for a longer time, hence using a refresh token.

  • @nirajdahal5019
    @nirajdahal5019 3 года назад

    Hello sir!! How do we add external login providers like facebook, google, linkedin etc in .net core web api.. for example: How do i add extra login providera like google facebook in this project that you have taught us?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 года назад

      Niraj Dahal so if I understand your requirement properly, you want to use Facebook or google etc as oauth provider. It should be similar way using a middleware. I can give it a try in a future video. Thanks

  • @anushreedesai7505
    @anushreedesai7505 3 года назад

    Can you tell how can we generate JWT token using azure active directory (using client, tenant id etc) ?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 года назад +1

      @Anushree Desai, generating JWT token is similar, but I have dot done it using azure active directory service before, so I cannot tell for sure what goes into it. Once I try it out I can let you know.

  • @MuhammadKamran-xj6jw
    @MuhammadKamran-xj6jw 2 года назад

    Is this sliding token concept?

  • @ayan-qn9or
    @ayan-qn9or 4 года назад

    If you please post a tutorial video on integration testing using key token, when token is generated in different api would be very helpful. Thanks.

    • @DotNetCoreCentral
      @DotNetCoreCentral  4 года назад +1

      @ayanghosh thanks for watching! Sure I will give it a try.

    • @ayan-qn9or
      @ayan-qn9or 4 года назад

      @@DotNetCoreCentral Thanks.

  • @ashokkumarnaralasetti4860
    @ashokkumarnaralasetti4860 2 года назад

    I think without refresh key also we can regenerate token right

  • @shuhaib864
    @shuhaib864 4 года назад

    Very nice video. Thanks 🙏
    Can you please try to do a video about Open ID connect using identity server 4?

    • @DotNetCoreCentral
      @DotNetCoreCentral  4 года назад +1

      @Muhammed Shuhaib, I will put it in my queue, thanks!

  • @AzZaph
    @AzZaph 3 года назад

    after receiving the refresh token after jwt expires. Which one should be use in the Authorization?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 года назад +1

      @Flote Fuertes, thanks for watching. You should use a refresh token to get the new token only. For authentication, you should use the new token received with the help of a refresh token.

    • @AzZaph
      @AzZaph 3 года назад

      @@DotNetCoreCentral Thank you very informative content

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 года назад

      @@AzZaph you are welcome!

  • @arslansaleem8629
    @arslansaleem8629 4 года назад

    please shear the link of other videos you have mention at the start of this video

    • @DotNetCoreCentral
      @DotNetCoreCentral  4 года назад

      @Arslan Saleem, all the videos are available on my channel.

  • @PankajNikam
    @PankajNikam 4 года назад

    Please share the repo in description.

    • @DotNetCoreCentral
      @DotNetCoreCentral  4 года назад

      It's in here: dotnetcorecentral.com/blog/authentication-handler-in-asp-net-core/
      Thanks for watching the video.

  • @mrjamiebowman
    @mrjamiebowman 3 года назад

    Is there a GitHub for this code? Would be helpful.

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 года назад +3

      @Jamie Bowman, yes. github.com/choudhurynirjhar/auth-demo

  • @sukurullasheikh3301
    @sukurullasheikh3301 3 года назад

    hello sir do you have git repo please send the project git repo link we need to undestand

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 года назад

      @sukurulla sheikh, here is the repo: github.com/choudhurynirjhar/auth-demo

  • @unknown3164
    @unknown3164 4 года назад +1

    link to the repository github.com/choudhurynirjhar/auth-demo

  • @techbuzz3869
    @techbuzz3869 4 года назад

    Plz explain .net core project structure and easy to code tips

    • @DotNetCoreCentral
      @DotNetCoreCentral  4 года назад +1

      tech buzz I’m not sure I understand completely what are you looking for. Can you please elaborate?

    • @techbuzz3869
      @techbuzz3869 4 года назад

      @@DotNetCoreCentral .net core basic project folder, which files will use for what

    • @DotNetCoreCentral
      @DotNetCoreCentral  4 года назад

      @@techbuzz3869 Ok, I will make a video in the future for that. Thanks for the feedback

  • @vattikiti
    @vattikiti 3 года назад

    Can you please give us the link of the source code

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 года назад

      @V VV, thanks for watching! The source code is available in my GitHub report here: github.com/choudhurynirjhar/auth-demo

  • @umasankar9971
    @umasankar9971 2 года назад

    Could you please share the source code for this

  • @Vennix13
    @Vennix13 3 года назад

    Hey, really good video, but do you have any source code ? like on github pls ?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 года назад

      @Vennicks, thanks for watching! Here is the repo link: github.com/choudhurynirjhar/auth-demo

    • @Vennix13
      @Vennix13 3 года назад

      @@DotNetCoreCentral thanks a lot !

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 года назад

      @@Vennix13 you are welcome!

  • @shivaprasadmanchala3955
    @shivaprasadmanchala3955 3 года назад

    I need to destroy jwt token when user logout...can u please let me sir

  • @PAJANI1910
    @PAJANI1910 3 года назад

    i followed your tutorial, but the token expiry is not working.. i created the token for 2 minutes, but my token is working more than 2 minutes. Then i go through some other videos. x.TokenValidationParameters = new TokenValidationParameters
    {
    ValidateIssuerSigningKey = true,
    IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secreteKey)),
    ValidateLifetime = true,
    ValidateIssuer = false,
    ValidateAudience=false,
    ClockSkew= TimeSpan.Zero

    };, in that they used ClockSkew property for token expiry. after i put ClockSkew , my token is not working more than two minutes.