Module asap::generator [−][src]
This module contains all things relating to the generation of ASAP tokens. Use this module if you need to generate ASAP tokens or authorisation headers for outgoing requests.
// The identifier of the service that issues the token (`iss`). let iss = "service01".to_string(); // The key id (`kid`) of the public key in your keyserver. let kid = "service01/my-key-id".to_string(); // The `private_key` used to sign each token. let private_key = include_bytes!("../support/keys/service01/1530402390-private.der").to_vec(); let mut generator = Generator::new(iss, kid, private_key); // You can then use the generator to create ASAP tokens: // The intended audience of your token: let aud = Aud::One("target-service".to_string()); // You can add custom extra claims too if you need: let extra_claims: Option<DefaultClaims> = None; // Authorization tokens: "eyJ0eXAiOiJKV..." generator.token::<DefaultClaims>(aud, extra_claims).unwrap(); // Or authorization headers: "Bearer eyJ0eXAiOiJKV..." // generator.auth_header(aud, extra_claims).unwrap();
You may also provide extra claims to your generated token, as long as your struct can be serialised and deserialised:
#[derive(Serialize, Deserialize)] struct ExtraClaims { foo: String, bar: i64, baz: Vec<String> } let extra_claims = Some(ExtraClaims { foo: "foo".to_string(), bar: 1234, baz: vec!["baz".to_string()] }); generator.token(aud, extra_claims).unwrap();
Structs
Generator |
An ASAP generator. |