haxe-jwt
A JSON Web Token library for native Haxe.
Features
- Signing (generating) tokens
- Limited to HS256 algorithm for now
- Verifying (& decoding) tokens
- Limited to HS256 algorithm for now
- Does not check any public claims (exp, iss, sub, etc) yet
Usage
The library exposes two main functionalities: signing tokens and verifying tokens.
Signing Tokens
import jwt.JWT;
// ...
var token:String = JWT.sign({ adm: true }, "my super secret secret");
Verifying Tokens
import jwt.JWT;
typedef TPayload = {
> jwt.JWTPayloadBase,
var adm:Bool;
}
// ...
var result:JWTResult<TPayload> = JWT.verify(token, "my super secret secret");
switch(result) {
case Valid(payload): {
trace(payload);
}
case Invalid: throw 'The token was invalid, you dummy!';
}
Extracting Headers and Claims
import jwt.JWT;
// ...
typedef HeaderStruct = {};
typedef PayloadStruct = {};
var header:HeaderStruct = JWT.extract(token, JWTPart.Header);
var payload:PayloadStruct = JWT.extract(token, JWTPart.Payload);
Change Log
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
1.1.0
Added
- A
replacer
parameter toJWT.sign
, allowing custom replacers for JSON encoding (throughhaxe.Json.encode
).
Fixed
- Actually fixed
haxelib.json
classpath
😅
1.0.1
Changed
- Attempted to fix
haxelib.json
classpath
so library can actually be used.
1.0.0
Added
- HMACSHA256 token generation & signing
- HMACSHA256 token verification & decoding