[GH-ISSUE #412] Automatically request token on startup #133

Closed
opened 2026-02-27 20:23:19 +03:00 by kerem · 5 comments
Owner

Originally created by @kangalio on GitHub (May 19, 2023).
Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/412

Is your feature request related to a problem? Please describe.
Having to call client.request_token().await? once after initializing ClientCredsSpotify and before making the first API call seems a bit arbitrary and easy-to-forget.

Describe the solution you'd like
RSpotify already seems to have auto-authentication capabilities. Could those be expanded to auto-authenticate on the first API call and not have to manually call .request_token() on startup?

Originally created by @kangalio on GitHub (May 19, 2023). Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/412 **Is your feature request related to a problem? Please describe.** Having to call `client.request_token().await?` once after initializing ClientCredsSpotify and before making the first API call seems a bit arbitrary and easy-to-forget. **Describe the solution you'd like** RSpotify already seems to have auto-authentication capabilities. Could those be expanded to auto-authenticate on the first API call and not have to manually call `.request_token()` on startup?
kerem 2026-02-27 20:23:19 +03:00
Author
Owner

@ramsayleung commented on GitHub (May 20, 2023):

In the initialized design of this library, request_token is automatically called on the startup when initializing the client, the process of request_token is transparent to the developers, someone will be confused that why did they get an error complaining that the token is invalid, while they don't know they have requested a token implicitly.

So we refactored this client and expose the request_token function to the developers, requiring them to request token explicitly, being aware of the flow of requesting token.

From where I understand, this project is a library, it's not responsible to do everything for the developers, it should expose all possible facilities to developer instead.

Additionally, it's only possible for ClientCredsSpotify to request_token automatically, but there are three clients in RSpotify, including AuthCodeSpotify, AuthCodePkceSpotify, which are unable to request_token automatically, because authorization flows require user interaction in the browser.

In order to maintain a consistent behavior for all clients, it's necessary to require developer to call request_token before making the first API call

<!-- gh-comment-id:1555568632 --> @ramsayleung commented on GitHub (May 20, 2023): In the initialized design of this library, `request_token` is automatically called on the startup when initializing the client, the process of `request_token` is transparent to the developers, someone will be confused that why did they get an error complaining that the token is invalid, while they don't know they have requested a token implicitly. So we refactored this client and expose the `request_token` function to the developers, requiring them to request token explicitly, being aware of the flow of requesting token. From where I understand, this project is a library, it's not responsible to do everything for the developers, it should expose all possible facilities to developer instead. Additionally, it's only possible for `ClientCredsSpotify` to `request_token` automatically, but there are three clients in `RSpotify`, including `AuthCodeSpotify`, `AuthCodePkceSpotify`, which are unable to `request_token` automatically, because authorization flows require user interaction in the browser. In order to maintain a consistent behavior for all clients, it's necessary to require developer to call `request_token` before making the first API call
Author
Owner

@kangalio commented on GitHub (May 23, 2023):

Ah, I can see how consistency to the other two authentication methods is nice. Still, for me as a fresh user of RSpotify, auto-authentication in ClientCredsSpotify seems less surprising and more user-friendly.

I had assumed RSpotify abstracts over the authorization workflow. However, you have to be aware that the underlying Spotify API requires a token request call. And later, (this ties in with #413) you have to be aware that Spotify requires hourly re-authentication. The fact that RSpotify exposes these details, when they could easily be done by RSpotify itself, surprised me.

Are there other API wrappers that require you to call an extra method after initializing the client to finish initialization? For example serenity doesn't

<!-- gh-comment-id:1559811342 --> @kangalio commented on GitHub (May 23, 2023): Ah, I can see how consistency to the other two authentication methods is nice. Still, for me as a fresh user of RSpotify, auto-authentication in ClientCredsSpotify seems less surprising and more user-friendly. I had assumed RSpotify abstracts over the authorization workflow. However, you have to be aware that the underlying Spotify API requires a token request call. And later, (this ties in with #413) you have to be aware that Spotify requires hourly re-authentication. The fact that RSpotify exposes these details, when they could easily be done by RSpotify itself, surprised me. Are there other API wrappers that require you to call an extra method after initializing the client to finish initialization? For example [serenity](https://github.com/serenity-rs/serenity) doesn't
Author
Owner

@blueforesticarus commented on GitHub (May 26, 2023):

The requirement could perhaps be put in the type system.
As in, the clients could have a separate type for the uninitialized state.

<!-- gh-comment-id:1564411794 --> @blueforesticarus commented on GitHub (May 26, 2023): The requirement could perhaps be put in the type system. As in, the clients could have a separate type for the uninitialized state.
Author
Owner

@github-actions[bot] commented on GitHub (Nov 23, 2023):

Message to comment on stale issues. If none provided, will not mark issues stale

<!-- gh-comment-id:1823740608 --> @github-actions[bot] commented on GitHub (Nov 23, 2023): Message to comment on stale issues. If none provided, will not mark issues stale
Author
Owner

@github-actions[bot] commented on GitHub (Nov 28, 2025):

Message to comment on stale issues. If none provided, will not mark issues stale

<!-- gh-comment-id:3587752581 --> @github-actions[bot] commented on GitHub (Nov 28, 2025): Message to comment on stale issues. If none provided, will not mark issues stale
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/rspotify#133
No description provided.