Very rudimentary development version of zoom auth

pull/277/head
nicolas 2021-06-11 01:37:58 +02:00
parent b7b644998a
commit b5733716de
3 changed files with 67 additions and 0 deletions

View File

@ -9,6 +9,10 @@ NEXT_PUBLIC_TELEMETRY_KEY=js.2pvs2bbpqq1zxna97wcml.oi2jzirnbj1ev4tc57c5r
MS_GRAPH_CLIENT_ID=
MS_GRAPH_CLIENT_SECRET=
# Used for the Zoom integration
ZOOM_CLIENT_ID=
ZOOM_CLIENT_SECRET=
# E-mail settings
# Calendso uses nodemailer (@see https://nodemailer.com/about/) to provide email sending. As such we are trying to

View File

@ -0,0 +1,29 @@
import type {NextApiRequest, NextApiResponse} from 'next';
import {getSession} from 'next-auth/client';
import prisma from '../../../../lib/prisma';
const client_id = process.env.ZOOM_CLIENT_ID;
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === 'GET') {
// Check that user is authenticated
const session = await getSession({req: req});
if (!session) { res.status(401).json({message: 'You must be logged in to do this'}); return; }
// Get user
const user = await prisma.user.findFirst({
where: {
email: session.user.email,
},
select: {
id: true
}
});
const redirectUri = encodeURI(process.env.BASE_URL + '/api/integrations/zoom/callback');
const authUrl = 'https://zoom.us/oauth/authorize?response_type=code&client_id=' + client_id + '&redirect_uri=' + redirectUri;
res.status(200).json({url: authUrl});
}
}

View File

@ -0,0 +1,34 @@
import type {NextApiRequest, NextApiResponse} from 'next';
const client_id = process.env.ZOOM_CLIENT_ID;
const client_secret = process.env.ZOOM_CLIENT_SECRET;
const scopes = ['meeting:write:admin', 'meeting:write', 'meeting:read:admin', 'meeting:read'];
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { code } = req.query;
console.log(code);
// Check that user is authenticated
/*const session = await getSession({req: req});
if (!session) { res.status(401).json({message: 'You must be logged in to do this'}); return; }
// TODO Init some sort of oAuth client here
// Convert to token
/*return new Promise( (resolve, reject) => oAuth2Client.getToken(code, async (err, token) => {
if (err) return console.error('Error retrieving access token', err);
const credential = await prisma.credential.create({
data: {
type: 'google_calendar',
key: token,
userId: session.user.id
}
});
res.redirect('/integrations');
resolve();
}));*/
res.redirect('/integrations');
}