Setup (one-time, in the dashboard)
Before using these endpoints you need to configure the OAuth provider in your project:- Go to Project Settings and add your frontend URL as the Site URL (e.g.,
https://myapp.com). - Go to Auth → Social Auth and select GitHub or Google.
- Copy the read-only Callback URL shown by urBackend (e.g.,
https://api.ub.bitbros.in/api/userAuth/social/github/callback). - Register that callback URL in the provider’s OAuth app settings (GitHub: Developer Settings → OAuth Apps; Google: Cloud Console → Credentials).
- 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.
OAuth provider name. Accepted values:
github, google.Your
pk_live_… key. Can also be sent as a header if you are making a non-redirect request.| Param | Location | Description |
|---|---|---|
token | URL fragment (#) | Access token (JWT) — use for API calls |
rtCode | Query string | One-time code to exchange for a refresh token |
provider | Query string | github or google |
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 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.
Required Headers
| Header | Value |
|---|---|
x-api-key | Your pk_live_… key |
Content-Type | application/json |
Request Body
The access token extracted from the URL fragment (
#token=…).The one-time exchange code from the query string (
?rtCode=…).Response Fields
true when the exchange succeeded.Human-readable status message.
