Skip to content

Commit

Permalink
refactor: improve client id handling
Browse files Browse the repository at this point in the history
  • Loading branch information
w-lfchen committed Oct 16, 2024
1 parent 1544f57 commit 685291d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions spotify_player/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::config;

// copied from https://github.com/hrkfdn/ncspot/pull/1244/commits/81f13e2f9458a378d70d864716c2d915ad8cdaa4
// TODO: adjust, this is just for debugging
pub const SPOTIFY_CLIENT_ID: &str = "65b708073fc0480ea92a077233ca87bd";
pub const CLIENT_REDIRECT_URI: &str = "http://127.0.0.1:8989/login";
static OAUTH_SCOPES: &[&str] = &[
"playlist-modify",
Expand Down Expand Up @@ -76,7 +75,10 @@ impl AuthConfig {

fn get_credentials() -> Result<Credentials, OAuthError> {
get_access_token(
SPOTIFY_CLIENT_ID,
&config::get_config()
.app_config
.get_client_id()
.unwrap_or_else(|_| String::from("65b708073fc0480ea92a077233ca87bd")),
CLIENT_REDIRECT_URI,
OAUTH_SCOPES.to_vec(),
)
Expand Down
2 changes: 1 addition & 1 deletion spotify_player/src/cli/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn try_connect_to_client(socket: &UdpSocket, configs: &config::Configs) -> Resul
// create a Spotify API client
// TODO: the client id has been set for debugging
// let client_id = configs.app_config.get_client_id()?;
let client_id = crate::auth::SPOTIFY_CLIENT_ID.to_string();
let client_id = configs.app_config.get_client_id()?;
let client = client::Client::new(session, auth_config, client_id);
rt.block_on(client.refresh_token())?;

Expand Down
2 changes: 1 addition & 1 deletion spotify_player/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ impl AppConfig {
SessionConfig {
proxy,
ap_port: self.ap_port,
client_id: crate::auth::SPOTIFY_CLIENT_ID.to_string(),
client_id: self.client_id.clone(),
..Default::default()
}
}
Expand Down

0 comments on commit 685291d

Please sign in to comment.