Types
JwtBuilder = object claims*: JsonNode
- Incrementally built JWT claims set.
JwtChecker = object leewaySeconds*: int64 ## Clock-skew tolerance for exp/nbf (default 60). issuer*: string ## Required `iss` value (empty = not checked). audience*: seq[string] ## Acceptable `aud` values (empty = not checked). requireExp*: bool ## Reject tokens without `exp` (default false). requireIat*: bool ## Reject tokens without `iat` (default false). required*: seq[string] ## Additional claim names that must be present. now*: int64 ## Reference time as Unix seconds (0 = current time).
- Validation policy for inbound JWT claims.
Procs
proc aud(b: var JwtBuilder; v: string) {....raises: [], tags: [], forbids: [].}
proc checkClaims(c: JwtChecker; claims: JsonNode): JsonNode {. ...raises: [JoseError, KeyError], tags: [TimeEffect], forbids: [].}
- Validate claims against the policy, returning them unchanged. Raises JoseError on any violation.
proc claim(b: var JwtBuilder; name, value: string) {....raises: [], tags: [], forbids: [].}
proc claim(b: var JwtBuilder; name: string; value: bool) {....raises: [], tags: [], forbids: [].}
proc claim(b: var JwtBuilder; name: string; value: int64) {....raises: [], tags: [], forbids: [].}
proc claim(b: var JwtBuilder; name: string; value: JsonNode) {....raises: [], tags: [], forbids: [].}
- Set a claim to an arbitrary JSON value.
proc exp(b: var JwtBuilder; v: int64) {....raises: [], tags: [], forbids: [].}
proc iat(b: var JwtBuilder; v: int64) {....raises: [], tags: [], forbids: [].}
proc initJwtBuilder(): JwtBuilder {....raises: [], tags: [], forbids: [].}
proc initJwtChecker(leewaySeconds = 60'i64; issuer = ""; audience: seq[string] = @[]; requireExp = false; requireIat = false; required: seq[string] = @[]): JwtChecker {. ...raises: [], tags: [], forbids: [].}
proc iss(b: var JwtBuilder; v: string) {....raises: [], tags: [], forbids: [].}
proc jti(b: var JwtBuilder; v: string) {....raises: [], tags: [], forbids: [].}
proc jwtDecrypt(token: string; key: Jwk; c: JwtChecker; allowAlgs: openArray[JweAlg] = []; allowEncs: openArray[JweEnc] = []): JsonNode {....raises: [ JoseError, IOError, OSError, ValueError, KeyError, Exception, IOError, OSError, ValueError, JoseError], tags: [ReadIOEffect, WriteIOEffect, RootEffect, TimeEffect], forbids: [].}
- Decrypt and validate claims. Returns the claims.
proc jwtEncrypt(b: JwtBuilder; alg: JweAlg; enc: JweEnc; key: Jwk; protectedExtra: JsonNode = nil; apu: openArray[byte] = []; apv: openArray[byte] = []; p2c = 100000): string {. ...raises: [JoseError, OSError, ValueError, Exception], tags: [RootEffect], forbids: [].}
- Encrypt the built claims, returning a JWE compact serialization.
proc jwtSign(b: JwtBuilder; alg: JwsAlg; key: Jwk; protectedExtra: JsonNode = nil): string {. ...raises: [JoseError, ValueError, Exception, OSError], tags: [RootEffect], forbids: [].}
- Sign the built claims, returning a JWS compact serialization.
proc jwtVerify(token: string; key: Jwk; c: JwtChecker; allowAlgs: openArray[JwsAlg] = []): JsonNode {....raises: [ JoseError, IOError, OSError, ValueError, KeyError, Exception, IOError, OSError, ValueError, JoseError], tags: [ReadIOEffect, WriteIOEffect, RootEffect, TimeEffect], forbids: [].}
- Verify the signature and validate claims. Returns the claims.
proc nbf(b: var JwtBuilder; v: int64) {....raises: [], tags: [], forbids: [].}
proc sub(b: var JwtBuilder; v: string) {....raises: [], tags: [], forbids: [].}