Skip to main content
Social auth is a two-step process: you redirect the user to the provider login page, then exchange a short-lived code for a refresh token once they return.

Setup (one-time, in the dashboard)

Before using these endpoints you need to configure the OAuth provider in your project:
  1. Go to Project Settings and add your frontend URL as the Site URL (e.g., https://myapp.com).
  2. Go to Auth → Social Auth and select GitHub or Google.
  3. Copy the read-only Callback URL shown by urBackend (e.g., https://api.ub.bitbros.in/api/userAuth/social/github/callback).
  4. Register that callback URL in the provider’s OAuth app settings (GitHub: Developer Settings → OAuth Apps; Google: Cloud Console → Credentials).
  5. Paste the provider’s Client ID and Client Secret into urBackend and enable the provider.

Step 1 — Start the OAuth Flow

GET /api/userAuth/social/:provider/start

Redirects the user’s browser to the provider login page. Because this is a browser redirect (not a fetch call), pass your API key as a query parameter.
string
required
OAuth provider name. Accepted values: github, google.
string
required
Your pk_live_… key. Can also be sent as a header if you are making a non-redirect request.
Response: HTTP redirect to the provider login page. The browser handles this automatically.
After the user authenticates with the provider, urBackend redirects them to:
The access token is placed in the URL fragment (#...) intentionally. Fragments are never sent to servers in HTTP requests, which prevents token leakage through referrer headers or server logs.

Step 2 — Exchange rtCode for a Refresh Token

POST /api/userAuth/social/exchange

Your /auth/callback page must call this endpoint to convert the one-time rtCode into a long-lived refresh token.
rtCode is one-time use and expires in 60 seconds. Exchange it immediately when your callback page loads.

Required Headers

Request Body

string
required
The access token extracted from the URL fragment (#token=…).
string
required
The one-time exchange code from the query string (?rtCode=…).

Response Fields

boolean
true when the exchange succeeded.
object
string
Human-readable status message.

Full Callback Page Example

Success Response

Error Responses