@@ -131,15 +131,15 @@ fn get_app_host(config: &AppConfig) -> String {
131131}
132132
133133pub struct OidcState {
134- pub config : Arc < OidcConfig > ,
135- pub client : Arc < OidcClient > ,
134+ pub config : OidcConfig ,
135+ pub client : OidcClient ,
136136}
137137
138138pub async fn initialize_oidc_state (
139139 app_config : & AppConfig ,
140140) -> anyhow:: Result < Option < Arc < OidcState > > > {
141141 let oidc_cfg = match OidcConfig :: try_from ( app_config) {
142- Ok ( c) => Arc :: new ( c ) ,
142+ Ok ( c) => c ,
143143 Err ( None ) => return Ok ( None ) , // OIDC not configured
144144 Err ( Some ( e) ) => return Err ( anyhow:: anyhow!( e) ) ,
145145 } ;
@@ -151,7 +151,7 @@ pub async fn initialize_oidc_state(
151151
152152 Ok ( Some ( Arc :: new ( OidcState {
153153 config : oidc_cfg,
154- client : Arc :: new ( client ) ,
154+ client,
155155 } ) ) )
156156}
157157
@@ -251,17 +251,26 @@ where
251251 & self ,
252252 request : ServiceRequest ,
253253 ) -> LocalBoxFuture < Result < ServiceResponse < BoxBody > , Error > > {
254- let oidc_client = Arc :: clone ( & self . oidc_state . client ) ;
255- let oidc_config = Arc :: clone ( & self . oidc_state . config ) ;
254+ let oidc_state = Arc :: clone ( & self . oidc_state ) ;
256255
257256 Box :: pin ( async move {
258257 let query_string = request. query_string ( ) ;
259- match process_oidc_callback ( & oidc_client, & oidc_config, query_string, & request) . await {
258+ match process_oidc_callback (
259+ & oidc_state. client ,
260+ & oidc_state. config ,
261+ query_string,
262+ & request,
263+ )
264+ . await
265+ {
260266 Ok ( response) => Ok ( request. into_response ( response) ) ,
261267 Err ( e) => {
262268 log:: error!( "Failed to process OIDC callback with params {query_string}: {e}" ) ;
263- let resp =
264- build_auth_provider_redirect_response ( & oidc_client, & oidc_config, & request) ;
269+ let resp = build_auth_provider_redirect_response (
270+ & oidc_state. client ,
271+ & oidc_state. config ,
272+ & request,
273+ ) ;
265274 Ok ( request. into_response ( resp) )
266275 }
267276 }
@@ -296,9 +305,9 @@ where
296305 fn call ( & self , request : ServiceRequest ) -> Self :: Future {
297306 log:: trace!( "Started OIDC middleware request handling" ) ;
298307
299- let oidc_client = Arc :: clone ( & self . oidc_state . client ) ;
300- let oidc_config = Arc :: clone ( & self . oidc_state . config ) ;
301- match get_authenticated_user_info ( & oidc_client, & oidc_config, & request) {
308+ let oidc_client = & self . oidc_state . client ;
309+ let oidc_config = & self . oidc_state . config ;
310+ match get_authenticated_user_info ( oidc_client, oidc_config, & request) {
302311 Ok ( Some ( claims) ) => {
303312 if request. path ( ) == SQLPAGE_REDIRECT_URI {
304313 return handle_authenticated_oidc_callback ( request) ;
@@ -331,7 +340,7 @@ where
331340
332341async fn process_oidc_callback (
333342 oidc_client : & OidcClient ,
334- oidc_config : & Arc < OidcConfig > ,
343+ oidc_config : & OidcConfig ,
335344 query_string : & str ,
336345 request : & ServiceRequest ,
337346) -> anyhow:: Result < HttpResponse > {
@@ -381,7 +390,7 @@ fn set_auth_cookie(
381390 response : & mut HttpResponse ,
382391 token_response : & openidconnect:: core:: CoreTokenResponse ,
383392 oidc_client : & OidcClient ,
384- oidc_config : & Arc < OidcConfig > ,
393+ oidc_config : & OidcConfig ,
385394) -> anyhow:: Result < ( ) > {
386395 let access_token = token_response. access_token ( ) ;
387396 log:: trace!( "Received access token: {}" , access_token. secret( ) ) ;
@@ -418,7 +427,7 @@ fn set_auth_cookie(
418427
419428fn build_auth_provider_redirect_response (
420429 oidc_client : & OidcClient ,
421- oidc_config : & Arc < OidcConfig > ,
430+ oidc_config : & OidcConfig ,
422431 request : & ServiceRequest ,
423432) -> HttpResponse {
424433 let AuthUrl { url, params } = build_auth_url ( oidc_client, & oidc_config. scopes ) ;
@@ -438,7 +447,7 @@ fn build_redirect_response(target_url: String) -> HttpResponse {
438447/// Returns the claims from the ID token in the `SQLPage` auth cookie.
439448fn get_authenticated_user_info (
440449 oidc_client : & OidcClient ,
441- config : & Arc < OidcConfig > ,
450+ config : & OidcConfig ,
442451 request : & ServiceRequest ,
443452) -> anyhow:: Result < Option < OidcClaims > > {
444453 let Some ( cookie) = request. cookie ( SQLPAGE_AUTH_COOKIE_NAME ) else {
@@ -546,7 +555,7 @@ impl std::error::Error for AwcWrapperError {
546555}
547556
548557fn make_oidc_client (
549- config : & Arc < OidcConfig > ,
558+ config : & OidcConfig ,
550559 provider_metadata : openidconnect:: core:: CoreProviderMetadata ,
551560) -> anyhow:: Result < OidcClient > {
552561 let client_id = openidconnect:: ClientId :: new ( config. client_id . clone ( ) ) ;
0 commit comments