-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jsonwebtoken): flatten claims to align with rfc (#780)
- Loading branch information
Showing
9 changed files
with
32 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,4 @@ | ||
use napi_derive::napi; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::{Map, Number, Value}; | ||
use indexmap::IndexMap; | ||
use serde_json::Value; | ||
|
||
#[napi(object)] | ||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Claims { | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub data: Option<Map<String, Value>>, | ||
// Recipient for which the JWT is intended | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub aud: Option<String>, | ||
// Time after which the JWT expires (as UTC timestamp, seconds from epoch time) | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub exp: Option<Number>, | ||
// Time at which the JWT was issued (as UTC timestamp, seconds from epoch time) | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub iat: Option<Number>, | ||
// Issuer of JWT | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub iss: Option<String>, | ||
// [JWT id] Unique identifier | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub jti: Option<String>, | ||
// [not-before-time] Time before which the JWT must not be accepted for processing (as UTC timestamp, seconds from epoch time) | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub nbf: Option<Number>, | ||
// Subject of JWT (the user) | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub sub: Option<String>, | ||
} | ||
|
||
impl Claims { | ||
#[inline] | ||
pub fn merge(self, other: Self) -> Self { | ||
Self { | ||
data: self.data, | ||
aud: self.aud.or(other.aud), | ||
exp: self.exp.or(other.exp), | ||
iat: self.iat.or(other.iat), | ||
iss: self.iss.or(other.iss), | ||
jti: self.jti.or(other.jti), | ||
nbf: self.nbf.or(other.nbf), | ||
sub: self.sub.or(other.sub), | ||
} | ||
} | ||
} | ||
|
||
impl Default for Claims { | ||
#[inline] | ||
fn default() -> Self { | ||
Self { | ||
data: Some(Map::new()), | ||
aud: None, | ||
exp: None, | ||
iat: Some(jsonwebtoken::get_current_timestamp().into()), | ||
iss: None, | ||
jti: None, | ||
nbf: None, | ||
sub: None, | ||
} | ||
} | ||
} | ||
pub type Claims = IndexMap<String, Value>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters