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;
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
add a comment |
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
For what purpose if I may ask?
– Peter Bons
Mar 26 at 15:35
add a comment |
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
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
asp.net-web-api jwt
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
Call the token endpoint of the Authorization Server each time before you make an API request.
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
add a comment |
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;
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Call the token endpoint of the Authorization Server each time before you make an API request.
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
add a comment |
Call the token endpoint of the Authorization Server each time before you make an API request.
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
add a comment |
Call the token endpoint of the Authorization Server each time before you make an API request.
Call the token endpoint of the Authorization Server each time before you make an API request.
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
add a comment |
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
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
answered Mar 27 at 14:56
Paresh VardeParesh Varde
3906 silver badges25 bronze badges
3906 silver badges25 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
For what purpose if I may ask?
– Peter Bons
Mar 26 at 15:35