-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
178 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use color_eyre::{ | ||
eyre::{self, Context as _}, | ||
Section as _, | ||
}; | ||
use librespot_core::SessionConfig; | ||
use librespot_core::{authentication::Credentials, Session}; | ||
use log::info; | ||
use tokio::runtime::Runtime; | ||
|
||
use crate::{config::CliConfig, setup_logger, LogTarget}; | ||
|
||
pub(crate) fn run_oauth(mut cli_config: CliConfig, oauth_port: u16) -> eyre::Result<()> { | ||
setup_logger(LogTarget::Terminal, cli_config.verbose)?; | ||
|
||
cli_config | ||
.load_config_file_values() | ||
.wrap_err("failed to read config file")?; | ||
|
||
let cache = cli_config | ||
.shared_config | ||
.get_cache(true) | ||
.with_note(|| "The result of the authentication needs to be cached to be usable later.")?; | ||
|
||
const OAUTH_SCOPES: &[&str] = &[ | ||
"app-remote-control", | ||
"playlist-modify", | ||
"playlist-modify-private", | ||
"playlist-modify-public", | ||
"playlist-read", | ||
"playlist-read-collaborative", | ||
"playlist-read-private", | ||
"streaming", | ||
"ugc-image-upload", | ||
"user-follow-modify", | ||
"user-follow-read", | ||
"user-library-modify", | ||
"user-library-read", | ||
"user-modify", | ||
"user-modify-playback-state", | ||
"user-modify-private", | ||
"user-personalized", | ||
"user-read-birthdate", | ||
"user-read-currently-playing", | ||
"user-read-email", | ||
"user-read-play-history", | ||
"user-read-playback-position", | ||
"user-read-playback-state", | ||
"user-read-private", | ||
"user-read-recently-played", | ||
"user-top-read", | ||
]; | ||
|
||
let session_config = SessionConfig { | ||
proxy: cli_config.shared_config.proxy_url(), | ||
..Default::default() | ||
}; | ||
|
||
let token = librespot_oauth::get_access_token( | ||
&session_config.client_id, | ||
&format!("http://127.0.0.1:{oauth_port}/login"), | ||
OAUTH_SCOPES.to_vec(), | ||
) | ||
.wrap_err("token retrieval failed")?; | ||
|
||
let creds = Credentials::with_access_token(token.access_token); | ||
|
||
Runtime::new().unwrap().block_on(async move { | ||
let session = Session::new(session_config, Some(cache)); | ||
session.connect(creds, true).await | ||
})?; | ||
|
||
info!("\nLogin successful! You are now ready to run spotifyd."); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters