jwt 0.1.0
A Simple D implementation of JSON Web Tokens
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
JWT
A Simple D implementation of JSON Web Tokens.
Supported Algorithms
- none
- HS256
- HS384
- HS512
How To Use
Encoding
import jwt.jwt;
import jwt.exceptions;
import jwt.algorithms;
import std.json;
import std.datetime;
void main() {
Token token = new Token(JWTAlgorithm.HS512);
token.claims.exp = Clock.currTime.toUnixTime();
token.claims.set("id", 60119);
string encodedToken = token.encode("supersecret");
// work with the encoded token
}
Verifying
import jwt.jwt;
import jwt.exceptions;
import jwt.algorithms;
void main() {
// get encoded token from header or ...
try {
Token token = verify(encodedToken, "supersecret", JWTAlgorithm.HS512);
writeln(token.claims.getInt("id"));
} catch (InvalidSignature e) {
writeln("This token has been tampered with");
} catch (ExpiredException e) {
writeln("Token has expired");
}
}
Limitations
- ##### Since Phobos doesn't support RSA algorithms this library only provides HMAC signing.
- ##### Currently this library only supports primitive data types(bool, string, int, float, double, null) in claims(working to remedy the situation)
Note
- Registered by Zelalem Mekonen
- 0.1.0 released 8 years ago
- zolamk/jwt
- MIT
- Copyright © 2016, Zelalem Mekonen
- Authors:
- Dependencies:
- none
- Versions:
-
0.4.0 2016-Sep-18 0.3.0 2016-Sep-17 0.2.0 2016-Sep-16 0.1.0 2016-Sep-15 ~master 2017-Feb-10 - Download Stats:
-
-
0 downloads today
-
12 downloads this week
-
68 downloads this month
-
11921 downloads total
-
- Score:
- 1.9
- Short URL:
- jwt.dub.pm