diff --git a/crates/in-client/Cargo.toml b/crates/in-client/Cargo.toml index 2205491..0658723 100644 --- a/crates/in-client/Cargo.toml +++ b/crates/in-client/Cargo.toml @@ -47,3 +47,7 @@ http = "1.5" # Tests generate their own RSA keys, and rsa 0.9's RNG is the rand_core 0.6 # line. rand_core06 = { package = "rand_core", version = "0.6.4", features = ["getrandom"] } + +[[example]] +name = "mint" +required-features = ["test-seam"] diff --git a/crates/in-client/examples/mint.rs b/crates/in-client/examples/mint.rs new file mode 100644 index 0000000..247bbb1 --- /dev/null +++ b/crates/in-client/examples/mint.rs @@ -0,0 +1,35 @@ +//! Development helper: mints a session-cookie value for smoke runs against a +//! fake im, without a browser dance. Requires the `test-seam` feature. +//! +//! ```text +//! cargo run -p in-client --example mint --features test-seam -- \ +//! [cookie-name] +//! ``` +//! +//! Print the value, then hand it to the browser as the session cookie. Any +//! token string works as long as the fake provider's introspection answers +//! `active: true` for it. + +fn main() { + let mut args = std::env::args().skip(1); + let key_path = args.next().unwrap_or_else(|| { + eprintln!("usage: mint [cookie-name]"); + std::process::exit(2); + }); + let token = args.next().expect("token"); + let cookie_name = args.next().unwrap_or_else(|| "in_session".to_string()); + let key: [u8; 32] = std::fs::read(&key_path) + .unwrap_or_else(|e| panic!("{key_path}: {e}")) + .try_into() + .expect("key file is not 32 bytes"); + let config = in_client::Config { + issuer: String::new(), + client_id: String::new(), + client_secret: String::new(), + redirect_uri: String::new(), + cookie_name, + cookie_key: key, + }; + let exp = time::OffsetDateTime::now_utc() + time::Duration::days(1); + println!("{}", in_client::mint_session_cookie(&config, &token, exp)); +}