summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2025-03-02 15:48:51 -0800
committerJesse Morgan <jesse@jesterpm.net>2025-03-02 15:48:51 -0800
commit5f37e7663dfc7e87cf8a88a85c68eb681fa5bd4f (patch)
treeed14fda421dc4918a775945b385e4ea8d381ecc8
parent9d4e3dc0c1b7a40da64b9c38015e8628ff624ed9 (diff)
Add command to print the bearer token.HEADmaster
-rw-r--r--README.md1
-rw-r--r--src/bin/sso/main.rs18
2 files changed, 15 insertions, 4 deletions
diff --git a/README.md b/README.md
index 069d3e7..f0cbe24 100644
--- a/README.md
+++ b/README.md
@@ -16,3 +16,4 @@ Options:
Commands:
login - default: get or renew an access token
curl - pass the access token to curl
+ token - print the current bearer token
diff --git a/src/bin/sso/main.rs b/src/bin/sso/main.rs
index 0356f3d..2e22198 100644
--- a/src/bin/sso/main.rs
+++ b/src/bin/sso/main.rs
@@ -60,9 +60,9 @@ enum Commands {
/// Request or refresh an access token (default command).
Login,
/// Send a curl request with an authorization header.
- Curl {
- args: Vec<String>,
- },
+ Curl { args: Vec<String> },
+ /// Print the current bearer token.
+ Token,
}
#[derive(Serialize, Deserialize, Clone)]
@@ -301,7 +301,7 @@ fn main() -> Result<(), Box<dyn Error>> {
if command == Commands::Login || !profile.valid_access_token() {
if profile.valid_refresh_token() {
// Try a refresh...
- // Ignore any errors
+ // Ignore any errors
if let Err(e) = profile.refresh() {
log::info!("Failed to refresh token: {}", e);
}
@@ -322,5 +322,15 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(()) /* No-op, we already took care of it above */
}
Commands::Curl { args } => do_curl(&profile, args),
+ Commands::Token => {
+ println!(
+ "{}",
+ profile
+ .access_token
+ .as_deref()
+ .expect("Must have valid access token")
+ );
+ Ok(())
+ }
}
}