Add social login with Google or GitHub
Register your app with a provider, paste its credentials into the Console, and let people sign in with an account they already have.
Social login lets people sign in with an account they already have. Your project supports Google and GitHub. You create an OAuth app with the provider, then give its credentials to your project.
Set up a provider
- At the provider (for example Google Cloud Console > APIs & Services > Credentials, or GitHub's developer settings), create an OAuth app.
- Register your app's callback URL with the provider. This is the page in your app that receives the user after they approve, for example
https://app.example.com/callback. - In the Console, open Authentication > Settings > Social login.
- Find the provider's card. Paste the Client ID and Client secret.
- Choose Save credentials. The card changes from Not configured to Configured.
A Google client ID ends in .apps.googleusercontent.com. The Console checks this and tells you if it does not match.
The secret is stored encrypted and is never shown again. To change it, enter new values and choose Replace credentials. To turn a provider off, choose Remove. Users will no longer be able to use it.
Wire it into your app
The sign-in has two steps. With the TypeScript SDK:
// 1. Ask for the provider's sign-in address
const { authorize_url, state } = await pgb.auth.oauthStart({
provider: "google",
redirectUri: "https://app.example.com/callback",
});
// send the browser to authorize_url
// 2. On your callback page, finish the sign-in
const result = await pgb.auth.oauthCallback({
provider: "google",
code, // from the address your app was opened with
state,
redirectUri: "https://app.example.com/callback",
});
The result contains the user and a session, just like a password sign-in. The Python, Go and Rust SDKs have the same two calls (oauth_start, oauth_callback).
To see which providers are on, call pgb.auth.getSettings(), so your sign-in page can show only the buttons that will work.
Good to know
- The
statevalue ties the two steps together and is valid for ten minutes. - The callback step is rate limited per address.
- Social login is separate from the Sign-in methods tab. You can use both side by side.
More guides in Console: authentication
Authentication in your project: users, settings and the Playground
What built-in authentication gives your app, and a tour of the Authentication page in the Console.
Choose sign-in methods and password rules
Turn sign-in methods on or off, set password rules and session lifetimes, and decide whether email must be verified.
Email verification and password reset
How confirmation emails and password resets work, and how to wire the links into your app.
Customize the emails your users receive
Edit the subject, wording, sender name and button colour of sign-in, verification and reset emails, with a live preview.
Send authentication emails from your own domain
Add and verify a sending domain so sign-in, verification and reset emails show your brand and address.
Two-factor sign-in for your app's users
How your users can protect their accounts with an authenticator app, and how you test and reset it.