forked from
rocksky.app/rocksky
A decentralized music tracking and discovery platform built on AT Protocol 馃幍
1use std::env;
2
3use anyhow::Error;
4use reqwest::Client;
5use types::AccessToken;
6
7pub mod client;
8pub mod types;
9
10pub async fn refresh_token(token: &str) -> Result<AccessToken, Error> {
11 if env::var("SPOTIFY_CLIENT_ID").is_err() || env::var("SPOTIFY_CLIENT_SECRET").is_err() {
12 panic!("Please set SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET environment variables");
13 }
14
15 let client_id = env::var("SPOTIFY_CLIENT_ID")?;
16 let client_secret = env::var("SPOTIFY_CLIENT_SECRET")?;
17
18 let client = Client::new();
19
20 let response = client
21 .post("https://accounts.spotify.com/api/token")
22 .basic_auth(&client_id, Some(client_secret))
23 .form(&[
24 ("grant_type", "refresh_token"),
25 ("refresh_token", token),
26 ("client_id", &client_id),
27 ])
28 .send()
29 .await?;
30 let token = response.json::<AccessToken>().await?;
31 Ok(token)
32}