-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5ed90c
commit 0ec9055
Showing
3 changed files
with
40 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { AppsRepository } from "@/modules/apps/apps.repository"; | ||
import { Injectable, Logger, NotFoundException } from "@nestjs/common"; | ||
import { google } from "googleapis"; | ||
import { z } from "zod"; | ||
|
||
@Injectable() | ||
export class GcalService { | ||
private logger = new Logger("GcalService"); | ||
|
||
constructor(private readonly appsRepository: AppsRepository) {} | ||
|
||
async getOAuthClient(redirectUri: string) { | ||
this.logger.log("Getting Google Calendar OAuth Client"); | ||
const app = await this.appsRepository.getAppBySlug("google-calendar"); | ||
|
||
if (!app) { | ||
throw new NotFoundException(); | ||
} | ||
|
||
const { client_id, client_secret } = z | ||
.object({ client_id: z.string(), client_secret: z.string() }) | ||
.parse(app.keys); | ||
|
||
const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirectUri); | ||
return oAuth2Client; | ||
} | ||
} |