Skip to content

Commit ba9fc35

Browse files
committed
Make expires_in u32 and (on regenerate) not default to the same as last time
1 parent 52c04c1 commit ba9fc35

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

crates/handlers/src/admin/v1/personal_sessions/add.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub struct Request {
6868

6969
/// Token expiry time in seconds.
7070
/// If not set, the token won't expire.
71-
expires_in: Option<u64>,
71+
expires_in: Option<u32>,
7272
}
7373

7474
pub fn doc(operation: TransformOperation) -> TransformOperation {

crates/handlers/src/admin/v1/personal_sessions/regenerate.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ impl IntoResponse for RouteError {
6464
#[serde(rename = "RegeneratePersonalSessionRequest")]
6565
pub struct Request {
6666
/// Token expiry time in seconds.
67-
/// If not set, the token will default to the same lifetime as when
68-
/// originally issued.
69-
expires_in: Option<u64>,
67+
/// If not set, the token won't expire.
68+
expires_in: Option<u32>,
7069
}
7170

7271
pub fn doc(operation: TransformOperation) -> TransformOperation {
@@ -132,17 +131,6 @@ pub async fn handler(
132131
return Err(RouteError::SessionNotValid);
133132
};
134133

135-
// Calculate the expiry time of the new token, defaulting
136-
// to the token's previous lifetime
137-
let expires_in = params
138-
.expires_in
139-
.map(|exp_in| Duration::seconds(i64::try_from(exp_in).unwrap_or(i64::MAX)))
140-
.or_else(|| {
141-
old_token
142-
.expires_at
143-
.map(|exp_at| exp_at - old_token.created_at)
144-
});
145-
146134
repo.personal_access_token()
147135
.revoke(&clock, old_token)
148136
.await?;
@@ -151,7 +139,15 @@ pub async fn handler(
151139
let access_token_string = TokenType::PersonalAccessToken.generate(&mut rng);
152140
let access_token = repo
153141
.personal_access_token()
154-
.add(&mut rng, &clock, &session, &access_token_string, expires_in)
142+
.add(
143+
&mut rng,
144+
&clock,
145+
&session,
146+
&access_token_string,
147+
params
148+
.expires_in
149+
.map(|exp_in| Duration::seconds(i64::from(exp_in))),
150+
)
155151
.await?;
156152

157153
repo.save().await?;

0 commit comments

Comments
 (0)