Skip to content

Commit df4a1ed

Browse files
committed
code quality
1 parent d83ea59 commit df4a1ed

File tree

6 files changed

+40
-32
lines changed

6 files changed

+40
-32
lines changed

src/visualization/jwt/claims.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub struct IdTokenClaims {
147147
/// Whether the user's email is verified
148148
#[serde(skip_serializing_if = "Option::is_none")]
149149
pub email_verified: Option<bool>,
150-
150+
151151
/// Additional custom claims
152152
#[serde(flatten)]
153153
pub additional_claims: HashMap<String, String>,

src/visualization/jwt/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
4848
// Internal modules that are not public
4949
mod claims;
50-
mod token_entry;
51-
mod token_map;
5250
mod issuer;
5351
mod responses;
52+
mod token_entry;
53+
mod token_map;
5454

5555
// Existing modules that remain public
5656
/// JWT extensions for OpenID Connect support

src/visualization/jwt/responses.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
//!
77
//! This module contains the response structures for OAuth token requests.
88
9+
use chrono::Utc;
910
use oxide_auth::primitives::issuer::IssuedToken;
1011
use serde::{Deserialize, Serialize};
11-
use chrono::Utc;
1212

1313
/// Custom OAuth token response structure with OpenID Connect support
1414
///
@@ -57,7 +57,7 @@ impl OidcTokenResponse {
5757
scope,
5858
}
5959
}
60-
60+
6161
/// Create a new OIDC token response with specified parameters
6262
pub fn new(
6363
access_token: String,

src/visualization/jwt/token_entry.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
1010
use chrono::{DateTime, Utc};
1111
use oxide_auth::primitives::grant::Grant;
12-
use std::collections::HashMap;
1312
use serde_json::Value;
13+
use std::collections::HashMap;
1414

1515
use super::claims::IdTokenClaims;
1616

@@ -54,7 +54,7 @@ pub struct TokenEntry {
5454
/// The time at which this token will expire and no longer be valid for use.
5555
/// Both access and refresh tokens share the same expiration time in this implementation.
5656
pub expiry: DateTime<Utc>,
57-
57+
5858
/// ID token claims stored for reference
5959
pub id_token_claims: Option<IdTokenClaims>,
6060
}
@@ -78,12 +78,12 @@ impl TokenEntry {
7878
id_token_claims,
7979
}
8080
}
81-
81+
8282
/// Check if the token has expired
8383
pub fn is_expired(&self) -> bool {
8484
self.expiry < Utc::now()
8585
}
86-
86+
8787
/// Get remaining validity time in seconds
8888
pub fn valid_for_seconds(&self) -> i64 {
8989
let now = Utc::now();
@@ -93,17 +93,17 @@ impl TokenEntry {
9393
(self.expiry - now).num_seconds()
9494
}
9595
}
96-
96+
9797
/// Get the user ID (subject) from the grant
9898
pub fn user_id(&self) -> &str {
9999
&self.grant.owner_id
100100
}
101-
101+
102102
/// Get the client ID from the grant
103103
pub fn client_id(&self) -> &str {
104104
&self.grant.client_id
105105
}
106-
106+
107107
/// Get the scope as a space-separated string
108108
pub fn scope(&self) -> String {
109109
self.grant.scope.to_string()

src/visualization/jwt/token_map.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
//!
77
//! This module contains the core implementation of the JWT token store.
88
9-
use std::collections::HashMap;
10-
use std::sync::Arc;
119
use chrono::{DateTime, Duration, TimeZone, Utc};
1210
use jsonwebtoken::{decode, encode, Algorithm, DecodingKey, EncodingKey, Header, Validation};
1311
use oxide_auth::primitives::generator::{RandomGenerator, TagGrant};
1412
use oxide_auth::primitives::grant::{Extensions, Grant, Value};
1513
use oxide_auth::primitives::issuer::{IssuedToken, Issuer, RefreshedToken, TokenType};
1614
use serde_json::Value as JsonValue;
15+
use std::collections::HashMap;
16+
use std::sync::Arc;
1717
use url::Url;
1818

1919
use super::claims::{IdTokenClaims, JwtClaims};
@@ -279,22 +279,31 @@ impl JwtTokenMap {
279279
let sid = sid.or_else(|| Some(format!("session-{}", self.usage_counter)));
280280
// Convert nonce to a string if it exists
281281
let nonce = nonce.map(|n| n.to_string());
282-
282+
283283
// Create the ID token claims
284284
let mut additional_claims = HashMap::new();
285-
285+
286286
// Add any extra claims that weren't explicitly handled
287287
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+
) {
292301
if let Value::Public(Some(val)) = value {
293302
additional_claims.insert(key.clone(), val.clone());
294303
}
295304
}
296305
}
297-
306+
298307
// Create the ID token claims
299308
Some(IdTokenClaims {
300309
sub: grant.owner_id.clone(),
@@ -398,15 +407,15 @@ impl Issuer for JwtTokenMap {
398407
} else {
399408
None // No ID token if 'openid' scope is not requested
400409
};
401-
410+
402411
// Store the token
403412
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,
410419
));
411420

412421
// Add to maps

src/visualization/server.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,9 @@ pub async fn build_rocket(figment: Figment) -> Rocket<Build> {
442442
base64::engine::general_purpose::STANDARD.decode(&oxide_state.rs256_public_key)
443443
{
444444
// Create a new JWT issuer with RS256 keys
445-
if let Ok(jwt_issuer) = super::jwt::JwtIssuer::with_rs256_pem(
446-
&decoded_private,
447-
&decoded_public,
448-
) {
445+
if let Ok(jwt_issuer) =
446+
super::jwt::JwtIssuer::with_rs256_pem(&decoded_private, &decoded_public)
447+
{
449448
oxide_state.issuer = std::sync::Arc::new(std::sync::Mutex::new(jwt_issuer));
450449
}
451450
}

0 commit comments

Comments
 (0)