Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Oauth2 login with spotify #731

Open
wants to merge 8 commits into
base: development
Choose a base branch
from

Conversation

stevenleadbeater
Copy link

@stevenleadbeater stevenleadbeater commented Oct 27, 2024

fixes #729, fixes #728 and fixes #726

works for me locally, I preserved the original login method, added a new one for login with spotify and fixed an issue that stopped tracks playing. I'm not massively familiar with this code (I pulled it yesterday because I wanted it to work on my pinephone) I'm happy to do a bit more to get this mergeable if needed but please bear in mind I may need a bit of guidance on what files to look at to solve issues

…ifyId::from_base62` is setting this to unkown which causes playback to fail with ` Unable to load audio item: Error { kind: Unavailable, error: NonPlayable } / unable to load track <SpotifyId("spotify:unknown:1iI5J72TQxYdQkKnkRwWCn")>`
@stevenleadbeater
Copy link
Author

That flatpak builder failure looks like clippy complaining about pre-existing code. Is this a new thing?

@stevenleadbeater
Copy link
Author

tested it on my pinephone too and I have tunes :)

davidosdr

This comment was marked as duplicate.

Copy link

@schooldanlp6 schooldanlp6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it should work with librespot 0.6.0 too which is also what I run on my OS currently

but thanks for the fix it works now :))))

@stevenleadbeater
Copy link
Author

but it should work with librespot 0.6.0 too which is also what I run on my OS currently

but thanks for the fix it works now :))))

You must have commented 0.6.0 within days of it's release :') I'll give it a go and see how it works. I was actually looking at the login5 stuff on librespot too as it may fix the other authentication issue....

@alumni
Copy link

alumni commented Nov 10, 2024

I also tested it locally and it seems it's working quite well. I would remove the old login button.

@xou816 Could you review?

@xou816
Copy link
Owner

xou816 commented Nov 10, 2024

Looks like a lot of great work, I'll try to review that tomorrow, thanks!

@xou816
Copy link
Owner

xou816 commented Nov 12, 2024

Looks good overall! I would have a few things to nitpick but nothing major/no reason to delay this. Just hesitant about the client id change, is it needed?

Copy link
Owner

@xou816 xou816 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nothing blocking, just want to discuss the client id real quick)

@@ -278,7 +311,8 @@ impl SpotifyPlayer {
}
}

const CLIENT_ID: &str = "782ae96ea60f4cdf986a766049607005";
const REDIRECT_URI: &str = "http://127.0.0.1:8898/login";
const SPOTIFY_CLIENT_ID: &str = "65b708073fc0480ea92a077233ca87bd";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the client id need to change? i guess we should eventually make this configurable

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated my client to allow the expected redirect uris, if you want to revert that!


Button login_with_spotify_button {
/* Translators: Log in button label */
label: _("Log in with Spotify");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the wording could probably be improved to make it clear its an external login, but I dont have any great suggestion just yet; probably need to review the whole ui of this dialog!

.url();

println!("Browse to: {}", auth_url);
if let Err(err) = open::that(auth_url.to_string()) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super clear on the benefits, but I'd be interested in doing that with portals/ASPHD at some later time!

}?;
trace!("Exchange {code:?} for access token");

// Do this sync in another thread because I am too stupid to make the async version work.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's absolutely fine that can be adressed later 😄

};
let refresh_token = match token.refresh_token() {
Some(t) => t.secret().to_string(),
_ => "".to_string(), // Spotify always provides a refresh token.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this trigger an error then?


let token_scopes: Vec<String> = match token.scopes() {
Some(s) => s.iter().map(|s| s.to_string()).collect(),
_ => scopes.into_iter().map(|s| s.to_string()).collect(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess its technically nullable but not really in practice, maybe it should be an error as well?

.map(|s| Scope::new(s.into()))
.collect();
let (auth_url, _) = client
.authorize_url(CsrfToken::new_random)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this token be validated somewhere down the line?

@@ -57,6 +57,12 @@ glib::wrapper! {
pub struct ReleaseDetailsWindow(ObjectSubclass<imp::ReleaseDetailsWindow>) @extends gtk::Widget, libadwaita::Window, libadwaita::PreferencesWindow;
}

impl Default for ReleaseDetailsWindow {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for taking care of clippy 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Any chances of a dependency bump? Cannot Log Back In Incorrect login credentials
9 participants