1
1
use core:: panic;
2
2
use std:: {
3
- collections:: BTreeMap ,
3
+ collections:: {
4
+ BTreeMap ,
5
+ HashMap ,
6
+ } ,
4
7
fmt,
5
8
time:: {
6
9
Duration ,
@@ -43,9 +46,14 @@ use errors::ErrorMetadata;
43
46
use metrics:: StaticMetricLabel ;
44
47
use openidconnect:: {
45
48
core:: {
46
- CoreIdToken ,
49
+ CoreGenderClaim ,
47
50
CoreIdTokenVerifier ,
51
+ CoreJsonWebKeyType ,
52
+ CoreJweContentEncryptionAlgorithm ,
53
+ CoreJwsSigningAlgorithm ,
48
54
} ,
55
+ AdditionalClaims ,
56
+ IdToken ,
49
57
Nonce ,
50
58
} ;
51
59
use pb:: {
@@ -370,7 +378,7 @@ pub struct UserIdentity {
370
378
pub expiration : SystemTime ,
371
379
pub attributes : UserIdentityAttributes ,
372
380
// The original token this user identity was created from.
373
- pub original_token : CoreIdToken ,
381
+ pub original_token : CoreIdTokenWithCustomClaims ,
374
382
}
375
383
376
384
#[ cfg( any( test, feature = "testing" ) ) ]
@@ -422,9 +430,21 @@ macro_rules! get_localized_string {
422
430
} ;
423
431
}
424
432
433
+ pub type CoreIdTokenWithCustomClaims = IdToken <
434
+ CustomClaims ,
435
+ CoreGenderClaim ,
436
+ CoreJweContentEncryptionAlgorithm ,
437
+ CoreJwsSigningAlgorithm ,
438
+ CoreJsonWebKeyType ,
439
+ > ;
440
+
441
+ #[ derive( Deserialize , Serialize , Debug , Clone , Default , PartialEq , Eq ) ]
442
+ pub struct CustomClaims ( HashMap < String , serde_json:: Value > ) ;
443
+ impl AdditionalClaims for CustomClaims { }
444
+
425
445
impl UserIdentity {
426
446
pub fn from_token (
427
- token : CoreIdToken ,
447
+ token : CoreIdTokenWithCustomClaims ,
428
448
verifier : CoreIdTokenVerifier ,
429
449
) -> Result < Self , anyhow:: Error > {
430
450
// NB: Nonce verification is optional, and we'd need the developer to create and
@@ -436,7 +456,7 @@ impl UserIdentity {
436
456
let subject = claims. subject ( ) . to_string ( ) ;
437
457
let issuer = claims. issuer ( ) . to_string ( ) ;
438
458
let mut custom_claims = BTreeMap :: new ( ) ;
439
- for claim in claims. custom_claims ( ) {
459
+ for claim in & claims. additional_claims ( ) . 0 {
440
460
// Filter out standard claims and claims set by auth providers
441
461
match claim. 0 . as_str ( ) {
442
462
// Standard claims that we support: see https://docs.convex.dev/api/interfaces/server.UserIdentity
0 commit comments