#sso #aws #rust

awscloud_sso_cred_helper

A helper library for AWS SSO credential workflows

1 stable release

new 1.2.0 Feb 21, 2025
1.1.0 Feb 21, 2025
1.0.0 Feb 19, 2025

#436 in Authentication

45 downloads per month

MIT license

23KB
380 lines

awscloud_sso_cred_helper

Crates.io Docs.rs Build Status

A crate for managing AWS Single Sign-On (SSO) workflows.

This library provides utilities to interact with AWS SSO using asynchronous operations. It handles client registration, device authorization, token polling, and writing AWS credentials directly to your ~/.aws/credentials file.

Getting Started

Add the following to your Cargo.toml:

Getting started

Add the following dependency to your Cargo.toml:

[dependencies]
awscloud_sso_cred_helper = "1.0.0"

Usage

Interactive Mode

If you do not supply a start URL or region, the library will prompt you interactively.

use awscloud_sso_cred_helper::AwsSsoWorkflow;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // With no parameters provided, the workflow prompts interactively.
    let mut workflow = AwsSsoWorkflow::default();
    let credential = workflow.run_workflow().await?;

    println!("Account ID: {}", credential.account_id);
    println!("Role Name: {}", credential.role_name);
    println!("Access Key ID: {}", credential.access_key_id);
    println!("Secret Access Key: {}", credential.secret_access_key);
    println!("Session Token: {}", credential.session_token);
    Ok(())
}

Non-interactive Mode

If you do not supply a start URL or region, the library will prompt you interactively.

use awscloud_sso_cred_helper::AwsSsoWorkflow;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut workflow = AwsSsoWorkflow {
        start_url: "https://your.awsapps.com/start".to_string(),
        region: "eu-west-1".to_string(),
        ..Default::default()
    };

    let credential = workflow.run_workflow().await?;
    println!("Account ID: {}", credential.account_id);
    println!("Role Name: {}", credential.role_name);
    println!("Access Key ID: {}", credential.access_key_id);
    println!("Secret Access Key: {}", credential.secret_access_key);
    println!("Session Token: {}", credential.session_token);
    Ok(())
}

Final Thoughts

  • Library vs. Binary:
    Your library now handles the core AWS SSO workflow and allows optional parameters. You can write a separate binary that uses your library and handles CLI arguments (using clap or similar) as needed.

Dependencies

~23–33MB
~504K SLoC