|
6 | 6 | //! |
7 | 7 | //! This module contains the core implementation of the JWT token store. |
8 | 8 |
|
9 | | -use std::collections::HashMap; |
10 | | -use std::sync::Arc; |
11 | 9 | use chrono::{DateTime, Duration, TimeZone, Utc}; |
12 | 10 | use jsonwebtoken::{decode, encode, Algorithm, DecodingKey, EncodingKey, Header, Validation}; |
13 | 11 | use oxide_auth::primitives::generator::{RandomGenerator, TagGrant}; |
14 | 12 | use oxide_auth::primitives::grant::{Extensions, Grant, Value}; |
15 | 13 | use oxide_auth::primitives::issuer::{IssuedToken, Issuer, RefreshedToken, TokenType}; |
16 | 14 | use serde_json::Value as JsonValue; |
| 15 | +use std::collections::HashMap; |
| 16 | +use std::sync::Arc; |
17 | 17 | use url::Url; |
18 | 18 |
|
19 | 19 | use super::claims::{IdTokenClaims, JwtClaims}; |
@@ -279,22 +279,31 @@ impl JwtTokenMap { |
279 | 279 | let sid = sid.or_else(|| Some(format!("session-{}", self.usage_counter))); |
280 | 280 | // Convert nonce to a string if it exists |
281 | 281 | let nonce = nonce.map(|n| n.to_string()); |
282 | | - |
| 282 | + |
283 | 283 | // Create the ID token claims |
284 | 284 | let mut additional_claims = HashMap::new(); |
285 | | - |
| 285 | + |
286 | 286 | // Add any extra claims that weren't explicitly handled |
287 | 287 | for (key, value) in &self.claims { |
288 | | - if !matches!(key.as_str(), |
289 | | - "user_name" | "name" | "preferred_username" | "nickname" | |
290 | | - "picture" | "email" | "email_verified" | "sid" | |
291 | | - "user_id" | "user_permissions") { |
| 288 | + if !matches!( |
| 289 | + key.as_str(), |
| 290 | + "user_name" |
| 291 | + | "name" |
| 292 | + | "preferred_username" |
| 293 | + | "nickname" |
| 294 | + | "picture" |
| 295 | + | "email" |
| 296 | + | "email_verified" |
| 297 | + | "sid" |
| 298 | + | "user_id" |
| 299 | + | "user_permissions" |
| 300 | + ) { |
292 | 301 | if let Value::Public(Some(val)) = value { |
293 | 302 | additional_claims.insert(key.clone(), val.clone()); |
294 | 303 | } |
295 | 304 | } |
296 | 305 | } |
297 | | - |
| 306 | + |
298 | 307 | // Create the ID token claims |
299 | 308 | Some(IdTokenClaims { |
300 | 309 | sub: grant.owner_id.clone(), |
@@ -398,15 +407,15 @@ impl Issuer for JwtTokenMap { |
398 | 407 | } else { |
399 | 408 | None // No ID token if 'openid' scope is not requested |
400 | 409 | }; |
401 | | - |
| 410 | + |
402 | 411 | // Store the token |
403 | 412 | let token_entry = Arc::new(TokenEntry::new( |
404 | | - access_token.clone(), |
405 | | - id_token.clone(), |
406 | | - refresh_token.clone(), |
407 | | - grant.clone(), |
408 | | - grant.until, |
409 | | - id_token_claims |
| 413 | + access_token.clone(), |
| 414 | + id_token.clone(), |
| 415 | + refresh_token.clone(), |
| 416 | + grant.clone(), |
| 417 | + grant.until, |
| 418 | + id_token_claims, |
410 | 419 | )); |
411 | 420 |
|
412 | 421 | // Add to maps |
|
0 commit comments