-
Notifications
You must be signed in to change notification settings - Fork 12.1k
feat: Proton Calendar integration via read-only ICS feed #28230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,3 @@ | ||
| Check availability from your Proton Calendar using shareable ICS feed URLs. No OAuth or API keys required — just paste your calendar's ICS link and Cal.com will check it for scheduling conflicts. | ||
|
|
||
| Proton Calendar is a privacy-focused calendar from the makers of Proton Mail. |
This file contains hidden or 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,90 @@ | ||
| import type { NextApiRequest, NextApiResponse } from "next"; | ||
|
|
||
| import { symmetricEncrypt } from "@calcom/lib/crypto"; | ||
| import logger from "@calcom/lib/logger"; | ||
| import prisma from "@calcom/prisma"; | ||
|
|
||
| import getInstalledAppPath from "../../_utils/getInstalledAppPath"; | ||
| import appConfig from "../config.json"; | ||
| import { BuildCalendarService } from "../lib"; | ||
|
|
||
| const ALLOWED_HOSTNAMES = ["calendar.proton.me", "calendar.protonmail.com"]; | ||
|
|
||
| function isAllowedUrl(url: string): boolean { | ||
| try { | ||
| const parsed = new URL(url); | ||
| if (parsed.protocol !== "https:") return false; | ||
| return ALLOWED_HOSTNAMES.some((host) => parsed.hostname === host || parsed.hostname.endsWith(`.${host}`)); | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| export default async function handler(req: NextApiRequest, res: NextApiResponse) { | ||
| if (req.method === "POST") { | ||
| const { urls } = req.body; | ||
|
|
||
| if (!Array.isArray(urls) || urls.length === 0) { | ||
| return res.status(400).json({ message: "At least one ICS feed URL is required" }); | ||
| } | ||
|
|
||
| // Validate all URLs are from Proton domains | ||
| for (const url of urls) { | ||
| if (!isAllowedUrl(url)) { | ||
| return res.status(400).json({ | ||
| message: `Invalid URL: only HTTPS URLs from ${ALLOWED_HOSTNAMES.join(" or ")} are accepted`, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // Get user | ||
| const user = await prisma.user.findFirstOrThrow({ | ||
| where: { | ||
| id: req.session?.user?.id, | ||
| }, | ||
| select: { | ||
| id: true, | ||
| email: true, | ||
| }, | ||
| }); | ||
|
|
||
| const data = { | ||
| type: appConfig.type, | ||
| key: symmetricEncrypt(JSON.stringify({ urls }), process.env.CALENDSO_ENCRYPTION_KEY || ""), | ||
| userId: user.id, | ||
| teamId: null, | ||
| appId: appConfig.slug, | ||
| invalid: false, | ||
| delegationCredentialId: null, | ||
| }; | ||
|
|
||
| try { | ||
| const dav = BuildCalendarService({ | ||
| id: 0, | ||
| ...data, | ||
| user: { email: user.email }, | ||
| encryptedKey: null, | ||
| }); | ||
| const listedCals = await dav.listCalendars(); | ||
|
|
||
| if (listedCals.length !== urls.length) { | ||
| throw new Error(`Listed cals and URLs mismatch: ${listedCals.length} vs. ${urls.length}`); | ||
| } | ||
|
|
||
| await prisma.credential.create({ | ||
| data, | ||
| }); | ||
| } catch (e) { | ||
| logger.error("Could not add Proton Calendar feeds", e); | ||
| return res.status(500).json({ message: "Could not add Proton Calendar feeds" }); | ||
| } | ||
|
|
||
| return res | ||
| .status(200) | ||
| .json({ url: getInstalledAppPath({ variant: "calendar", slug: "proton-calendar" }) }); | ||
| } | ||
|
|
||
| if (req.method === "GET") { | ||
| return res.status(200).json({ url: "/apps/proton-calendar/setup" }); | ||
| } | ||
| } | ||
This file contains hidden or 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 @@ | ||
| export { default as add } from "./add"; |
This file contains hidden or 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,15 @@ | ||
| { | ||
| "name": "Proton Calendar", | ||
| "title": "Proton Calendar", | ||
| "slug": "proton-calendar", | ||
| "dirName": "protoncalendar", | ||
| "type": "proton-calendar_calendar", | ||
| "logo": "icon.svg", | ||
| "variant": "calendar", | ||
| "categories": ["calendar"], | ||
| "publisher": "Cal.com, Inc.", | ||
| "email": "help@cal.com", | ||
| "description": "Check availability from Proton Calendar using ICS feed URLs. Proton Calendar is a privacy-focused calendar from Proton.", | ||
| "isTemplate": false, | ||
| "__createdUsingCli": true | ||
| } |
This file contains hidden or 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,2 @@ | ||
| export * as api from "./api"; | ||
| export * as lib from "./lib"; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Proton URL validation logic (
ALLOWED_HOSTNAMES+isAllowedUrl) is duplicated here and again inlib/CalendarService.ts(and separately in tests). This duplication risks the API accepting/rejecting different URLs than the service if one copy changes. Consider moving this into a shared utility (e.g.lib/urlValidation.ts) and importing it from both places (and tests).