Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# INTRO

Front-page for Sign-in: https://zmiftah.github.io/google-auth-page/

For verify: `node verify.js`

For getting token: `node verify-browser.js`

# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Expand Down
44 changes: 44 additions & 0 deletions verify-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

import { OAuth2Client } from 'google-auth-library';
import readline from 'readline';
import dotenv from 'dotenv';

dotenv.config();

const CLIENT_ID = process.env.GOOGLE_CLIENT_ID;
const CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET;
const REDIRECT_URI = 'http://localhost';

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

async function main() {
const oAuth2Client = new OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);

const authUrl = oAuth2Client.generateAuthUrl({
access_type: 'offline',
scope: ['openid', 'email', 'profile'],
});

console.log('🔐 Open this URL in your browser to authenticate:');
console.log(authUrl);

rl.question('\n📥 Paste the code here: ', async (code) => {
try {
const { tokens } = await oAuth2Client.getToken(code);
oAuth2Client.setCredentials(tokens);

const idToken = tokens.id_token;
console.log('\n✓ Your Google ID Token (JWT):\n');
console.log(idToken);
} catch (err) {
console.error('❌ Error retrieving token:', err);
} finally {
rl.close();
}
});
}

main();