[GH-ISSUE #380] Allow usage with provided tokens #120

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

Originally created by @TPausL on GitHub (Jan 2, 2023).
Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/380

Is your feature request related to a problem? Please describe.
I use authorization via Ory for my app and connect to spotify via them, so i already have authenticated the user. I can't figure out a way to insert that existing token into a rspotify client. I tried manuallly creating a Token from the library but can't access the correct duration and it is a not an intendet use I guess.

Describe the solution you'd like
It would be cool if you could use the api directly (just inserting the provided token to every request or on a per request basis) or create an auth flow from existing (external) data (tokens, expire date).

Originally created by @TPausL on GitHub (Jan 2, 2023). Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/380 **Is your feature request related to a problem? Please describe.** I use authorization via [Ory](https://ory.sh) for my app and connect to spotify via them, so i already have authenticated the user. I can't figure out a way to insert that existing token into a rspotify client. I tried manuallly creating a Token from the library but can't access the correct duration and it is a not an intendet use I guess. **Describe the solution you'd like** It would be cool if you could use the api directly (just inserting the provided token to every request or on a per request basis) or create an auth flow from existing (external) data (tokens, expire date).
kerem 2026-02-27 20:23:14 +03:00
Author
Owner

@ramsayleung commented on GitHub (Jan 6, 2023):

I can't figure out a way to insert that existing token into a rspotify client. I tried manuallly creating a Token from the library but can't access the correct duration and it is a not an intendet use I guess.

I am not familiar with Ory, what do you get after authenticating with user?

Does this work for you?

let manual_token = Token {
    access_token: String::from("your-access-token"),
    expires_in: Duration::seconds(3600), // The time period for which your access token is valid.
    expires_at: Some(Utc::now() + Duration::seconds(3600)),
    refresh_token: None,
    scopes: scopes!("user-follow-read user-follow-modify your-scopes")
};
let spotify = AuthCodeSpotify:: from_token(manual_token);  
let user = spotify.me();
println!("Request: {user:?}");
<!-- gh-comment-id:1373244345 --> @ramsayleung commented on GitHub (Jan 6, 2023): > I can't figure out a way to insert that existing token into a rspotify client. I tried manuallly creating a Token from the library but can't access the correct duration and it is a not an intendet use I guess. I am not familiar with `Ory`, what do you get after authenticating with user? Does this work for you? ```rs let manual_token = Token { access_token: String::from("your-access-token"), expires_in: Duration::seconds(3600), // The time period for which your access token is valid. expires_at: Some(Utc::now() + Duration::seconds(3600)), refresh_token: None, scopes: scopes!("user-follow-read user-follow-modify your-scopes") }; let spotify = AuthCodeSpotify:: from_token(manual_token); let user = spotify.me(); println!("Request: {user:?}"); ```
Author
Owner

@TPausL commented on GitHub (Jan 6, 2023):

Yeah I tried that before. My problem was that the correct type for the date wasn't accessible but i figured it out now with using the defaults and then setting the my access token. In order to refresh these I now create an AuthCodeFlow and set that token manually later. Is there are more elegant way or is that fine?

<!-- gh-comment-id:1373458813 --> @TPausL commented on GitHub (Jan 6, 2023): Yeah I tried that before. My problem was that the correct type for the date wasn't accessible but i figured it out now with using the defaults and then setting the my access token. In order to refresh these I now create an AuthCodeFlow and set that token manually later. Is there are more elegant way or is that fine?
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#120
No description provided.