@@ -790,7 +790,7 @@ struct UserIdentityAttributesJson {
790
790
#[ serde( skip_serializing_if = "Option::is_none" ) ]
791
791
pub updated_at : Option < String > ,
792
792
#[ serde( flatten) ]
793
- pub custom_claims : Option < BTreeMap < String , String > > ,
793
+ pub custom_claims : Option < BTreeMap < String , JsonValue > > ,
794
794
}
795
795
796
796
impl TryFrom < JsonValue > for UserIdentityAttributes {
@@ -808,6 +808,13 @@ impl TryFrom<JsonValue> for UserIdentityAttributes {
808
808
let custom_claims = raw
809
809
. custom_claims
810
810
. context ( "expected custom claims to be set" ) ?;
811
+ let custom_claims_string = custom_claims
812
+ . into_iter ( )
813
+ . map ( |( key, value) | {
814
+ let value_string = serde_json:: to_string ( & value) ?;
815
+ Ok ( ( key, value_string) )
816
+ } )
817
+ . collect :: < anyhow:: Result < _ > > ( ) ?;
811
818
812
819
Ok ( UserIdentityAttributes {
813
820
token_identifier,
@@ -831,7 +838,7 @@ impl TryFrom<JsonValue> for UserIdentityAttributes {
831
838
phone_number_verified : raw. phone_number_verified ,
832
839
address : raw. address ,
833
840
updated_at : raw. updated_at ,
834
- custom_claims,
841
+ custom_claims : custom_claims_string ,
835
842
} )
836
843
}
837
844
}
@@ -840,6 +847,14 @@ impl TryFrom<UserIdentityAttributes> for JsonValue {
840
847
type Error = anyhow:: Error ;
841
848
842
849
fn try_from ( value : UserIdentityAttributes ) -> Result < Self , Self :: Error > {
850
+ let custom_claims_json = value
851
+ . custom_claims
852
+ . into_iter ( )
853
+ . map ( |( key, value) | {
854
+ let value_json = serde_json:: from_str ( & value) ?;
855
+ Ok ( ( key, value_json) )
856
+ } )
857
+ . collect :: < anyhow:: Result < _ > > ( ) ?;
843
858
let raw = UserIdentityAttributesJson {
844
859
token_identifier : Some ( value. token_identifier ) ,
845
860
issuer : value. issuer ,
@@ -862,7 +877,7 @@ impl TryFrom<UserIdentityAttributes> for JsonValue {
862
877
phone_number_verified : value. phone_number_verified ,
863
878
address : value. address ,
864
879
updated_at : value. updated_at ,
865
- custom_claims : Some ( value . custom_claims ) ,
880
+ custom_claims : Some ( custom_claims_json ) ,
866
881
} ;
867
882
Ok ( serde_json:: to_value ( raw) ?)
868
883
}
0 commit comments