Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. const { OAuth2Client } = require("google-auth-library");
  2.  
  3. const Mutations = {
  4. async auth(parent, ctx, info) {
  5. const googleConfig = {
  6. clientId: process.env.GOOGLE_CLIENT_ID, // e.g. asdfghjkljhgfdsghjk.apps.googleusercontent.com
  7. clientSecret: process.env.GOOGLE_CLIENT_SECRET, // e.g. _ASDFA%DFASDFASDFASD#FAD-
  8. redirect: process.env.GOOGLE_REDIRECT_URL // this must match your google api settings
  9. };
  10.  
  11. const defaultScope = [
  12. "https://www.googleapis.com/auth/userinfo.profile"
  13. ];
  14.  
  15. const oAuth2Client = new OAuth2Client(
  16. googleConfig.clientId,
  17. googleConfig.clientSecret,
  18. googleConfig.redirect
  19. );
  20.  
  21. const authorizeUrl = await oAuth2Client.generateAuthUrl({
  22. access_type: "offline",
  23. prompt: "consent",
  24. scope: defaultScope,
  25. });
  26.  
  27. /**The only thing I can think of doing differently is to somehow**/
  28. /**open the URL in the mutation and wait for the redirect.**/
  29. /**That or use Express to handle the callback and/or use it**/
  30. /**to pipe the redirect back to this mutation**/
  31.  
  32. return authorizeUrl;
  33. },
  34. };
  35.  
  36. module.exports = Mutations
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement