1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-08 04:33:38 +00:00

PM-20532 - SendAccessToken model first draft

This commit is contained in:
Jared Snider
2025-05-21 15:29:04 -04:00
parent b9a8c32dce
commit 8cbd75caef

View File

@@ -0,0 +1,32 @@
export class SendAccessToken {
constructor(
/**
* The access token string
*/
readonly token: string,
/**
* The time (in milliseconds since the epoch) when the token expires
*/
readonly expiresAt: number,
) {}
/**
* Builds an instance from our Identity token response data
* @param accessToken The `access_token` string
* @param expiresInSeconds The `expires_in` value (in seconds)
*/
static fromResponseData(accessToken: string, expiresInSeconds: number): SendAccessToken {
const expiresAtTimeStamp = Date.now() + expiresInSeconds * 1000;
return new SendAccessToken(accessToken, expiresAtTimeStamp);
}
/** Returns whether the send access token is expired or not */
isExpired(): boolean {
return Date.now() >= this.expiresAt;
}
/** Returns how many full seconds remain until expiry. Returns 0 if expired. */
timeUntilExpirySeconds(): number {
return Math.max(0, Math.floor((this.expiresAt - Date.now()) / 1_000));
}
}