MyPayIndia Identity Documentation
Overview
MyPayIndia Identity lets your website, bot or app find out who a user is on MyPayIndia without ever seeing their credentials. You send the user to MyPayIndia, they sign in and approve your app, and MyPayIndia sends them back to you with a code that your app exchanges for their identity.
It is standard OpenID Connect (OIDC), built on OAuth 2.0. Any OIDC library works with it, you just paste in the discovery URL, your client ID and, if you have one, your client secret. Some that work well are openid-client and Auth.js for JavaScript, Authlib for Python, and league/oauth2-client for PHP.
MyPayIndia Identity is designed to replace the need to ask your user to enter your MyPayIndia credentials into your app, making it much more protected against any attack. Therefore, asking a user for their credentials is discouraged from this point on as it may raise red flags for users on why you don't use MyPayIndia Identity in your app.
Quickstart
- Register your app on the Developer Apps page. You need a verified email address to do this.
- Pick the app type. Confidential apps have a server that can keep a secret, and get a client secret shown once when you create the app. Public apps (SPAs, mobile apps, CLIs, anything whose code ends up on the user's device) have no secret.
- Add the exact URL of your callback page as a redirect URI, for example
https://example.com/callback. - Point your OIDC library at the discovery URL below with your client ID (and secret if applicable), and ask for the scopes you need.
Discovery URL
Node.js (openid-client)
import * as client from "openid-client";
const config = await client.discovery(
new URL("https://mypayindia.com"),
"your_client_id",
"your_client_secret", // leave out for public apps
);
// When the user clicks "Sign in with MyPayIndia".
// Keep verifier, state and nonce in the user's session.
const verifier = client.randomPKCECodeVerifier();
const state = client.randomState();
const nonce = client.randomNonce();
const url = client.buildAuthorizationUrl(config, {
redirect_uri: "https://example.com/callback",
scope: "openid profile",
code_challenge: await client.calculatePKCECodeChallenge(verifier),
code_challenge_method: "S256",
state,
nonce,
});
// Redirect the user to url
// On https://example.com/callback
const tokens = await client.authorizationCodeGrant(config, callbackUrl, {
pkceCodeVerifier: verifier,
expectedState: state,
expectedNonce: nonce,
});
const user = tokens.claims(); // user.sub, user.preferred_username, ... Auth.js / NextAuth provider
{
id: "mypayindia",
name: "MyPayIndia",
type: "oidc",
issuer: "https://mypayindia.com",
clientId: process.env.MYPAYINDIA_CLIENT_ID,
clientSecret: process.env.MYPAYINDIA_CLIENT_SECRET,
authorization: { params: { scope: "openid profile" } },
checks: ["pkce", "state", "nonce"],
} sub claim as the user's account ID to tell users apart. Don't use
other fields, like a username or email, as those can change.Endpoints
Most libraries read these from the discovery document, so you only need them if you are writing the requests yourself.
| Endpoint | Method | Purpose |
|---|---|---|
| /.well-known/openid-configuration | GET | Discovery document |
| /oauth/jwks | GET | Public keys for checking ID token signatures |
| /oauth/authorize | GET | Where you send the user to sign in |
| /oauth/token | POST | Exchange a code, refresh token or device code for tokens |
| /oauth/userinfo | GET POST | The user's claims for an access token |
| /oauth/revoke | POST | Revoke an access or refresh token |
| /oauth/device/code | POST | Start a device sign-in |
| /device | GET | Where users enter a device code |
Authorization Request
Send the user's browser to the authorize endpoint. On that page, the user will see what your app is asking for and can approve or deny the authorization request.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
| response_type | string required | Always code |
| client_id | string required | Your app's client ID |
| redirect_uri | string optional | Where to send the user back to. Must exactly match one of your registered redirect URIs. It can only be left out when your app has exactly one |
| scope | string required | Space separated scopes. Include openid to get an ID token |
| code_challenge | string required | PKCE challenge: the base64url encoded SHA-256 hash of a random code verifier that you keep. Required for every app, including confidential ones. |
| code_challenge_method | string required | Must be S256, plain is refused. |
| state | string optional | A random value sent back to you unchanged. Check it on your callback to protect against CSRF |
| nonce | string optional | A random value copied into the ID token. Check it to make sure the ID token belongs to this sign in request |
| prompt | string optional | login makes the user sign in again, consent shows the approval screen even if they approved
before, and none fails with an error instead of showing any page |
| max_age | integer optional | Seconds since the user last signed in to MyPayIndia. If it has been longer, they have to sign in again |
Example
https://mypayindia.com/oauth/authorize
?response_type=code
&client_id=your_client_id
&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback
&scope=openid%20profile
&state=af0ifjsldkj
&nonce=n-0S6_WzA2Mj
&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
&code_challenge_method=S256 Response
Once the user approves, they are sent back to your redirect URI with a code, your state, and iss set to https://mypayindia.com. Check that iss matches before using the code.
https://example.com/callback?code=def50200a1b2...&state=af0ifjsldkj&iss=https%3A%2F%2Fmypayindia.com If something goes wrong, they come back with an error instead:
https://example.com/callback?error=access_denied&error_description=The+resource+owner+or+authorization+server+denied+the+request.&state=af0ifjsldkj&iss=https%3A%2F%2Fmypayindia.com Errors
| Error | Description |
|---|---|
| access_denied | The user denied your app, or your app has reached its user limit (see tiers) |
| invalid_request | A parameter is missing or wrong, for example no S256 code challenge |
| invalid_scope | A requested scope doesn't exist |
| login_required | prompt=none was sent but the user has to sign in |
| consent_required | prompt=none was sent but the user hasn't approved these scopes
yet |
Token Exchange
On your callback, exchange the code for tokens. Codes work once and expire after 60 seconds. If a code is used twice, every token your app holds for that user is revoked, because a reused code means it could have been stolen.
Request Body (form encoded)
| Parameter | Type | Description |
|---|---|---|
| grant_type | string required | authorization_code |
| code | string required | The code from the callback |
| redirect_uri | string required | The same redirect URI used in the authorization request |
| code_verifier | string required | The PKCE code verifier the challenge was made from |
| client_id | string optional | Required for public apps, and for confidential apps that send their secret in the body |
| client_secret | string optional | Confidential apps only, if not using HTTP Basic auth |
Confidential apps authenticate with HTTP Basic auth (client ID as the username,
secret as the password) or with client_id and client_secret in the body.
Public apps only send client_id.
Example Request
curl -X POST https://mypayindia.com/oauth/token \
-u "your_client_id:your_client_secret" \
-d grant_type=authorization_code \
-d code=def50200a1b2... \
-d redirect_uri=https://example.com/callback \
-d code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk Example Response
{
"token_type": "Bearer",
"expires_in": 3600,
"access_token": "a1b2c3d4e5f6...",
"refresh_token": "def50200f6e5...",
"scope": "openid profile offline_access",
"id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ii..."
} Access tokens last 60 minutes. A refresh_token is only included when the user approved the offline_access scope.
Errors
| Error | HTTP | Description |
|---|---|---|
| invalid_client | 401 | Unknown client ID, wrong secret, or the app is disabled |
| invalid_grant | 400 | The code or refresh token is expired, already used, revoked, or the code verifier doesn't match |
| invalid_request | 400 | A required parameter is missing |
| unauthorized_client | 400 | The grant type isn't turned on for your app, for example device sign-in |
| unsupported_grant_type | 400 | The grant type is unknown |
Scopes and Claims
Scopes are what your app asks for. The user sees each one described on the approval screen. Ask only for what you need, the fewer scopes, the more likely people are to approve.
| Scope | Shown to the user as | Claims |
|---|---|---|
| openid | Know which MyPayIndia account is yours | sub |
| profile | See your username, profile link, avatar, pronouns and verified badge | preferred_username,profile,picture,pronouns,mpi_verified |
| See your email address and its verification status | email,email_verified | |
| name | See your first and last name | name,given_name,family_name |
| offline_access | Retain access while you are not using it | None |
| session | Sign in to your account with access to the full MyPayIndia API | None |
openid is needed for an ID token and for userinfo.
offline_access adds a refresh token so your app can keep working after
the access token expires.
session is only available to apps with full account access turned on.
Claims
| Claim | Type | Description |
|---|---|---|
| sub | string | The user's MyPayIndia account ID. It never changes and is never reused, use it as the key for the user in your app. |
| preferred_username | string | The user's current username |
| profile | string | URL of the user's MyPayIndia profile page |
| picture | string | URL of the user's avatar |
| pronouns | string | The pronouns shown on the user's profil |
| mpi_verified | boolean | Whether the user has the verified badge on MyPayIndia |
| string | The user's email address | |
| email_verified | boolean | Whether the user has verified that email address |
| name | string | The user's first and last name |
| given_name | string | The user's first name |
| family_name | string | The user's last name |
Full Account Access
An app that needs the whole MyPayIndia API, not just the user's identity, can sign
people in with the session scope and trade the access token for an API v2 session. Turn on full
account access in your app's developer settings first.
- Start sign-in at
/oauth/authorizewithscope=openid session. It cannot be combined withoffline_access, and the device flow refuses it. - The user types
FULLACCESSon the approval screen to confirm. They are asked every time, even if they approved your app before. - Exchange the code at
/oauth/tokenas usual, then send the access token in the body ofPOST /api/v2/auth/oauth. The response has asession_idto use asAuthorization: Beareron API v2.
While your app is unreviewed, only you can sign in to it with session. Unverified apps show users a large warning that MyPayIndia
does not endorse them. To get verified, explain to staff why your app needs full
account access.
If a verified app changes its name, logo or redirect URIs, or turns full account
access on, access is paused until staff review it. The same happens if staff turn it
off manually. While paused, /oauth/authorize answers invalid_scope for session. Sessions your app already
created keep working.
When a user disconnects your app, or your app is disabled or deleted, every session it created for them is signed out.
ID Token
The id_token is a JWT signed with RS256. It holds the claims for the scopes
the user approved, plus the standard ones below. Most libraries check it for you. If yours
doesn't:
- Fetch the keys from
https://mypayindia.com/oauth/jwksand pick the one whosekidmatches the token header. Cache them, and fetch again when you see akidyou don't know, because keys are rotated. - Check the RS256 signature with that key.
- Check that
issishttps://mypayindia.com,audis your client ID, andexpis in the future. - If you sent a
nonce, check that it matches.
Example Payload
{
"iss": "https://mypayindia.com",
"sub": "69",
"aud": "9d3f1c2a-5b7e-4f10-8a6b-2c4d6e8f0a1b",
"iat": 1791460800,
"exp": 1791464400,
"auth_time": 1791460750,
"nonce": "n-0S6_WzA2Mj",
"at_hash": "77QmUPtjPfzWtF2AnpK9RQ",
"preferred_username": "johnpayment",
"profile": "https://mypayindia.com/@johnpayment",
"picture": "https://mypayindia.com/storage/profiles/avatars/67.webp",
"pronouns": "he/him",
"mpi_verified": false
} | Claim | Description |
|---|---|
| iss | Always https://mypayindia.com |
| aud | Your client ID |
| iat, exp | When the token was issued and when it expires, as Unix timestamps |
| auth_time | When the user last signed in to MyPayIndia |
| nonce | The nonce from your authorization request, if you sent one |
| at_hash | Hash of the access token issued with this ID token |
Userinfo
Returns the user's current claims for an access token. Users can change their
profile at any time, and the ID token only holds the claims from when it was issued.
Fetch fresh data from userinfo rather than relying on what you stored earlier. The
access token must include the openid scope.
Example Request
curl https://mypayindia.com/oauth/userinfo \
-H "Authorization: Bearer a1b2c3d4e5f6..." Example Response
{
"sub": "69",
"preferred_username": "johnpayment",
"profile": "https://mypayindia.com/@johnpayment",
"mpi_verified": false,
"email": "[email protected]",
"email_verified": true
} 401 with invalid_token means the token expired, was revoked,
or the user's account is no longer active.Refresh Tokens
If the user approved offline_access, you get a refresh token that lasts 30
days. Use it to get a new access token without sending the user through sign-in again.
Example Request
curl -X POST https://mypayindia.com/oauth/token \
-u "your_client_id:your_client_secret" \
-d grant_type=refresh_token \
-d refresh_token=def50200f6e5... The response looks like the token exchange response, with a new access token, a new refresh token, and a new ID token.
Device Sign-in
This can be used for apps that can't open a web page, like Discord bots, CLIs, game servers, etcetera. Your app shows the user a short code, the user enters it on MyPayIndia in their own browser, and your app picks up the tokens once they approve.
Turn on device sign-in on your app's page under Developer Apps first.
With it on, redirect URIs are optional.
1. Start the sign-in
curl -X POST https://mypayindia.com/oauth/device/code \
-d client_id=your_client_id \
-d "scope=openid profile" Confidential apps also authenticate here, the same way as on the token endpoint.
{
"device_code": "def50200c3d4...",
"user_code": "BCDF-GHJK",
"verification_uri": "https://mypayindia.com/device",
"verification_uri_complete": "https://mypayindia.com/device?user_code=BCDF-GHJK",
"expires_in": 600,
"interval": 5
} 2. Show the code
Tell the user to go to verification_uri and enter the user_code, for example: "Go to https://mypayindia.com/device and enter BCDF-GHJK". verification_uri_complete has the code filled in already, which is useful for a link or QR code. The code expires
after 10 minutes.
3. Poll for tokens
Every interval seconds, ask the token endpoint whether the user has finished.
curl -X POST https://mypayindia.com/oauth/token \
-d grant_type=urn:ietf:params:oauth:grant-type:device_code \
-d client_id=your_client_id \
-d device_code=def50200c3d4... | Error | What to do |
|---|---|
| authorization_pending | The user hasn't finished yet. Keep polling |
| slow_down | You polled too fast. Add 5 seconds to your interval and keep polling |
| access_denied | The user denied your app. Stop polling |
| expired_token | The code expired. Start a new sign in request |
Once the user approves, the poll returns the same response as the token exchange.
Desktop and Mobile Apps
Register desktop and mobile apps as public apps. Anything shipped to a user's device can be unpacked, so it can't keep a secret. PKCE protects the sign-in instead.
Loopback redirects (desktop)
Start a local web server on any free port and use it as the redirect URI. Register http://127.0.0.1/callback (or http://[::1]/callback) without a port. When the request comes in, the
port can be anything, but the path and query must match exactly. Send the full
redirect URI, port included, in both the authorization request and the token
request.
localhost redirect URIs are matched exactly, port included, so prefer 127.0.0.1.
Custom schemes (mobile)
Mobile apps can use their own scheme, such as myapp://callback or com.example.app:/callback. Open the authorize URL in the system browser
or an in app browser tab, not an embedded web view.
Revocation
Revoke a token when the user signs out of your app. Revoking a refresh token also revokes the access token issued with it.
curl -X POST https://mypayindia.com/oauth/revoke \
-u "your_client_id:your_client_secret" \
-d token=def50200f6e5... The response is always 200 once your app has authenticated, even if the token
was unknown or already revoked.
When tokens stop working
Your app's tokens for a user are revoked when:
- the user disconnects your app from Connected apps in their account settings
- the user changes their password
- the user's account is suspended
- your app is disabled by MyPayIndia staff
Treat invalid_grant on refresh, or 401 from userinfo, as "signed
out" and send the user through sign-in again.
Review Tiers
Every app has a tier, shown as a badge on the approval screen. New apps start unreviewed. When your app is ready, contact MyPayIndia staff to have it reviewed.
| Tier | Badge | What users see |
|---|---|---|
| Unreviewed | A red warning that MyPayIndia hasn't reviewed the app. Only the app's owner and 10 other people can sign in. | |
| Unverified | A yellow warning that the app isn't verified. No limit on how many people can sign in. | |
| Verified | The verified badge. Apps with this badge were reviewed and officially approved for use by MyPayIndia. | |
| Official MyPayIndia Service | Reserved for MyPayIndia's own services. |
Button and Branding
The button is a normal link to the page on your site that starts the sign-in. Copy it as is, or make your own that follows the rules below.
<a href="/auth/mypayindia" style="display:inline-flex;align-items:center;gap:8px;padding:8px 16px;border-radius:8px;background:#121212;color:#fff;font:600 14px/20px system-ui,sans-serif;text-decoration:none"><img src="https://mypayindia.com/images/branding/logo-256.webp" alt="" width="32" height="32">Sign in with MyPayIndia</a> Rules
- Label it "Sign in with MyPayIndia" or "Continue with MyPayIndia".
- Don't stretch or redraw the MyPayIndia logo.
- Don't suggest that MyPayIndia made or endorses your app unless it is an Official MyPayIndia Service.
