Skip to content

Instantly share code, notes, and snippets.

@charlessolar
Last active March 14, 2018 17:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlessolar/4826cd1af0fabfac5b8f to your computer and use it in GitHub Desktop.
Save charlessolar/4826cd1af0fabfac5b8f to your computer and use it in GitHub Desktop.
Servicestack OAuth JWT Verification
this.GlobalRequestFilters.Add((httpReq, httpResp, requestDto) =>
{
var header = httpReq.Headers["Authorization"];
if( header.IsNullOrEmpty() ) {
httpResp.StatusCode = (int)HttpStatusCode.Unauthorized;
httpResp.EndRequest();
}
try
{
var token = header.Split(' ');
if( token[0].ToUpper() != "BEARER" ){
httpResp.StatusCode = (int)HttpStatusCode.Unauthorized;
httpResp.EndRequest();
}
var secret = appSettings.GetString("oauth.auth0.AppSecret").Replace('-', '+').Replace('_', '/');
JWT.JsonWebToken.Decode(token[1], Convert.FromBase64String(secret), verify: true);
}
catch (Exception)
{
httpResp.StatusCode = (int)HttpStatusCode.Unauthorized;
httpResp.EndRequest();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment