Skip to content

Commit 1221fd1

Browse files
committed
fix: Ensure we add scopes for Spotify OAuth tokens
1 parent ab50837 commit 1221fd1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

config.example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ client_id = "xxxxx"
1111
client_secret = "xxxxx"
1212
auth_url = "https://accounts.spotify.com/authorize"
1313
token_url = "https://accounts.spotify.com/api/token"
14+
scopes = [
15+
"user-library-read",
16+
"playlist-modify-public",
17+
"playlist-modify-private"
18+
]
1419

1520
[web]
1621
address = "127.0.0.1:8080"

src/web/oauth.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
web::ui::{error_page, not_found},
44
};
55
use actix_web::{dev::HttpServiceFactory, web};
6-
use oauth2::{CsrfToken, TokenResponse};
6+
use oauth2::{CsrfToken, Scope, TokenResponse};
77
use reqwest::Url;
88
use serde::Deserialize;
99
use yew::{ServerRenderer, html};
@@ -163,6 +163,8 @@ pub struct OAuth2Config {
163163
pub client_secret: String,
164164
pub auth_url: String,
165165
pub token_url: String,
166+
#[serde(default)]
167+
pub scopes: Vec<String>,
166168
}
167169

168170
impl OAuth2Config {
@@ -183,6 +185,7 @@ impl OAuth2Config {
183185

184186
let (url, _csrf) = client
185187
.authorize_url(|| CsrfToken::new_random())
188+
.add_scopes(self.scopes.iter().cloned().map(Scope::new))
186189
.url()
187190
.clone();
188191
Ok(url)

0 commit comments

Comments
 (0)