@@ -25,7 +25,7 @@ use actix_web::{
2525 http:: header:: ContentType ,
2626 web,
2727} ;
28- use chrono:: TimeDelta ;
28+ use chrono:: { Duration , TimeDelta } ;
2929use openid:: Bearer ;
3030use regex:: Regex ;
3131use serde:: Deserialize ;
@@ -275,23 +275,38 @@ pub async fn reply_login(
275275 // If still no roles, look for a native user with the same email
276276 // and inherit their roles (e.g. tenant owner logging in via OAuth)
277277 if final_roles. is_empty ( )
278- && let Some ( email) = & user_info. email {
279- for u in & metadata . users {
280- if matches ! ( u . ty , UserType :: Native ( _ ) )
281- && u . userid ( ) == email . as_str ( )
282- && !u . roles . is_empty ( )
283- {
284- final_roles . clone_from ( & u . roles ) ;
285- break ;
286- }
278+ && let Some ( email) = & user_info. email
279+ {
280+ for u in & metadata . users {
281+ if matches ! ( u . ty , UserType :: Native ( _ ) )
282+ && u . userid ( ) == email . as_str ( )
283+ && !u . roles . is_empty ( )
284+ {
285+ final_roles . clone_from ( & u . roles ) ;
286+ break ;
287287 }
288288 }
289+ }
290+
291+ let expires_in = if let Some ( expires_in) = bearer. expires_in . as_ref ( ) {
292+ // need an i64 somehow
293+ if * expires_in > u32:: MAX . into ( ) {
294+ EXPIRY_DURATION
295+ } else {
296+ let v = i64:: from ( * expires_in as u32 ) ;
297+ Duration :: seconds ( v)
298+ }
299+ } else {
300+ EXPIRY_DURATION
301+ } ;
289302
290- match ( existing_user, final_roles) {
303+ let user = match ( existing_user, final_roles) {
291304 ( Some ( user) , roles) => update_user_if_changed ( user, roles, user_info, bearer) . await ?,
292305 ( None , roles) => put_user ( & user_id, roles, user_info, bearer, tenant_id. clone ( ) ) . await ?,
293306 } ;
307+
294308 let id = Ulid :: new ( ) ;
309+ Users . new_session ( & user, SessionKey :: SessionId ( id) , expires_in) ;
295310
296311 let cookies = [
297312 cookie_session ( id) ,
0 commit comments