2 Commits
0.4.2 ... 0.4.4

3 changed files with 11 additions and 3 deletions

View File

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

View File

@ -10,6 +10,7 @@ proc newApiError*(parent: ref Exception = nil, respCode: HttpCode, respMsg: stri
result = newException(ApiError, msg, parent)
result.respCode = respCode
result.respMsg = respMsg
result.trace &= parent.trace
proc raiseApiError*(respCode: HttpCode, respMsg: string, msg = "") =

View File

@ -143,8 +143,15 @@ proc validateJWT*(ctx: ApiAuthContext, jwt: JWT) =
if jwt.claims.sub.isNone: failAuth "Missing 'sub' claim."
if jwt.claims.exp.isNone: failAuth "Missing or invalid 'exp' claim."
if not ctx.validAudiences.contains(jwt.claims.aud.get):
failAuth "JWT is not for us (invalid audience)."
if jwt.claims["aud"].get.kind == JString:
# 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