Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { OAuth2Client } = require("google-auth-library");
- const Mutations = {
- async auth(parent, ctx, info) {
- const googleConfig = {
- clientId: process.env.GOOGLE_CLIENT_ID, // e.g. asdfghjkljhgfdsghjk.apps.googleusercontent.com
- clientSecret: process.env.GOOGLE_CLIENT_SECRET, // e.g. _ASDFA%DFASDFASDFASD#FAD-
- redirect: process.env.GOOGLE_REDIRECT_URL // this must match your google api settings
- };
- const defaultScope = [
- "https://www.googleapis.com/auth/userinfo.profile"
- ];
- const oAuth2Client = new OAuth2Client(
- googleConfig.clientId,
- googleConfig.clientSecret,
- googleConfig.redirect
- );
- const authorizeUrl = await oAuth2Client.generateAuthUrl({
- access_type: "offline",
- prompt: "consent",
- scope: defaultScope,
- });
- /**The only thing I can think of doing differently is to somehow**/
- /**open the URL in the mutation and wait for the redirect.**/
- /**That or use Express to handle the callback and/or use it**/
- /**to pipe the redirect back to this mutation**/
- return authorizeUrl;
- },
- };
- module.exports = Mutations
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement