[][src]Crate oauth2_noserver

Handles the oauth2 flow for installed apps that don't have a server side

fn main() -> Result<(), Box<std::error::Error>> {
    let config = loadConfig()?;

    let auth_url = "https://accounts.google.com/o/oauth2/v2/auth";
    let token_url = "https://www.googleapis.com/oauth2/v3/token";

    // Set up the config for the Google OAuth2 process.
    let oauthConfig = Oauth2Config::new(
        config.googleapi_app_credentials.client_id,
        config.googleapi_app_credentials.client_secret,
        auth_url,
        token_url,
    )
    .add_scope("https://www.googleapis.com/auth/calendar")
    .add_scope("https://www.googleapis.com/auth/plus.me");

    const PORT: u16 = 14565;
    let authenticator = oauth2_noserver::Authenticator::new(oauthConfig)
        .set_port(PORT)
        .set_redirect_url(format!("http://localhost:{}/oauth/callback", PORT));
    authenticator.authenticate().unwrap();

    Ok(())
}

Structs

Authenticator

A struct to hold oauth authentication

Config

Stores the configuration for an OAuth2 client.