In this post, you will learn how OAuth integrations work and specifically how you can set up a Google OAuth integration with your own Node.js application.
GitHub repository: https://github.com/tomanagle/google-oauth-tutorial
Note: This guide does not use Passport
How does OAuth work?
Setting up an OAuth integration for the first time can be a little confusing. Luckily, most OAuth integrations, including Google, follow the same flow:
- Provide the user with a link to the authentication system that includes what data you’d like the user to give your application access to (scopes), your client ID, and a redirect URL
- When the user clicks the link and grants access to your application, they will be redirected back to your application with a security code in the query string
- The security code is sent to your application’s server
- Your application’s server uses the security code, client ID, and client secret to request an access token & bearer token
- The access token and bearer token are used to fetch the user’s profile information on their behalf
- The profile information can be used to either verify them against an existing user in your…