mirror of
https://github.com/ramsayleung/rspotify.git
synced 2026-04-26 07:55:55 +03:00
[GH-ISSUE #389] Scopes!() Disclaimer in documentation #124
Labels
No labels
Stale
bug
discussion
enhancement
good first issue
good first issue
help wanted
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/rspotify#124
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Inheritor-Vision on GitHub (Feb 18, 2023).
Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/389
Hi!
First of all, I am new to Rust, so sorry in advance for any imprecision or mistake. I also do not know if this is a bug or simply disclaimer to add to the documentation.
Summary
scopes!()accept the old way of making scopes (i.e with spaces likescopes!("user-read-recently-played playlist-modify-public playlist-modify-private")) without errors. The mistake will only appears whenprompt_for_token()will keep asking for authorization, even if the token is cached.prompt_for_tokenis probably used once in the code, when creating the Spotify client for the first time. And at this time, it is hard to debug and find thatscopes!()is the issue, because everything seems OK on that side.Long story
It seems like one of the breaking change between 0.10 and 0.11 was to make the creation of scopes behave differently.
0.10:
0.11:
However, doing the following in 0.11 do not produce any visible error:
Worse than that, it produces the exact same valid URL from
get_authorize_url. So, when used withprompt_for_token, everything works fine for the current session.If the token is stored:
The difference will then appears when the token will be retreived from the cache. Scopes from cache and scopes from the code will be then built differently:
Then
self.get_oauth().scopes.is_subset()insideread_token_cacheinsideprompt_for_tokenwill silently return false and act like the token do not have the same scope, hence re-asking for authorization.Potential fixes
I would see 3 different potential fixes:
join_scopes!()reject any inputs with a space or, silently split it.self.get_oauth().scopes.is_subset()inread_token_cachescopes!()in the documentation, for newbies like me still taking inspirationg from code prior 0.11Again, I'm Rust newbie, I hope it helps!
@ramsayleung commented on GitHub (Feb 22, 2023):
Hi @Inheritor-Vision, thanks for your contribution, since the
scopes!macro doesn't reject any inputs with space, then it will cause some subtle bugs here.In my opinion, I prefer the combination of first solution and third solution, because the second fix doesn't actually fix this problem, it generates some message to help developer to address this subtle problem. As for the third fix, some developers might miss the documentation.
I think the best way to solve a problem is to prevent it from happening in the first place.
PS:
I create a PR to fix this problem :)