1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-03 09:49:31 +02:00

Credentials with access token (oauth) (#1309)

* core: Create credentials from access token via OAuth2

* core: Credentials.username is optional: not required for token auth.

* core: store auth data within session. We might need this later if need to re-auth and original creds are no longer valid/available.

* bin: New --token arg for using Spotify access token. Specify 0 to manually enter the auth code (headless).

* bin: Added --enable-oauth / -j option. Using --password / -p option will error and exit.

* core: reconnect session if using token authentication

Token authenticated sessions cannot use keymaster. So reconnect using the reusable credentials we just obtained. Can perhaps remove this
workaround once keymaster is replaced with login5.

* examples: replace password login with token login
This commit is contained in:
Nick Steel 2024-09-13 06:35:55 +01:00 committed by GitHub
parent f6473319f6
commit 4f9151c642
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 629 additions and 88 deletions

View file

@ -22,13 +22,13 @@ async fn main() {
let audio_format = AudioFormat::default();
let args: Vec<_> = env::args().collect();
if args.len() != 4 {
eprintln!("Usage: {} USERNAME PASSWORD TRACK", args[0]);
if args.len() != 3 {
eprintln!("Usage: {} ACCESS_TOKEN TRACK", args[0]);
return;
}
let credentials = Credentials::with_password(&args[1], &args[2]);
let credentials = Credentials::with_access_token(&args[1]);
let mut track = SpotifyId::from_base62(&args[3]).unwrap();
let mut track = SpotifyId::from_base62(&args[2]).unwrap();
track.item_type = SpotifyItemType::Track;
let backend = audio_backend::find(None).unwrap();