Skip to content
This repository was archived by the owner on May 25, 2025. It is now read-only.

Commit 7c661b4

Browse files
committed
Added custom scopes
1 parent 9c6744d commit 7c661b4

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ services:
5858
# - 'ACR_VALUES=password email' # <- OpenID Context Authentication Context Requirements,
5959
# space seperated list of allowed actions (OPTIONAL), see
6060
# https://github.com/MarcelCoding/jitsi-openid/issues/122
61+
# - 'SCOPES=openid email jitsi' # <- OpenID Scopes, space seperated list of scopes (OPTIONAL),
62+
# default: openid email
6163
ports:
6264
- '3000:3000'
6365

src/cfg.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,26 @@ pub(crate) struct Cfg {
2222
#[serde(default)]
2323
#[serde(deserialize_with = "string_array")]
2424
pub(crate) acr_values: Option<Vec<AuthenticationContextClass>>,
25+
#[serde(default)]
26+
#[serde(deserialize_with = "string_array2")]
27+
pub(crate) scopes: Option<Vec<String>>,
2528
}
2629

2730
fn default_listen_addr() -> SocketAddr {
2831
([127, 0, 0, 1], 3000).into()
2932
}
3033

34+
/// Serializes an OffsetDateTime to a Unix timestamp (milliseconds since 1970/1/1T00:00:00T)
35+
pub fn string_array2<'a, D: Deserializer<'a>>(
36+
deserializer: D,
37+
) -> Result<Option<Vec<String>>, D::Error> {
38+
let input: String = Deserialize::deserialize(deserializer)?;
39+
40+
let values = input.split(' ').map(|acr| acr.to_string()).collect();
41+
42+
Ok(Some(values))
43+
}
44+
3145
/// Serializes an OffsetDateTime to a Unix timestamp (milliseconds since 1970/1/1T00:00:00T)
3246
pub fn string_array<'a, D: Deserializer<'a>>(
3347
deserializer: D,

src/routes.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,20 @@ async fn room(
4848
CsrfToken::new_random,
4949
Nonce::new_random,
5050
)
51-
.set_pkce_challenge(pkce_challenge)
52-
.add_scope(Scope::new("profile".to_string()))
53-
.add_scope(Scope::new("email".to_string()));
51+
.set_pkce_challenge(pkce_challenge);
52+
53+
match config.scopes {
54+
None => {
55+
request = request
56+
.add_scope(Scope::new("profile".to_string()))
57+
.add_scope(Scope::new("email".to_string()))
58+
}
59+
Some(scopes) => {
60+
for scope in &scopes {
61+
request = request.add_scope(Scope::new(scope.to_string()));
62+
}
63+
}
64+
};
5465

5566
if let Some(acr_values) = config.acr_values {
5667
for class in acr_values {

0 commit comments

Comments
 (0)