Skip to main content
urBackend supports OAuth sign-in via GitHub and Google. Once configured, your users can authenticate without creating a password — urBackend creates or links their account automatically. Base URL: https://api.ub.bitbros.in

How the flow works

After a successful login, urBackend redirects the user to <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)

1

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.
2

Open Social Auth settings

Go to Auth → Social Auth and select the provider you want to configure (GitHub or Google).
3

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.
4

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
5

Paste credentials and enable

Copy the Client ID and Client Secret from the provider console, paste them into the urBackend Social Auth form, and toggle the provider on.

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 a fetch 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:
  1. Check for an error in the query string
  2. Extract token from the URL fragment and rtCode from the query string
  3. Exchange rtCode for a refresh token by calling /api/userAuth/social/exchange
  4. Store the tokens and redirect to your app

What urBackend sends to your callback URL

After a successful provider login, urBackend redirects to:
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:
Request body:
Success response:
rtCode expires after 60 seconds and is one-time use. Exchange it immediately after the redirect. If it has expired or been used, you will receive "Invalid or expired refresh token exchange code" and the user will need to log in again.

Complete flow summary

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. The linkedByEmail 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.