mirror of
https://github.com/ramsayleung/rspotify.git
synced 2026-04-26 07:55:55 +03:00
[PR #379] [CLOSED] Much simpler interface based on webapp example #422
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#422
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?
📋 Pull Request Information
Original PR: https://github.com/ramsayleung/rspotify/pull/379
Author: @marioortizmanero
Created: 12/29/2022
Status: ❌ Closed
Base:
master← Head:better-webapp📝 Commits (5)
23a08e7Much simpler webappe1acfbeRefactor auth process & token mutex4d850d0Small improvements494f0afNo need to handle token cache manually in promptab6740dMore clearis_token_valid📊 Changes
13 files changed (+217 additions, -307 deletions)
View changed files
📝
Cargo.toml(+1 -0)📝
examples/webapp/Cargo.toml(+1 -1)📝
examples/webapp/src/main.rs(+95 -125)📝
src/auth_code.rs(+15 -10)📝
src/auth_code_pkce.rs(+15 -10)📝
src/client_creds.rs(+4 -30)📝
src/clients/base.rs(+79 -17)📝
src/clients/oauth.rs(+6 -79)📝
src/lib.rs(+0 -1)➖
src/sync/blocking.rs(+0 -1)➖
src/sync/futures.rs(+0 -16)➖
src/sync/mod.rs(+0 -16)📝
tests/test_with_oauth.rs(+1 -1)📄 Description
Description
This PR simplifies
rspotify's usage based on the webapp example. I realized that we were really handing the token cache ourselves, instead of being automatic. We had lots of unnecessary boilerplate, which I've now simplified thanks to a refactored auth flow:read_token_cacheintoBaseClientand generalized it to all kinds of clients through the methodis_token_valid. Note that valid doesn't mean that it's ready to be used, just that it matches the flow, and that it could be used to reauthenticate (i.e., even if expired, we have a refresh token).write_token_cacheso that it needs to have thetokenpassed, instead of only usingself.token. Not only does this avoid unnecessary locks in some places (and weird code because we don't want to lock inside a lock), but also it's more consistent with the wayread_cache_tokenworks.token_cachedandtoken_refreshingare enabled. Otherwise, they'll have to take care of that themselves.Motivation and Context
This closes #324
Dependencies
parking_lotmakestoken's usage simpler by simply not dealing with lock poisoning manually. We can avoidunwrapfor every lock we have. Furthermore, I've removed the async variant, as many sources indicate that a regular mutex is usually better anyway.Type of change
Please delete options that are not relevant.
How has this been tested?
Ran it locally
Is this change properly documented?
Yes.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.