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

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

КОМЕНТАРІ • 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...

  • @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).

  • @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.

  • @user-rp9iis1en6h
    @user-rp9iis1en6h 2 роки тому

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

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

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

  • @boredo7502
    @boredo7502 4 роки тому +3

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

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

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

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

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

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

    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  3 роки тому

      @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.

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

    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  4 роки тому +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

  • @MuhammadKamran-xj6jw
    @MuhammadKamran-xj6jw 2 роки тому

    Is this sliding token concept?

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

    Awesome . Cleared my doubts. Thank you bro 🙏

  • @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.

  • @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!

  • @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);

  • @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.

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

    I think without refresh key also we can regenerate token right

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

    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  4 роки тому

      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

  • @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.

  • @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!

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

    Thank you Brother....!

  • @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.

  • @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

  • @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.

  • @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!

  • @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

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

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

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

      @sukurulla sheikh, here is the repo: 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

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

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

  • @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

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

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

  • @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.