diff --git a/README.md b/README.md index 7059a96..c1773da 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/verify-browser.js b/verify-browser.js new file mode 100644 index 0000000..d3a8404 --- /dev/null +++ b/verify-browser.js @@ -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();