Simplify google-auth-library

Simplify google-auth-library

google-auth-simplify is a npm package that simplifies google-auth-library in 3 steps:

  1. Generate auth URL

  2. Get auth token

  3. Get user info

So basically, it's just a wrapper that wraps all complex parts of google-auth-library. you can say it's a facade for google-auth-library.

Talk is cheap. Show me the code

const express = require('express');
const { GoogleAuth } = require('google-auth-simplify');

const app = express();

const googleAuth = new GoogleAuth({
  clientId: GOOGLE_CLIENT_ID,
  clientSecret: GOOGLE_CLIENT_SECRET,
  redirectURI: GOOGLE_REDIRECT_URI,
});

app.get('/login', (req, res) => {
  const authUrl = googleAuth.generateAuthUrl();// STEP 1
  res.redirect(authUrl);
});

app.get('/google_redirect_url', async (req, res) => {
  const code = req.query['code'];
  const authToken = await googleAuth.getAuthToken(code);// STEP 2
  const profile = await googleAuth.getUserInfo(authToken);// STEP 3
  res.json({profile});
});

app.listen(3000, () => {
  console.log('server started:.:.:');
});

I think it's easy to understand.

have any questions? let me know in the comments :D

BTW here is the repo: google-auth-simplify

Did you find this article valuable?

Support saud chougle by becoming a sponsor. Any amount is appreciated!