Skip to content

Commit 4d0bf62

Browse files
supalarryPeerRichThyMinimalDev
authoredJun 13, 2024
chore: return accessTokenExpiresAt in oauth exchange and refresh (#15425)
Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com>
1 parent 70b4e3a commit 4d0bf62

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed
 

‎apps/api/v2/src/modules/oauth-clients/controllers/oauth-flow/oauth-flow.controller.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,18 @@ export class OAuthFlowController {
118118
throw new BadRequestException("Missing 'Bearer' Authorization header.");
119119
}
120120

121-
const { accessToken, refreshToken } = await this.oAuthFlowService.exchangeAuthorizationToken(
122-
authorizeEndpointCode,
123-
clientId,
124-
body.clientSecret
125-
);
121+
const { accessToken, refreshToken, accessTokenExpiresAt } =
122+
await this.oAuthFlowService.exchangeAuthorizationToken(
123+
authorizeEndpointCode,
124+
clientId,
125+
body.clientSecret
126+
);
126127

127128
return {
128129
status: SUCCESS_STATUS,
129130
data: {
130131
accessToken,
132+
accessTokenExpiresAt: accessTokenExpiresAt.valueOf(),
131133
refreshToken,
132134
},
133135
};
@@ -141,7 +143,7 @@ export class OAuthFlowController {
141143
@Headers(X_CAL_SECRET_KEY) secretKey: string,
142144
@Body() body: RefreshTokenInput
143145
): Promise<KeysResponseDto> {
144-
const { accessToken, refreshToken } = await this.oAuthFlowService.refreshToken(
146+
const { accessToken, refreshToken, accessTokenExpiresAt } = await this.oAuthFlowService.refreshToken(
145147
clientId,
146148
secretKey,
147149
body.refreshToken
@@ -151,6 +153,7 @@ export class OAuthFlowController {
151153
status: SUCCESS_STATUS,
152154
data: {
153155
accessToken: accessToken,
156+
accessTokenExpiresAt: accessTokenExpiresAt.valueOf(),
154157
refreshToken: refreshToken,
155158
},
156159
};

‎apps/api/v2/src/modules/oauth-clients/controllers/oauth-flow/responses/KeysResponse.dto.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ApiProperty } from "@nestjs/swagger";
22
import { Type } from "class-transformer";
3-
import { ValidateNested, IsEnum, IsString, IsNotEmptyObject } from "class-validator";
3+
import { ValidateNested, IsEnum, IsString, IsNotEmptyObject, IsNumber } from "class-validator";
44

55
import { SUCCESS_STATUS, ERROR_STATUS } from "@calcom/platform-constants";
66

@@ -16,6 +16,9 @@ class KeysDto {
1616
})
1717
@IsString()
1818
refreshToken!: string;
19+
20+
@IsNumber()
21+
accessTokenExpiresAt!: number;
1922
}
2023

2124
export class KeysResponseDto {

‎apps/api/v2/src/modules/oauth-clients/services/oauth-flow.service.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class OAuthFlowService {
103103
tokenId: string,
104104
clientId: string,
105105
clientSecret: string
106-
): Promise<{ accessToken: string; refreshToken: string }> {
106+
): Promise<{ accessToken: string; refreshToken: string; accessTokenExpiresAt: Date }> {
107107
const oauthClient = await this.oAuthClientRepository.getOAuthClientWithAuthTokens(
108108
tokenId,
109109
clientId,
@@ -120,7 +120,7 @@ export class OAuthFlowService {
120120
throw new BadRequestException("Invalid Authorization Token.");
121121
}
122122

123-
const { accessToken, refreshToken } = await this.tokensRepository.createOAuthTokens(
123+
const { accessToken, refreshToken, accessTokenExpiresAt } = await this.tokensRepository.createOAuthTokens(
124124
clientId,
125125
authorizationToken.owner.id
126126
);
@@ -129,6 +129,7 @@ export class OAuthFlowService {
129129

130130
return {
131131
accessToken,
132+
accessTokenExpiresAt,
132133
refreshToken,
133134
};
134135
}
@@ -158,6 +159,7 @@ export class OAuthFlowService {
158159

159160
return {
160161
accessToken: accessToken.secret,
162+
accessTokenExpiresAt: accessToken.expiresAt,
161163
refreshToken: refreshToken.secret,
162164
};
163165
}

0 commit comments

Comments
 (0)
Please sign in to comment.