From fe8041c00d6fef42e8dd9319e6c681f36100a675 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Mon, 23 Jun 2025 15:26:42 -0400 Subject: [PATCH] Perform Spotify authorization --- src/main.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index a646424..943b7e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,34 @@ +use rspotify::{ + prelude::*, + scopes, AuthCodeSpotify, Credentials, OAuth, +}; + #[tokio::main] async fn main() -> Result<(), Box> { dotenvy::dotenv()?; - println!("Hello, world!"); + let client_id = std::env::var("SPOTIFY_CLIENT_ID") + .expect("SPOTIFY_CLIENT_ID must be set in .env file or as an environment variable"); + + let client_secret = std::env::var("SPOTIFY_CLIENT_SECRET") + .expect("SPOTIFY_CLIENT_SECRET must be set in .env file or as an environment variable"); + + let redirect_uri = std::env::var("SPOTIFY_REDIRECT_URI") + .unwrap_or("http://127.0.0.1:8888/callback".to_string()); + + let credentials = Credentials::new(&client_id, &client_secret); + + let oauth = OAuth { + redirect_uri, + scopes: scopes!(), + ..Default::default() + }; + + let spotify = AuthCodeSpotify::new(credentials, oauth); + + println!("Performing authorization..."); + let url = spotify.get_authorize_url(false)?; + spotify.prompt_for_token(&url).await?; Ok(()) }