@@ -8,32 +8,20 @@ import { OAuthClientRepository } from "@/modules/oauth-clients/oauth-client.repo
88import { OAuthFlowService } from "@/modules/oauth-clients/services/oauth-flow.service" ;
99import { ProfilesRepository } from "@/modules/profiles/profiles.repository" ;
1010import { TokensRepository } from "@/modules/tokens/tokens.repository" ;
11+ import { TokensService } from "@/modules/tokens/tokens.service" ;
1112import { UsersService } from "@/modules/users/services/users.service" ;
1213import { UserWithProfile , UsersRepository } from "@/modules/users/users.repository" ;
13- import {
14- HttpException ,
15- Injectable ,
16- InternalServerErrorException ,
17- UnauthorizedException ,
18- } from "@nestjs/common" ;
14+ import { Injectable , InternalServerErrorException , UnauthorizedException } from "@nestjs/common" ;
1915import { Logger } from "@nestjs/common" ;
2016import { ConfigService } from "@nestjs/config" ;
2117import { PassportStrategy } from "@nestjs/passport" ;
2218import type { Request } from "express" ;
23- import * as jwt from "jsonwebtoken" ;
2419import { getToken } from "next-auth/jwt" ;
2520
2621import { INVALID_ACCESS_TOKEN , X_CAL_CLIENT_ID , X_CAL_SECRET_KEY } from "@calcom/platform-constants" ;
2722
2823import type { AllowedAuthMethod } from "../../decorators/api-auth-guard-only-allow.decorator" ;
2924
30- interface OAuthTokenPayload {
31- userId ?: number ;
32- teamId ?: number ;
33- scope : string [ ] ;
34- token_type : string ;
35- }
36-
3725export type ApiAuthGuardUser = UserWithProfile & { isSystemAdmin : boolean } ;
3826export type ApiAuthGuardRequest = Request & {
3927 authMethod : AuthMethods ;
@@ -53,6 +41,7 @@ export class ApiAuthStrategy extends PassportStrategy(BaseStrategy, "api-auth")
5341 private readonly config : ConfigService ,
5442 private readonly oauthFlowService : OAuthFlowService ,
5543 private readonly tokensRepository : TokensRepository ,
44+ private readonly tokensService : TokensService ,
5645 private readonly userRepository : UsersRepository ,
5746 private readonly apiKeyRepository : ApiKeysRepository ,
5847 private readonly oauthRepository : OAuthClientRepository ,
@@ -323,20 +312,8 @@ export class ApiAuthStrategy extends PassportStrategy(BaseStrategy, "api-auth")
323312 token : string ,
324313 request : ApiAuthGuardRequest
325314 ) : Promise < { success : true ; data : UserWithProfile } | { success : false } > {
326- // Removed requiredScopes parameter
327- const encryptionKey = this . config . get < string > ( "CALENDSO_ENCRYPTION_KEY" ) ;
328- if ( ! encryptionKey ) {
329- throw new InternalServerErrorException ( "CALENDSO_ENCRYPTION_KEY environment variable is not set." ) ;
330- }
331-
332- let decodedToken : OAuthTokenPayload ;
333- try {
334- decodedToken = jwt . verify ( token , encryptionKey ) as OAuthTokenPayload ;
335- } catch ( e ) {
336- return { success : false } ;
337- }
338-
339- if ( ! decodedToken || decodedToken . token_type !== "Access Token" ) {
315+ const decodedToken = this . tokensService . getDecodedThirdPartyAccessToken ( token ) ;
316+ if ( ! decodedToken ) {
340317 return { success : false } ;
341318 }
342319
0 commit comments