#oauth2 #gcp #google-api #api-access #generate

google-api-auth

Dead simple API for generating access_token to query GCP's API

3 unstable releases

new 0.2.1 Dec 6, 2024
0.2.0 Oct 8, 2024
0.1.0 Aug 24, 2024

#1185 in Web programming

Download history 140/week @ 2024-08-19 18/week @ 2024-08-26 16/week @ 2024-09-16 9/week @ 2024-09-23 10/week @ 2024-09-30 151/week @ 2024-10-07 8/week @ 2024-10-14 3/week @ 2024-11-04 1/week @ 2024-11-18 114/week @ 2024-12-02

115 downloads per month

Apache-2.0

16KB
126 lines

google-api-auth

Dead simple API for generating access_token to query GCP's API

Production Readiness

This is already used in production in affiliated company for specific use-case. Use this in production at your own risk.

Examples

cargo.toml

[dependencies]
serde = { version = "1.0", features = ["derive"] }
google-api-auth = "0.2.0"

main.rs

fn main() {
    let mut dir = env::current_exe().unwrap();
    dir.pop();
    dir.push("some-name-000000-000000000.json");

    let json_string = json!({
        "type": "service_account",
        "project_id": "some-name-000000",
        "private_key_id": "somerandomuuid000000000",
        "private_key": "-----BEGIN PRIVATE KEY-----\n SOME CERT DATA \n-----END PRIVATE KEY-----\n",
        "client_email": "some-name@some-account-000000.iam.gserviceaccount.com",
        "client_id": "000000000000000",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/some-account.iam.gserviceaccount.com",
        "universe_domain": "googleapis.com"
    }).to_string();

    //Create the handler.
    let handler = AuthenticationHandler::new(dir.into());

    //Handler using json `String`
    let handler_2 = AuthenticationHandler::new(json_string.into());

    //Get a token with scoped read / write access to GCP DNS API.
    let token = handler.get_access_token_model(
    vec!["https://www.googleapis.com/auth/ndev.clouddns.readwrite".into()]);

    println!("Access Token: {}", token.access_token);
}

Affiliation with Google

This project isn't affiliated or maintained by Google, it's created by independent developer.

Dependencies

~4–16MB
~224K SLoC