Update docs a bit
This commit is contained in:
parent
275c95281f
commit
e7d856efb3
20
README.md
20
README.md
|
@ -18,19 +18,20 @@ In terms of imports:
|
|||
extern crate jsonwebtoken as jwt;
|
||||
extern crate rustc_serialize;
|
||||
|
||||
use jwt::{encode, decode, Algorithm};
|
||||
use jwt::{encode, decode, Header, Algorithm};
|
||||
```
|
||||
|
||||
### Encoding
|
||||
```rust
|
||||
let token = encode(&my_claims, "secret", Algorithm::HS256);
|
||||
let token = encode(&my_claims, "secret".as_ref(), Header::default()).unwrap();
|
||||
```
|
||||
In that example, `my_claims` is an instance of the Claims struct.
|
||||
The struct you are using for your claims should derive `RustcEncodable` and `RustcDecodable`.
|
||||
|
||||
### Decoding
|
||||
```rust
|
||||
let claims = decode::<Claims>(&token, "secret", Algorithm::HS256);
|
||||
let token = decode::<Claims>(&token, "secret", Algorithm::HS256).unwrap();
|
||||
// token is a struct with 2 params: header and claims
|
||||
```
|
||||
In addition to the normal base64/json decoding errors, `decode` can return two custom errors:
|
||||
|
||||
|
@ -42,12 +43,19 @@ In addition to the normal base64/json decoding errors, `decode` can return two c
|
|||
Right now, the library only validates the algorithm type used but does not verify claims such as expiration.
|
||||
Feel free to add a `validate` method to your claims struct to handle that.
|
||||
|
||||
### Custom headers
|
||||
All the parameters from the RFC are supported but the default header only has `typ` and `alg` set: all the other fields are optional.
|
||||
If you want to set the `kid` parameter for example:
|
||||
|
||||
```rust
|
||||
let mut header = Header::default();
|
||||
header.kid = Some("blabla".to_owned());
|
||||
let token = encode(&my_claims, "secret".as_ref(), header).unwrap();
|
||||
```
|
||||
|
||||
## Algorithms
|
||||
Right now, only SHA family is supported: SHA256, SHA384 and SHA512.
|
||||
|
||||
## Missing
|
||||
The header is currently not customisable and therefore does not support things like kid right now.
|
||||
|
||||
## Performance
|
||||
On my thinkpad 440s for a 2 claims struct using SHA256:
|
||||
|
||||
|
|
Loading…
Reference in New Issue