Very rudimentary development version of zoom auth #2
This commit is contained in:
parent
b5733716de
commit
a2f1462f10
1 changed files with 35 additions and 16 deletions
|
@ -1,4 +1,6 @@
|
|||
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_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) {
|
||||
const { code } = req.query;
|
||||
console.log(code);
|
||||
|
||||
// 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; }
|
||||
|
||||
// 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
|
||||
/*return new Promise( (resolve, reject) => oAuth2Client.getToken(code, async (err, token) => {
|
||||
if (err) return console.error('Error retrieving access token', err);
|
||||
const options = {
|
||||
method: 'POST',
|
||||
qs: {
|
||||
grant_type: 'authorization_code',
|
||||
code,
|
||||
redirect_uri: authUrl
|
||||
},
|
||||
headers: {
|
||||
Authorization: authHeader
|
||||
}
|
||||
};
|
||||
|
||||
const credential = await prisma.credential.create({
|
||||
data: {
|
||||
type: 'google_calendar',
|
||||
key: token,
|
||||
userId: session.user.id
|
||||
}
|
||||
});
|
||||
return new Promise( (resolve, reject) => fetch('https://zoom.us/oauth/token', options)
|
||||
.then((res) => res.text())
|
||||
.then((text) => {
|
||||
console.log(text);
|
||||
const credential = await prisma.credential.create({
|
||||
data: {
|
||||
type: 'google_calendar',
|
||||
key: 'lel',
|
||||
userId: session.user.id
|
||||
}
|
||||
});
|
||||
|
||||
res.redirect('/integrations');
|
||||
resolve();
|
||||
}));*/
|
||||
res.redirect('/integrations');
|
||||
res.redirect('/integrations');
|
||||
resolve();
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err) throw new Error(err);
|
||||
}));
|
||||
}
|
Loading…
Reference in a new issue