Dev cookie-minter example for OIDC-less smoke runs
Browse files at this commita4f71ba46757bc85dbd4e13cd2bff5bef8e168d0Parent: 4118043- test
- dev cookie-minter example for OIDC-less smoke runs
2 changed files +39 -0
crates/in-client/Cargo.tomlmodified+4 -0
| @@ -47,3 +47,7 @@ http = "1.5" | ||
| 47 | 47 | # Tests generate their own RSA keys, and rsa 0.9's RNG is the rand_core 0.6 |
| 48 | 48 | # line. |
| 49 | 49 | rand_core06 = { package = "rand_core", version = "0.6.4", features = ["getrandom"] } |
| 50 | + | |
| 51 | +[[example]] | |
| 52 | +name = "mint" | |
| 53 | +required-features = ["test-seam"] |
crates/in-client/examples/mint.rsadded+35 -0
| @@ -0,0 +1,35 @@ | ||
| 1 | +//! Development helper: mints a session-cookie value for smoke runs against a | |
| 2 | +//! fake im, without a browser dance. Requires the `test-seam` feature. | |
| 3 | +//! | |
| 4 | +//! ```text | |
| 5 | +//! cargo run -p in-client --example mint --features test-seam -- \ | |
| 6 | +//! <path-to-in.key> <app-session-token> [cookie-name] | |
| 7 | +//! ``` | |
| 8 | +//! | |
| 9 | +//! Print the value, then hand it to the browser as the session cookie. Any | |
| 10 | +//! token string works as long as the fake provider's introspection answers | |
| 11 | +//! `active: true` for it. | |
| 12 | + | |
| 13 | +fn main() { | |
| 14 | + let mut args = std::env::args().skip(1); | |
| 15 | + let key_path = args.next().unwrap_or_else(|| { | |
| 16 | + eprintln!("usage: mint <in.key path> <app-session-token> [cookie-name]"); | |
| 17 | + std::process::exit(2); | |
| 18 | + }); | |
| 19 | + let token = args.next().expect("token"); | |
| 20 | + let cookie_name = args.next().unwrap_or_else(|| "in_session".to_string()); | |
| 21 | + let key: [u8; 32] = std::fs::read(&key_path) | |
| 22 | + .unwrap_or_else(|e| panic!("{key_path}: {e}")) | |
| 23 | + .try_into() | |
| 24 | + .expect("key file is not 32 bytes"); | |
| 25 | + let config = in_client::Config { | |
| 26 | + issuer: String::new(), | |
| 27 | + client_id: String::new(), | |
| 28 | + client_secret: String::new(), | |
| 29 | + redirect_uri: String::new(), | |
| 30 | + cookie_name, | |
| 31 | + cookie_key: key, | |
| 32 | + }; | |
| 33 | + let exp = time::OffsetDateTime::now_utc() + time::Duration::days(1); | |
| 34 | + println!("{}", in_client::mint_session_cookie(&config, &token, exp)); | |
| 35 | +} |