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

[Auth restructure 3] Split up Spotify into multiple clients #215

Merged
merged 32 commits into from
Jul 8, 2021

Conversation

marioortizmanero
Copy link
Collaborator

@marioortizmanero marioortizmanero commented Jun 19, 2021

Part 3 of splitting up #207, possibly the biggest of all changes. There's no way to reduce the number of changes here, really, as it requires moving most of the client's code into multiple files and different structures. But it doesn't really introduce that many changes. The endpoints themselves aren't changed at all and can be ignored, as they just were moved into traits.

The main library should be able to compile without problems after this PR.

@marioortizmanero marioortizmanero changed the base branch from master to auth-rewrite-part2 June 19, 2021 10:18
Copy link
Owner

@ramsayleung ramsayleung left a comment

Choose a reason for hiding this comment

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

Except for the small nitpick I commented, everything else looks good to me. Great job!

payload.insert(headers::SCOPE, &scope);
payload.insert(headers::STATE, &oauth.state);
// payload.insert(headers::CODE_CHALLENGE, todo!());
// payload.insert(headers::CODE_CHALLENGE_METHOD, "S256");
Copy link
Owner

Choose a reason for hiding this comment

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

According to the Spotify document, code_challenge_method and code_challenge are required when constructing the authorization URI. Why would you like to comment this code? It's still WIP?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've left the PKCE implementation for a future PR

@marioortizmanero
Copy link
Collaborator Author

One thing I'm still not sure about, though:

Maybe prompt_for_token should be implemented in the struct instead of in the trait? That way we could combine these two lines into one: https://github.com/ramsayleung/rspotify/blob/auth-rewrite-part4/examples/auth_code.rs#L44-L45.

@ramsayleung
Copy link
Owner

That way we could combine these two lines into one: https://github.com/ramsayleung/rspotify/blob/auth-rewrite-part4/examples/auth_code.rs#L44-L45.

The link is broken for the part-4 PR has been merged.

@marioortizmanero
Copy link
Collaborator Author

@marioortizmanero
Copy link
Collaborator Author

Also you should wait to review all the PRs before merging any because otherwise the diff is going to have more unnecessary stuff (like what just happened after merging the fourth PR). If you didn't know you can always revert the auth-rewrite-part4 and start from scratch.

@ramsayleung
Copy link
Owner

Also you should wait to review all the PRs before merging any because otherwise the diff is going to have more unnecessary stuff (like what just happened after merging the fourth PR).

Yep, it makes sense. You could to merge master into this PR since it includes some changes have been merged into master by auth-rewrite-part4

@marioortizmanero
Copy link
Collaborator Author

Sorry I don't quite understand your last comment

@ramsayleung
Copy link
Owner

Sorry for the ambiguity, I mean, you could merge master into this auth-rewrite-part3, since examples, tests, docs and CI have been fixed, then it doesn't need to be shown on the diff. Is it clear for you now?

@marioortizmanero
Copy link
Collaborator Author

You mean merge this into master? Well, it'd merge into auth-rewrite-part2 and we'd have the same problem in that case. Or have you reviewed it already?

@ramsayleung
Copy link
Owner

ramsayleung commented Jun 21, 2021

You mean merge this into master? Well, it'd merge into auth-rewrite-part2 and we'd have the same problem in that case.

Alright, I could just manually ignore the diff which has been merged into master in PR auth-rewrite-part4.

Or have you reviewed it already?

Not yet, I just took a rough review before, to check what has been modified. Then I will review this PR with caution, since it's a huge PR, it will take some time.

@marioortizmanero
Copy link
Collaborator Author

Alright, I could just manually ignore the diff which has been merged into master in PR auth-rewrite-part4

What I was saying before is that you can revert the auth-rewrite-part4 PR and apply it again after you're done:

image

But if you're ok with manually doing it then no problem.

src/clients/pagination/iter.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
/// `RSPOTIFY_CLIENT_ID` and `RSPOTIFY_CLIENT_SECRET`. You can optionally
/// activate the `env-file` feature in order to read these variables from
/// a `.env` file.
pub fn from_env() -> Option<Self> {
Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps we could return ClientResult for from_env() functions instead of Option<Self>?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The thing is that env::var returns just an Option, so there's nothing else to report with a Result in that function.

I also wanted to do this for Token::from_cache, but then I would have to re-think this in src/client_creds.rs:

    /// Tries to read the cache file's token, which may not exist.
    ///
    /// Similarly to [`Self::write_token_cache`], this will already check if the
    /// cached token is enabled and return `None` in case it isn't.
    #[maybe_async]
    pub async fn read_token_cache(&self) -> Option<Token> {
        if !self.get_config().token_cached {
            return None;
        }

        let token = Token::from_cache(&self.get_config().cache_path)?;
        if token.is_expired() {
            // Invalid token, since it doesn't have at least the currently
            // required scopes or it's expired.
            // TODO: update with error?
            None
        } else {
            Some(token)
        }
    }

In that case we now have to return an error when the scopes don't match instead of (Some/None), and I'm not sure which one to pick. Perhaps we should add a new variant?

Copy link
Owner

Choose a reason for hiding this comment

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

Well, I think Some/None is more reasonable, since we should return None when we could not find matched data, which is following the semantics of Option type.

src/lib.rs Show resolved Hide resolved
src/clients/base.rs Show resolved Hide resolved
src/clients/base.rs Show resolved Hide resolved
src/clients/base.rs Show resolved Hide resolved
src/clients/base.rs Show resolved Hide resolved
@marioortizmanero
Copy link
Collaborator Author

Also, remember to only accept (and not merge) this PR after you're done. Then you can review the second PR, do the same, and after you agree with all of them merge them. That way the diff can be easy to follow.

@ramsayleung ramsayleung self-requested a review June 29, 2021 02:18
@ramsayleung
Copy link
Owner

Yeah, everything looks good to me, approve :)

@marioortizmanero marioortizmanero mentioned this pull request Jul 2, 2021
@ramsayleung ramsayleung merged commit 1987bfd into auth-rewrite-part2 Jul 8, 2021
@ramsayleung ramsayleung deleted the auth-rewrite-part3 branch July 8, 2021 02:19
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.

2 participants