Comments (3)
Suppose I log in to Google and get redirected to a callback URL where I update my user information in the database using Node. How will my front end know whether the login was successful?
That would depend on your authorization model - if redirecting the successful response from the backend confirms a successful login.
To make this easier I would recommend the Google Identity Services JavaScript library for the frontend:
Further reading:
- https://developers.google.com/identity/oauth2/web/guides/choose-authorization-model
- https://developers.google.com/identity/oauth2/web/guides/use-code-model#preventing_csrf_attacks
from google-auth-library-nodejs.
How to use nodejs api of google auth in axios fetch using API URL directly on anchor tag is not safe and fetching this using axios is not working as expected
I do not understand this question, perhaps these resources can be of assistance:
- https://github.com/googleapis/google-auth-library-nodejs?tab=readme-ov-file#a-complete-oauth2-example
- https://github.com/googleapis/google-auth-library-nodejs/blob/409da97d633268ae6402cdbb22166a4644c29860/samples/puppeteer/oauth2-test.js
- https://developers.google.com/identity/oauth2/web/guides/overview
from google-auth-library-nodejs.
Hi @danielbankhead,
Suppose I log in to Google and get redirected to a callback URL where I update my user information in the database using Node. How will my front end know whether the login was successful? Should I call an API to check whether the user was created successfully?
My approach
- Upon receiving data on the callback route, the server will first update the database. Then, it will set an encrypted data cookie on the frontend using "res.cookie" and redirect to the frontend URL using "res.redirect(frontend)".
- The frontend will check if the URL contains something like "google auth success". If it does, the frontend will fetch an API that contains the cookie saved by the server to retrieve the data of the Google logged-in user.
- The server will verify the encrypted data that comes with the API request. If the encrypted data is verified, the server will return an auth token (with a maximum age of 15 days, which can also help to refresh the access token) and an access token (with a maximum age of 1 hour).
Many thanks
Ashish
from google-auth-library-nodejs.
Related Issues (20)
- Occasional timeout when requesting Google ID Token Verify HOT 2
- Allow passing in AWS credentials instead of only using environment variables HOT 2
- Type definitions in google-auth-library >= 9.5.0 incompatible with client libraries HOT 3
- GaxiosError: Failed to retrieve verification certificates: request to https://www.googleapis.com/oauth2/v1/certs failed HOT 1
- refactor!: Move Base `AuthClient` Types to `authclient.ts` HOT 2
- samples for external-account: should acquire ADC for url-sourced creds failed HOT 2
- samples for external-account: should acquire ADC for AWS creds failed HOT 2
- Client args type error for GCP HOT 4
- samples for external-account: should acquire ADC for file-sourced creds failed HOT 2
- Facing timeout issue for https://www.googleapis.com/oauth2/v4/token while generating oauth access token using google-auth-library HOT 7
- Ht
- G
- How to handle google auth with react and node js api HOT 1
- ToC for Reference Documentation is broken HOT 1
- error: FetchError: request to https://www.googleapis.com/oauth2/v1/certs failed, reason: connect ETIMEDOUT 142.251.43.10:443 HOT 1
- error: FetchError: request to https://oauth2.googleapis.com/token failed, reason: connect ETIMEDOUT 172.217.160.74:443 HOT 1
- use getToken error: FetchError: request to https://oauth2.googleapis.com/token failed, reason: connect ETIMEDOUT 172.217.160.74:443
- exchanging code for tokens: GaxiosError: request to https://oauth2.googleapis.com/token failed,
- oauth2client.d.ts references non existant type "QueryStringInput" in querystring.d.ts HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-auth-library-nodejs.