Prepare for 1.0 release
This commit is contained in:
parent
4163dc0441
commit
4ce022fca2
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "jsonwebtoken"
|
||||
version = "0.2.0"
|
||||
version = "1.0.0"
|
||||
authors = ["Vincent Prouillet <vincent@wearewizards.io>"]
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
|
@ -11,7 +11,7 @@ keywords = ["jwt", "web", "api", "token", "json"]
|
|||
|
||||
[dependencies]
|
||||
rustc-serialize = "0.3"
|
||||
clippy = {version = "0.0.22", optional = true}
|
||||
clippy = {version = "0.0.32", optional = true}
|
||||
rust-crypto = "0.2.34"
|
||||
|
||||
[features]
|
||||
|
|
18
README.md
18
README.md
|
@ -6,12 +6,12 @@
|
|||
Add the following to Cargo.toml:
|
||||
|
||||
```toml
|
||||
jsonwebtoken = "0.2"
|
||||
jsonwebtoken = "1.0"
|
||||
rustc-serialize = "0.3"
|
||||
```
|
||||
|
||||
## How to use
|
||||
There is a complete example in examples/claims.rs but here's a quick one.
|
||||
There is a complete example in `examples/claims.rs` but here's a quick one.
|
||||
|
||||
In terms of imports:
|
||||
```rust
|
||||
|
@ -21,13 +21,16 @@ extern crate rustc_serialize;
|
|||
use jwt::{encode, decode, Header, Algorithm};
|
||||
```
|
||||
|
||||
Look at the examples directory for 2 examples: a basic one and one with a custom
|
||||
header.
|
||||
|
||||
### Encoding
|
||||
```rust
|
||||
let token = encode(Header::default(), &my_claims, "secret".as_ref()).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`.
|
||||
The default algorithm is HS256. Look at custom headers section to see how to change that.
|
||||
In that example, `my_claims` is an instance of a Claims struct that derives `RustcEncodable` and `RustcDecodable`.
|
||||
The default algorithm is HS256.
|
||||
Look at custom headers section to see how to change that.
|
||||
|
||||
### Decoding
|
||||
```rust
|
||||
|
@ -41,8 +44,8 @@ In addition to the normal base64/json decoding errors, `decode` can return two c
|
|||
- **WrongAlgorithmHeader**: if the alg in the header doesn't match the one given to decode
|
||||
|
||||
### Validation
|
||||
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.
|
||||
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: there is an example of that in `examples/claims.rs`.
|
||||
|
||||
### 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.
|
||||
|
@ -54,6 +57,7 @@ header.kid = Some("blabla".to_owned());
|
|||
header.alg = Algorithm::HS512;
|
||||
let token = encode(header, &my_claims, "secret".as_ref()).unwrap();
|
||||
```
|
||||
Look at `examples/custom_header.rs` for a full working example.
|
||||
|
||||
## Algorithms
|
||||
Right now, only SHA family is supported: SHA256, SHA384 and SHA512.
|
||||
|
|
Loading…
Reference in New Issue