Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is JwtSecurityTokenHandler thread safe

I'm using JwtSecurityTokenHandler to issue tokens in a aspnet core web api app:

JwtSecurityToken token = BuildJwtSecurityToken(...);
public string toks = new JwtSecurityTokenHandler().WriteToken(token);

each time a token is requested and created, a new JwtSecurityTokenHandler is instantiated, can I use a global instance of it and use it for every token generation?

private JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler();
private GenToken(JwtSecurityToken token) => handler.WriteToken(token);

Is there any problems to use like this?

like image 252
fluter Avatar asked Nov 18 '17 04:11

fluter


1 Answers

Docs say instance members for JwtSecurityTokenHandler are not guaranteed to be thread safe.

https://msdn.microsoft.com/en-us/library/system.identitymodel.tokens.jwtsecuritytokenhandler(v=vs.114).aspx

like image 115
NYCdotNet Avatar answered Nov 14 '22 22:11

NYCdotNet