Skip to content

Instantly share code, notes, and snippets.

@CoderBK
Created January 13, 2022 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CoderBK/e9fa4c68df19b87080b3486826309438 to your computer and use it in GitHub Desktop.
Save CoderBK/e9fa4c68df19b87080b3486826309438 to your computer and use it in GitHub Desktop.
public class JWTTokenProvider:IValueProvider {
private HttpRequest _httprequest;
private readonly IJWTHandlerService _jWTHandlerService;
public JWTTokenProvider(HttpRequest httpRequest, IJWTHandlerService jWTHandlerService) {
_httprequest = httpRequest;
_jWTHandlerService = jWTHandlerService;
}
public async Task<object> GetValueAsync() {
var request = await _httprequest.ReadAsStringAsync() as object;
string token = _httprequest.Headers["Authorization"];
JWTClaim claim = null;
if (string.IsNullOrWhiteSpace(token)) { return claim; }
try
{
claim = _jWTHandlerService.ParseClaims(token);
}
catch (Exception e)
{
return claim;
}
return claim;
}
public string ToInvokeString() => string.Empty;
public Type Type => typeof(object);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment