https://api.ub.bitbros.in
How the flow works
<your-site>/auth/callback with an access token in the URL fragment and a short-lived exchange code in the query string.
Dashboard setup (one time)
Set your site URL
Go to Project Settings in the urBackend dashboard and enter your frontend URL (e.g.,
https://myapp.com). urBackend uses this as the base for the post-login redirect.Open Social Auth settings
Go to Auth → Social Auth and select the provider you want to configure (GitHub or Google).
Copy the callback URL
urBackend displays a read-only callback URL for the selected provider:Copy this URL — you will register it with the provider in the next step.
Register the callback URL with the provider
Paste the callback URL into the provider’s developer console:
- GitHub: Settings → Developer settings → OAuth Apps → New OAuth App
- Google: Google Cloud Console → APIs & Services → Credentials → Create OAuth Client
Frontend implementation
1. Add login buttons
When a user clicks “Login with GitHub” or “Login with Google”, redirect their browser to urBackend’s start endpoint. Pass your publishable key as a query parameter (since this is a browser redirect, not afetch call).
2. Create the callback page
You must create a page at/auth/callback in your frontend. After the provider login completes, urBackend redirects the user here with tokens in the URL.
The callback page should:
- Check for an error in the query string
- Extract
tokenfrom the URL fragment andrtCodefrom the query string - Exchange
rtCodefor a refresh token by calling/api/userAuth/social/exchange - Store the tokens and redirect to your app
What urBackend sends to your callback URL
After a successful provider login, urBackend redirects to:| Parameter | Location | Description |
|---|---|---|
token | URL fragment (#) | Access token (JWT) for API calls |
rtCode | Query string | One-time code to exchange for a refresh token |
provider | Query string | github or google |
projectId | Query string | Your urBackend project ID |
userId | Query string | The user’s ID in your database |
isNewUser | Query string | true if the account was just created |
linkedByEmail | Query string | true if an existing account was linked by email |
error | Query string | Error message (only present on failure) |
The access token is placed in the URL fragment (
#) intentionally. Fragments are never sent to servers in HTTP requests, which prevents the token from leaking through referrer headers or server logs.Exchange endpoint
Endpoint:POST /api/userAuth/social/exchange
Headers:
Complete flow summary
| Step | What happens | Who does it |
|---|---|---|
| 1 | User clicks “Login with GitHub” | Your frontend |
| 2 | Browser redirects to /api/userAuth/social/github/start | Your frontend |
| 3 | urBackend redirects to GitHub login page | urBackend |
| 4 | User logs in on GitHub | User |
| 5 | GitHub redirects to urBackend callback | GitHub |
| 6 | urBackend creates or links the user, generates tokens | urBackend |
| 7 | urBackend redirects to <your-site>/auth/callback?rtCode=...#token=... | urBackend |
| 8 | Callback page extracts token and rtCode from URL | Your frontend |
| 9 | Callback page calls /api/userAuth/social/exchange with both | Your frontend |
| 10 | urBackend returns refreshToken | urBackend |
| 11 | App stores tokens and redirects to dashboard | Your frontend |
Account linking
If a user signs in with a social provider and their provider account has a verified email that matches an existing urBackend user, the accounts are automatically linked. ThelinkedByEmail parameter in the callback URL will be true in this case.
New users created via social auth receive an internally generated hashed password to satisfy the users collection contract. They can set a real password later using the change-password endpoint.