@@ -17,12 +17,13 @@ use std::collections::HashSet;
17
17
use clap:: Parser ;
18
18
use mas_config:: { ConfigurationSection , RootConfig , SyncConfig } ;
19
19
use mas_storage:: {
20
- upstream_oauth2:: UpstreamOAuthProviderRepository , RepositoryAccess , SystemClock ,
20
+ upstream_oauth2:: { UpstreamOAuthProviderParams , UpstreamOAuthProviderRepository } ,
21
+ RepositoryAccess , SystemClock ,
21
22
} ;
22
23
use mas_storage_pg:: PgRepository ;
23
24
use rand:: SeedableRng ;
24
25
use sqlx:: { postgres:: PgAdvisoryLock , Acquire } ;
25
- use tracing:: { info, info_span, warn} ;
26
+ use tracing:: { error , info, info_span, warn} ;
26
27
27
28
use crate :: util:: database_connection_from_config;
28
29
@@ -204,10 +205,11 @@ async fn sync(root: &super::Options, prune: bool, dry_run: bool) -> anyhow::Resu
204
205
}
205
206
206
207
for provider in config. upstream_oauth2 . providers {
208
+ let _span = info_span ! ( "provider" , %provider. id) . entered ( ) ;
207
209
if existing_ids. contains ( & provider. id ) {
208
- info ! ( %provider . id , "Updating provider" ) ;
210
+ info ! ( "Updating provider" ) ;
209
211
} else {
210
- info ! ( %provider . id , "Adding provider" ) ;
212
+ info ! ( "Adding provider" ) ;
211
213
}
212
214
213
215
if dry_run {
@@ -218,20 +220,65 @@ async fn sync(root: &super::Options, prune: bool, dry_run: bool) -> anyhow::Resu
218
220
. client_secret ( )
219
221
. map ( |client_secret| encrypter. encrypt_to_string ( client_secret. as_bytes ( ) ) )
220
222
. transpose ( ) ?;
221
- let client_auth_method = provider. client_auth_method ( ) ;
222
- let client_auth_signing_alg = provider. client_auth_signing_alg ( ) ;
223
+ let token_endpoint_auth_method = provider. client_auth_method ( ) ;
224
+ let token_endpoint_signing_alg = provider. client_auth_signing_alg ( ) ;
225
+
226
+ let discovery_mode = match provider. discovery_mode {
227
+ mas_config:: UpstreamOAuth2DiscoveryMode :: Oidc => {
228
+ mas_data_model:: UpstreamOAuthProviderDiscoveryMode :: Oidc
229
+ }
230
+ mas_config:: UpstreamOAuth2DiscoveryMode :: Insecure => {
231
+ mas_data_model:: UpstreamOAuthProviderDiscoveryMode :: Insecure
232
+ }
233
+ mas_config:: UpstreamOAuth2DiscoveryMode :: Disabled => {
234
+ mas_data_model:: UpstreamOAuthProviderDiscoveryMode :: Disabled
235
+ }
236
+ } ;
237
+
238
+ if discovery_mode. is_disabled ( ) {
239
+ if provider. authorization_endpoint . is_none ( ) {
240
+ error ! ( "Provider has discovery disabled but no authorization endpoint set" ) ;
241
+ }
242
+
243
+ if provider. token_endpoint . is_none ( ) {
244
+ error ! ( "Provider has discovery disabled but no token endpoint set" ) ;
245
+ }
246
+
247
+ if provider. jwks_uri . is_none ( ) {
248
+ error ! ( "Provider has discovery disabled but no JWKS URI set" ) ;
249
+ }
250
+ }
251
+
252
+ let pkce_mode = match provider. pkce_method {
253
+ mas_config:: UpstreamOAuth2PkceMethod :: Auto => {
254
+ mas_data_model:: UpstreamOAuthProviderPkceMode :: Auto
255
+ }
256
+ mas_config:: UpstreamOAuth2PkceMethod :: Always => {
257
+ mas_data_model:: UpstreamOAuthProviderPkceMode :: S256
258
+ }
259
+ mas_config:: UpstreamOAuth2PkceMethod :: Never => {
260
+ mas_data_model:: UpstreamOAuthProviderPkceMode :: Disabled
261
+ }
262
+ } ;
223
263
224
264
repo. upstream_oauth_provider ( )
225
265
. upsert (
226
266
& clock,
227
267
provider. id ,
228
- provider. issuer ,
229
- provider. scope . parse ( ) ?,
230
- client_auth_method,
231
- client_auth_signing_alg,
232
- provider. client_id ,
233
- encrypted_client_secret,
234
- map_claims_imports ( & provider. claims_imports ) ,
268
+ UpstreamOAuthProviderParams {
269
+ issuer : provider. issuer ,
270
+ scope : provider. scope . parse ( ) ?,
271
+ token_endpoint_auth_method,
272
+ token_endpoint_signing_alg,
273
+ client_id : provider. client_id ,
274
+ encrypted_client_secret,
275
+ claims_imports : map_claims_imports ( & provider. claims_imports ) ,
276
+ token_endpoint_override : provider. token_endpoint ,
277
+ authorization_endpoint_override : provider. authorization_endpoint ,
278
+ jwks_uri_override : provider. jwks_uri ,
279
+ discovery_mode,
280
+ pkce_mode,
281
+ } ,
235
282
)
236
283
. await ?;
237
284
}
@@ -268,10 +315,11 @@ async fn sync(root: &super::Options, prune: bool, dry_run: bool) -> anyhow::Resu
268
315
}
269
316
270
317
for client in config. clients . iter ( ) {
318
+ let _span = info_span ! ( "client" , client. id = %client. client_id) . entered ( ) ;
271
319
if existing_ids. contains ( & client. client_id ) {
272
- info ! ( client . id = %client . client_id , "Updating client" ) ;
320
+ info ! ( "Updating client" ) ;
273
321
} else {
274
- info ! ( client . id = %client . client_id , "Adding client" ) ;
322
+ info ! ( "Adding client" ) ;
275
323
}
276
324
277
325
if dry_run {
0 commit comments