@@ -23,6 +23,7 @@ use minijinja::{
2323pub ( crate ) struct AttributeMappingContext {
2424 id_token_claims : Option < HashMap < String , serde_json:: Value > > ,
2525 extra_callback_parameters : Option < serde_json:: Value > ,
26+ userinfo_claims : Option < serde_json:: Value > ,
2627}
2728
2829impl AttributeMappingContext {
@@ -46,6 +47,11 @@ impl AttributeMappingContext {
4647 self
4748 }
4849
50+ pub fn with_userinfo_claims ( mut self , userinfo_claims : serde_json:: Value ) -> Self {
51+ self . userinfo_claims = Some ( userinfo_claims) ;
52+ self
53+ }
54+
4955 pub fn build ( self ) -> Value {
5056 Value :: from_object ( self )
5157 }
@@ -54,7 +60,25 @@ impl AttributeMappingContext {
5460impl Object for AttributeMappingContext {
5561 fn get_value ( self : & Arc < Self > , name : & Value ) -> Option < Value > {
5662 match name. as_str ( ) ? {
57- "user" | "id_token_claims" => self . id_token_claims . as_ref ( ) . map ( Value :: from_serialize) ,
63+ "user" => {
64+ if self . id_token_claims . is_none ( ) && self . userinfo_claims . is_none ( ) {
65+ return None ;
66+ }
67+ let mut merged_user: HashMap < String , serde_json:: Value > = HashMap :: new ( ) ;
68+ if let serde_json:: Value :: Object ( userinfo) = self
69+ . userinfo_claims
70+ . clone ( )
71+ . unwrap_or ( serde_json:: Value :: Null )
72+ {
73+ merged_user. extend ( userinfo) ;
74+ }
75+ if let Some ( id_token) = self . id_token_claims . clone ( ) {
76+ merged_user. extend ( id_token) ;
77+ }
78+ Some ( Value :: from_serialize ( merged_user) )
79+ }
80+ "id_token_claims" => self . id_token_claims . as_ref ( ) . map ( Value :: from_serialize) ,
81+ "userinfo_claims" => self . userinfo_claims . as_ref ( ) . map ( Value :: from_serialize) ,
5882 "extra_callback_parameters" => self
5983 . extra_callback_parameters
6084 . as_ref ( )
@@ -64,17 +88,20 @@ impl Object for AttributeMappingContext {
6488 }
6589
6690 fn enumerate ( self : & Arc < Self > ) -> Enumerator {
67- match (
68- self . id_token_claims . is_some ( ) ,
69- self . extra_callback_parameters . is_some ( ) ,
70- ) {
71- ( true , true ) => {
72- Enumerator :: Str ( & [ "user" , "id_token_claims" , "extra_callback_parameters" ] )
73- }
74- ( true , false ) => Enumerator :: Str ( & [ "user" , "id_token_claims" ] ) ,
75- ( false , true ) => Enumerator :: Str ( & [ "extra_callback_parameters" ] ) ,
76- ( false , false ) => Enumerator :: Str ( & [ "user" ] ) ,
91+ let mut attrs = Vec :: new ( ) ;
92+ if self . id_token_claims . is_some ( ) || self . userinfo_claims . is_none ( ) {
93+ attrs. push ( minijinja:: Value :: from ( "user" ) ) ;
94+ }
95+ if self . id_token_claims . is_some ( ) {
96+ attrs. push ( minijinja:: Value :: from ( "id_token_claims" ) ) ;
97+ }
98+ if self . userinfo_claims . is_some ( ) {
99+ attrs. push ( minijinja:: Value :: from ( "userinfo_claims" ) ) ;
100+ }
101+ if self . extra_callback_parameters . is_some ( ) {
102+ attrs. push ( minijinja:: Value :: from ( "extra_callback_parameters" ) ) ;
77103 }
104+ Enumerator :: Values ( attrs)
78105 }
79106}
80107
0 commit comments