Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
c75c973350 | |||
3c3edacd7c |
@ -1,6 +1,6 @@
|
|||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.4.2"
|
version = "0.4.4"
|
||||||
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"
|
||||||
|
@ -10,6 +10,7 @@ proc newApiError*(parent: ref Exception = nil, respCode: HttpCode, respMsg: stri
|
|||||||
result = newException(ApiError, msg, parent)
|
result = newException(ApiError, msg, parent)
|
||||||
result.respCode = respCode
|
result.respCode = respCode
|
||||||
result.respMsg = respMsg
|
result.respMsg = respMsg
|
||||||
|
result.trace &= parent.trace
|
||||||
|
|
||||||
|
|
||||||
proc raiseApiError*(respCode: HttpCode, respMsg: string, msg = "") =
|
proc raiseApiError*(respCode: HttpCode, respMsg: string, msg = "") =
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user