Regenerate JWT bearer token on each API requestJWT (JSON Web Token) automatic prolongation of expirationHow to apply custom validation to JWT token on each request for ASP.NET WebApi?Set up JWT Bearer Token Authorization/Authentication in HangfireJWT(lcobucci/jwt) - refresh tokenWhat's the difference between JWTs and Bearer Token?How to pass JSON web token (JWT) to a get requestSigning jwt token with refresh token as payloadPass jwt refresh token on header or bodyJWT token on response gives www-authenticate →Bearer on response headerWhy does JWT need to be sent as a Bearer Token header?

How do changes to your speed that occur on your own turn affect your available movement?

The 50,000 row query limit is not actually a "per APEX call" as widely believed

Found more old paper shares from broken up companies

Why is DC so, so, so Democratic?

Sci-fi short story: plants attracting spaceship and using them as a agents of pollination between two planets

Sometimes you are this word with three vowels

Bug in Lualatex: not printing characters from calculation

What exactly makes a General Products hull nearly indestructible?

Why is chess failing to attract big name sponsors?

what to say when a company asks you why someone (a friend) who was fired left?

Is it possible to be an intellectual/do research without the internet?

Why does the salt in the oceans not sink to the bottom?

Travelling from Venice to Budapest, making a stop in Croatia

High income and difficulty during interviews

Span command across LaTeX environments

dos2unix is unable to convert typescript file to unix format

What Is the Meaning of "you has the wind of me"?

What was the rationale behind 36 bit computer architectures?

If a check is written for bill, but account number is not mentioned on memo line, is it still processed?

Can a character with a low Intelligence score take the Ritual Caster feat and choose the Wizard class?

Is there a way to factor age into the mass-luminosity relationship for stars?

What the purpose of the fuel shutoff valve?

Can I pay with HKD in Macau or Shenzhen?

Sextortion with actual password not found in leaks



Regenerate JWT bearer token on each API request


JWT (JSON Web Token) automatic prolongation of expirationHow to apply custom validation to JWT token on each request for ASP.NET WebApi?Set up JWT Bearer Token Authorization/Authentication in HangfireJWT(lcobucci/jwt) - refresh tokenWhat's the difference between JWTs and Bearer Token?How to pass JSON web token (JWT) to a get requestSigning jwt token with refresh token as payloadPass jwt refresh token on header or bodyJWT token on response gives www-authenticate →Bearer on response headerWhy does JWT need to be sent as a Bearer Token header?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I want to regenerate my bearer token on each request being made to the server.



I do not want to use refresh token for this purpose.



Can someone please advise how I can regenerate a new token with new expiration stamp from the earlier token generated which is being passed through the authorization header?










share|improve this question






















  • For what purpose if I may ask?

    – Peter Bons
    Mar 26 at 15:35

















1















I want to regenerate my bearer token on each request being made to the server.



I do not want to use refresh token for this purpose.



Can someone please advise how I can regenerate a new token with new expiration stamp from the earlier token generated which is being passed through the authorization header?










share|improve this question






















  • For what purpose if I may ask?

    – Peter Bons
    Mar 26 at 15:35













1












1








1








I want to regenerate my bearer token on each request being made to the server.



I do not want to use refresh token for this purpose.



Can someone please advise how I can regenerate a new token with new expiration stamp from the earlier token generated which is being passed through the authorization header?










share|improve this question














I want to regenerate my bearer token on each request being made to the server.



I do not want to use refresh token for this purpose.



Can someone please advise how I can regenerate a new token with new expiration stamp from the earlier token generated which is being passed through the authorization header?







asp.net-web-api jwt






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 15:18









Paresh VardeParesh Varde

3906 silver badges25 bronze badges




3906 silver badges25 bronze badges












  • For what purpose if I may ask?

    – Peter Bons
    Mar 26 at 15:35

















  • For what purpose if I may ask?

    – Peter Bons
    Mar 26 at 15:35
















For what purpose if I may ask?

– Peter Bons
Mar 26 at 15:35





For what purpose if I may ask?

– Peter Bons
Mar 26 at 15:35












2 Answers
2






active

oldest

votes


















0














Call the token endpoint of the Authorization Server each time before you make an API request.






share|improve this answer























  • I don't want to make addtional request. I am trying to generate token on each call the to web server and new token will be send in response mesasage. I am looking for sliding expiration token

    – Paresh Varde
    Mar 27 at 9:57











  • ok, the words you use suggested OAuth 2.0 hence my answer; seems you're looking to do something else than a standard

    – Hans Z.
    Mar 27 at 14:53











  • I did something identical to what you suggest but instead of calling endpoint each time I made generic response in each API call which will have new token with extended validity

    – Paresh Varde
    Mar 29 at 8:09


















0














I created a MessageHandler filter inheriting from DelegatingHandler class and overwrote SendAsync method.



I can have access to my original bearer token received from the request here which I can decode and generate a new one. After generating a new one I dump it to the response so that this will execute on every request and we don't need to manage individual API



 string audienceId = Properties.Settings.Default.AudienceId;
var issuer = Properties.Settings.Default.AngularHostURL;
string symmetricKeyAsBase64 = Properties.Settings.Default.AudienceSecret;

DateTime IssuedUtc = DateTime.UtcNow;
DateTime ExpiresUtc =
IssuedUtc.AddMinutes(Properties.Settings.Default.TokenLifetimeInMinutes);
var keyByteArray = TextEncodings.Base64Url.Decode(symmetricKeyAsBase64);
var signingKey = new HmacSigningCredentials(keyByteArray);

var identity = new ClaimsIdentity("JWT");

foreach (var claim in claims)
identity.AddClaim(claim);

var tokennew = new JwtSecurityToken(issuer, audienceId, identity.Claims,
IssuedUtc, ExpiresUtc, signingKey);
var handler = new JwtSecurityTokenHandler();
var jwt = handler.WriteToken(tokennew);

return jwt;





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55360646%2fregenerate-jwt-bearer-token-on-each-api-request%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Call the token endpoint of the Authorization Server each time before you make an API request.






    share|improve this answer























    • I don't want to make addtional request. I am trying to generate token on each call the to web server and new token will be send in response mesasage. I am looking for sliding expiration token

      – Paresh Varde
      Mar 27 at 9:57











    • ok, the words you use suggested OAuth 2.0 hence my answer; seems you're looking to do something else than a standard

      – Hans Z.
      Mar 27 at 14:53











    • I did something identical to what you suggest but instead of calling endpoint each time I made generic response in each API call which will have new token with extended validity

      – Paresh Varde
      Mar 29 at 8:09















    0














    Call the token endpoint of the Authorization Server each time before you make an API request.






    share|improve this answer























    • I don't want to make addtional request. I am trying to generate token on each call the to web server and new token will be send in response mesasage. I am looking for sliding expiration token

      – Paresh Varde
      Mar 27 at 9:57











    • ok, the words you use suggested OAuth 2.0 hence my answer; seems you're looking to do something else than a standard

      – Hans Z.
      Mar 27 at 14:53











    • I did something identical to what you suggest but instead of calling endpoint each time I made generic response in each API call which will have new token with extended validity

      – Paresh Varde
      Mar 29 at 8:09













    0












    0








    0







    Call the token endpoint of the Authorization Server each time before you make an API request.






    share|improve this answer













    Call the token endpoint of the Authorization Server each time before you make an API request.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 26 at 17:02









    Hans Z.Hans Z.

    31.1k7 gold badges59 silver badges87 bronze badges




    31.1k7 gold badges59 silver badges87 bronze badges












    • I don't want to make addtional request. I am trying to generate token on each call the to web server and new token will be send in response mesasage. I am looking for sliding expiration token

      – Paresh Varde
      Mar 27 at 9:57











    • ok, the words you use suggested OAuth 2.0 hence my answer; seems you're looking to do something else than a standard

      – Hans Z.
      Mar 27 at 14:53











    • I did something identical to what you suggest but instead of calling endpoint each time I made generic response in each API call which will have new token with extended validity

      – Paresh Varde
      Mar 29 at 8:09

















    • I don't want to make addtional request. I am trying to generate token on each call the to web server and new token will be send in response mesasage. I am looking for sliding expiration token

      – Paresh Varde
      Mar 27 at 9:57











    • ok, the words you use suggested OAuth 2.0 hence my answer; seems you're looking to do something else than a standard

      – Hans Z.
      Mar 27 at 14:53











    • I did something identical to what you suggest but instead of calling endpoint each time I made generic response in each API call which will have new token with extended validity

      – Paresh Varde
      Mar 29 at 8:09
















    I don't want to make addtional request. I am trying to generate token on each call the to web server and new token will be send in response mesasage. I am looking for sliding expiration token

    – Paresh Varde
    Mar 27 at 9:57





    I don't want to make addtional request. I am trying to generate token on each call the to web server and new token will be send in response mesasage. I am looking for sliding expiration token

    – Paresh Varde
    Mar 27 at 9:57













    ok, the words you use suggested OAuth 2.0 hence my answer; seems you're looking to do something else than a standard

    – Hans Z.
    Mar 27 at 14:53





    ok, the words you use suggested OAuth 2.0 hence my answer; seems you're looking to do something else than a standard

    – Hans Z.
    Mar 27 at 14:53













    I did something identical to what you suggest but instead of calling endpoint each time I made generic response in each API call which will have new token with extended validity

    – Paresh Varde
    Mar 29 at 8:09





    I did something identical to what you suggest but instead of calling endpoint each time I made generic response in each API call which will have new token with extended validity

    – Paresh Varde
    Mar 29 at 8:09













    0














    I created a MessageHandler filter inheriting from DelegatingHandler class and overwrote SendAsync method.



    I can have access to my original bearer token received from the request here which I can decode and generate a new one. After generating a new one I dump it to the response so that this will execute on every request and we don't need to manage individual API



     string audienceId = Properties.Settings.Default.AudienceId;
    var issuer = Properties.Settings.Default.AngularHostURL;
    string symmetricKeyAsBase64 = Properties.Settings.Default.AudienceSecret;

    DateTime IssuedUtc = DateTime.UtcNow;
    DateTime ExpiresUtc =
    IssuedUtc.AddMinutes(Properties.Settings.Default.TokenLifetimeInMinutes);
    var keyByteArray = TextEncodings.Base64Url.Decode(symmetricKeyAsBase64);
    var signingKey = new HmacSigningCredentials(keyByteArray);

    var identity = new ClaimsIdentity("JWT");

    foreach (var claim in claims)
    identity.AddClaim(claim);

    var tokennew = new JwtSecurityToken(issuer, audienceId, identity.Claims,
    IssuedUtc, ExpiresUtc, signingKey);
    var handler = new JwtSecurityTokenHandler();
    var jwt = handler.WriteToken(tokennew);

    return jwt;





    share|improve this answer



























      0














      I created a MessageHandler filter inheriting from DelegatingHandler class and overwrote SendAsync method.



      I can have access to my original bearer token received from the request here which I can decode and generate a new one. After generating a new one I dump it to the response so that this will execute on every request and we don't need to manage individual API



       string audienceId = Properties.Settings.Default.AudienceId;
      var issuer = Properties.Settings.Default.AngularHostURL;
      string symmetricKeyAsBase64 = Properties.Settings.Default.AudienceSecret;

      DateTime IssuedUtc = DateTime.UtcNow;
      DateTime ExpiresUtc =
      IssuedUtc.AddMinutes(Properties.Settings.Default.TokenLifetimeInMinutes);
      var keyByteArray = TextEncodings.Base64Url.Decode(symmetricKeyAsBase64);
      var signingKey = new HmacSigningCredentials(keyByteArray);

      var identity = new ClaimsIdentity("JWT");

      foreach (var claim in claims)
      identity.AddClaim(claim);

      var tokennew = new JwtSecurityToken(issuer, audienceId, identity.Claims,
      IssuedUtc, ExpiresUtc, signingKey);
      var handler = new JwtSecurityTokenHandler();
      var jwt = handler.WriteToken(tokennew);

      return jwt;





      share|improve this answer

























        0












        0








        0







        I created a MessageHandler filter inheriting from DelegatingHandler class and overwrote SendAsync method.



        I can have access to my original bearer token received from the request here which I can decode and generate a new one. After generating a new one I dump it to the response so that this will execute on every request and we don't need to manage individual API



         string audienceId = Properties.Settings.Default.AudienceId;
        var issuer = Properties.Settings.Default.AngularHostURL;
        string symmetricKeyAsBase64 = Properties.Settings.Default.AudienceSecret;

        DateTime IssuedUtc = DateTime.UtcNow;
        DateTime ExpiresUtc =
        IssuedUtc.AddMinutes(Properties.Settings.Default.TokenLifetimeInMinutes);
        var keyByteArray = TextEncodings.Base64Url.Decode(symmetricKeyAsBase64);
        var signingKey = new HmacSigningCredentials(keyByteArray);

        var identity = new ClaimsIdentity("JWT");

        foreach (var claim in claims)
        identity.AddClaim(claim);

        var tokennew = new JwtSecurityToken(issuer, audienceId, identity.Claims,
        IssuedUtc, ExpiresUtc, signingKey);
        var handler = new JwtSecurityTokenHandler();
        var jwt = handler.WriteToken(tokennew);

        return jwt;





        share|improve this answer













        I created a MessageHandler filter inheriting from DelegatingHandler class and overwrote SendAsync method.



        I can have access to my original bearer token received from the request here which I can decode and generate a new one. After generating a new one I dump it to the response so that this will execute on every request and we don't need to manage individual API



         string audienceId = Properties.Settings.Default.AudienceId;
        var issuer = Properties.Settings.Default.AngularHostURL;
        string symmetricKeyAsBase64 = Properties.Settings.Default.AudienceSecret;

        DateTime IssuedUtc = DateTime.UtcNow;
        DateTime ExpiresUtc =
        IssuedUtc.AddMinutes(Properties.Settings.Default.TokenLifetimeInMinutes);
        var keyByteArray = TextEncodings.Base64Url.Decode(symmetricKeyAsBase64);
        var signingKey = new HmacSigningCredentials(keyByteArray);

        var identity = new ClaimsIdentity("JWT");

        foreach (var claim in claims)
        identity.AddClaim(claim);

        var tokennew = new JwtSecurityToken(issuer, audienceId, identity.Claims,
        IssuedUtc, ExpiresUtc, signingKey);
        var handler = new JwtSecurityTokenHandler();
        var jwt = handler.WriteToken(tokennew);

        return jwt;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 14:56









        Paresh VardeParesh Varde

        3906 silver badges25 bronze badges




        3906 silver badges25 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55360646%2fregenerate-jwt-bearer-token-on-each-api-request%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현