Skip to content

Commit 38731cb

Browse files
committed
Add expires_in to introspection responses
1 parent 5a1ac37 commit 38731cb

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

crates/handlers/src/oauth2/introspection.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ const INACTIVE: IntrospectionResponse = IntrospectionResponse {
151151
username: None,
152152
token_type: None,
153153
exp: None,
154+
expires_in: None,
154155
iat: None,
155156
nbf: None,
156157
sub: None,
@@ -281,6 +282,9 @@ pub(crate) async fn post(
281282
username,
282283
token_type: Some(OAuthTokenTypeHint::AccessToken),
283284
exp: access_token.expires_at,
285+
expires_in: access_token
286+
.expires_at
287+
.map(|expires_at| expires_at.signed_duration_since(clock.now()).num_seconds()),
284288
iat: Some(access_token.created_at),
285289
nbf: Some(access_token.created_at),
286290
sub,
@@ -341,6 +345,7 @@ pub(crate) async fn post(
341345
username,
342346
token_type: Some(OAuthTokenTypeHint::RefreshToken),
343347
exp: None,
348+
expires_in: None,
344349
iat: Some(refresh_token.created_at),
345350
nbf: Some(refresh_token.created_at),
346351
sub,
@@ -414,6 +419,9 @@ pub(crate) async fn post(
414419
username: Some(user.username),
415420
token_type: Some(OAuthTokenTypeHint::AccessToken),
416421
exp: access_token.expires_at,
422+
expires_in: access_token
423+
.expires_at
424+
.map(|expires_at| expires_at.signed_duration_since(clock.now()).num_seconds()),
417425
iat: Some(access_token.created_at),
418426
nbf: Some(access_token.created_at),
419427
sub: Some(user.sub),
@@ -487,6 +495,7 @@ pub(crate) async fn post(
487495
username: Some(user.username),
488496
token_type: Some(OAuthTokenTypeHint::RefreshToken),
489497
exp: None,
498+
expires_in: None,
490499
iat: Some(refresh_token.created_at),
491500
nbf: Some(refresh_token.created_at),
492501
sub: Some(user.sub),

crates/oauth2-types/src/requests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,10 @@ pub struct IntrospectionResponse {
767767
#[serde_as(as = "Option<TimestampSeconds>")]
768768
pub exp: Option<DateTime<Utc>>,
769769

770+
/// Relative timestamp indicating when the token will expire,
771+
/// in seconds from the current instant.
772+
pub expires_in: Option<i64>,
773+
770774
/// Timestamp indicating when the token was issued.
771775
#[serde_as(as = "Option<TimestampSeconds>")]
772776
pub iat: Option<DateTime<Utc>>,

0 commit comments

Comments
 (0)