3 Commits
0.4.2 ... 0.4.5

3 changed files with 13 additions and 3 deletions

View File

@ -1,6 +1,6 @@
# Package # Package
version = "0.4.2" version = "0.4.5"
author = "Jonathan Bernard" author = "Jonathan Bernard"
description = "Jonathan's opinionated extensions and auth layer for Jester." description = "Jonathan's opinionated extensions and auth layer for Jester."
license = "MIT" license = "MIT"

View File

@ -11,6 +11,9 @@ proc newApiError*(parent: ref Exception = nil, respCode: HttpCode, respMsg: stri
result.respCode = respCode result.respCode = respCode
result.respMsg = respMsg result.respMsg = respMsg
if not parent.isNil:
result.trace &= parent.trace
proc raiseApiError*(respCode: HttpCode, respMsg: string, msg = "") = proc raiseApiError*(respCode: HttpCode, respMsg: string, msg = "") =
var apiError = newApiError( var apiError = newApiError(

View File

@ -143,8 +143,15 @@ proc validateJWT*(ctx: ApiAuthContext, jwt: JWT) =
if jwt.claims.sub.isNone: failAuth "Missing 'sub' claim." if jwt.claims.sub.isNone: failAuth "Missing 'sub' claim."
if jwt.claims.exp.isNone: failAuth "Missing or invalid 'exp' claim." if jwt.claims.exp.isNone: failAuth "Missing or invalid 'exp' claim."
if not ctx.validAudiences.contains(jwt.claims.aud.get): if jwt.claims["aud"].get.kind == JString:
failAuth "JWT is not for us (invalid audience)." # If the token is for a single audience, check that it is for us.
if not ctx.validAudiences.contains(jwt.claims.aud.get):
failAuth "JWT is not for us (invalid audience)."
elif jwt.claims["aud"].get.kind == JArray:
# If the token is for multiple audiences, check that at least one is for us.
let auds = jwt.claims["aud"].get.getElems
if not auds.anyIt(ctx.validAudiences.contains(it.getStr)):
failAuth "JWT is not for us (invalid audience)."
let signingAlgorithm = jwt.header.alg.get let signingAlgorithm = jwt.header.alg.get