Skip to content

Commit cea3a6a

Browse files
Jeidnxjevolk
authored andcommitted
chore: impl default value for callback_url
1 parent d67cb8b commit cea3a6a

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

src/core/config/mod.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,11 +2632,10 @@ pub struct IdentityProvider {
26322632
pub issuer_url: Option<Url>,
26332633

26342634
/// The callback URL configured when registering the OAuth application with
2635-
/// the provider. Tuwunel's callback URL must be strictly formatted exactly
2636-
/// as instructed. The URL host must point directly at the matrix server and
2637-
/// use the following path:
2638-
/// `/_matrix/client/unstable/login/sso/callback/<client_id>` where
2639-
/// `<client_id>` is the same one configured for this provider above.
2635+
/// the provider. This doesn't need to be set manually, it will be
2636+
/// constructed as:
2637+
/// `<global.well_known.client>/_matrix/client/unstable/login/sso/callback/
2638+
/// <client_id>`
26402639
pub callback_url: Option<Url>,
26412640

26422641
/// When more than one identity_provider has been configured and
@@ -2695,10 +2694,13 @@ pub struct IdentityProvider {
26952694
#[serde(default)]
26962695
pub userid_claims: BTreeSet<String>,
26972696

2698-
/// Optional extra path components after the issuer_url leading to the
2699-
/// location of the `.well-known` directory used for discovery. This will be
2700-
/// empty for specification-compliant providers. We have supplied any known
2701-
/// values based on `brand` (e.g. `/login/oauth` for GitHub).
2697+
/// Optionally overwrite the path used for the discovery url. If base_path
2698+
/// starts with a / the issuer path is ignored and the discovery url is
2699+
/// constructed from the host + base_path + well-known path. If base_path is
2700+
/// a relative path, it will be constructed relative to the issuer
2701+
/// path. This should be empty for specification-compliant providers. We
2702+
/// have supplied any known values based on `brand` (e.g. `/login/oauth`
2703+
/// for GitHub).
27022704
pub base_path: Option<String>,
27032705

27042706
/// Overrides the `.well-known` location where the provider's openid

src/service/oauth/providers.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,25 @@ async fn configure(&self, mut provider: Provider) -> Result<Provider> {
123123
.name
124124
.get_or_insert_with(|| provider.brand.clone());
125125

126+
if provider.callback_url.is_none() {
127+
let server_url = self
128+
.services
129+
.config
130+
.well_known
131+
.client
132+
.as_ref()
133+
.expect("should be set");
134+
135+
let callback_path =
136+
format!("_matrix/client/unstable/login/sso/callback/{}", provider.client_id);
137+
138+
provider.callback_url = Some(
139+
server_url
140+
.join(&callback_path)
141+
.expect("valid callback url"),
142+
);
143+
}
144+
126145
if provider.brand == "github" {
127146
return configure_github(provider);
128147
}

0 commit comments

Comments
 (0)