Very rudimentary development version of zoom auth #2

This commit is contained in:
nicolas 2021-06-11 02:03:48 +02:00
parent b5733716de
commit a2f1462f10

View file

@ -1,4 +1,6 @@
import type {NextApiRequest, NextApiResponse} from 'next'; 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; const client_id = process.env.ZOOM_CLIENT_ID;
const client_secret = process.env.ZOOM_CLIENT_SECRET; const client_secret = process.env.ZOOM_CLIENT_SECRET;
@ -7,28 +9,45 @@ const scopes = ['meeting:write:admin', 'meeting:write', 'meeting:read:admin', 'm
export default async function handler(req: NextApiRequest, res: NextApiResponse) { export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { code } = req.query; const { code } = req.query;
console.log(code);
// Check that user is authenticated // Check that user is authenticated
/*const session = await getSession({req: req}); const session = await getSession({req: req});
if (!session) { res.status(401).json({message: 'You must be logged in to do this'}); return; } if (!session) { res.status(401).json({message: 'You must be logged in to do this'}); return; }
// TODO Init some sort of oAuth client here 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;
const authHeader = 'Basic ' + Buffer.from(client_id + ':' + client_secret).toString('base64');
// Convert to token // Convert to token
/*return new Promise( (resolve, reject) => oAuth2Client.getToken(code, async (err, token) => { const options = {
if (err) return console.error('Error retrieving access token', err); method: 'POST',
qs: {
grant_type: 'authorization_code',
code,
redirect_uri: authUrl
},
headers: {
Authorization: authHeader
}
};
const credential = await prisma.credential.create({ return new Promise( (resolve, reject) => fetch('https://zoom.us/oauth/token', options)
data: { .then((res) => res.text())
type: 'google_calendar', .then((text) => {
key: token, console.log(text);
userId: session.user.id const credential = await prisma.credential.create({
} data: {
}); type: 'google_calendar',
key: 'lel',
userId: session.user.id
}
});
res.redirect('/integrations'); res.redirect('/integrations');
resolve(); resolve();
}));*/ })
res.redirect('/integrations'); .catch((err) => {
if (err) throw new Error(err);
}));
} }