spotify-oauth

Crates.iospotify-oauth
lib.rsspotify-oauth
version0.3.0
sourcesrc
created_at2019-03-15 20:20:27.25918
updated_at2019-12-28 17:28:22.057686
descriptionAn implementation of the Spotify Authorization Code Flow in Rust
homepagehttps://github.com/FrictionlessPortals/spotify-oauth
repositoryhttps://github.com/FrictionlessPortals/spotify-oauth
max_upload_size
id121114
size89,629
(FrictionlessPortals)

documentation

https://docs.rs/spotify-oauth/

README

spotify-oauth

Docs

Description

spotify-oauth is a library for Spotify Authorization. It features a full implementation of the Authorization Code Flow that Spotify requires a user to undergo before using the web API.

Basic Example

This example shows how the library can be used to create a full authorization flow for retrieving the token required to use the web API.

use std::{io::stdin, str::FromStr, error::Error};
use spotify_oauth::{SpotifyAuth, SpotifyCallback, SpotifyScope};

#[async_std::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {

    // Setup Spotify Auth URL
    let auth = SpotifyAuth::new_from_env("code".into(), vec![SpotifyScope::Streaming], false);
    let auth_url = auth.authorize_url()?;

    // Open the auth URL in the default browser of the user.
    open::that(auth_url)?;

    println!("Input callback URL:");
    let mut buffer = String::new();
    stdin().read_line(&mut buffer)?;

    // Convert the given callback URL into a token.
    let token = SpotifyCallback::from_str(buffer.trim())?
        .convert_into_token(auth.client_id, auth.client_secret, auth.redirect_uri).await?;

    println!("Token: {:#?}", token);

    Ok(())
}

API Documentation

More API information can be located here.

Contribution

If you have any suggestions or issues towards this library, please submit an issue. Pull requests, code reviewing and feedback are welcome.

License

MIT

Commit count: 19

cargo fmt