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

  1. Register your app on the Developer Apps page. You need a verified email address to do this.
  2. 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.
  3. Add the exact URL of your callback page as a redirect URI, for example https://example.com/callback.
  4. 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

https://mypayindia.com/.well-known/openid-configuration

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"],
}
Use the 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.

EndpointMethodPurpose
/.well-known/openid-configurationGETDiscovery document
/oauth/jwksGETPublic keys for checking ID token signatures
/oauth/authorizeGETWhere you send the user to sign in
/oauth/tokenPOSTExchange a code, refresh token or device code for tokens
/oauth/userinfoGET POSTThe user's claims for an access token
/oauth/revokePOSTRevoke an access or refresh token
/oauth/device/codePOSTStart a device sign-in
/deviceGETWhere users enter a device code
The token, revoke and device endpoints allow 60 requests per minute for each app and IP address.

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.

GET https://mypayindia.com/oauth/authorize

Query Parameters

ParameterTypeDescription
response_typestring requiredAlways code
client_idstring requiredYour app's client ID
redirect_uristring optionalWhere 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
scopestring requiredSpace separated scopes. Include openid to get an ID token
code_challengestring requiredPKCE challenge: the base64url encoded SHA-256 hash of a random code verifier that you keep. Required for every app, including confidential ones.
code_challenge_methodstring requiredMust be S256, plain is refused.
statestring optionalA random value sent back to you unchanged. Check it on your callback to protect against CSRF
noncestring optionalA random value copied into the ID token. Check it to make sure the ID token belongs to this sign in request
promptstring optionallogin 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_ageinteger optionalSeconds 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

ErrorDescription
access_deniedThe user denied your app, or your app has reached its user limit (see tiers)
invalid_requestA parameter is missing or wrong, for example no S256 code challenge
invalid_scopeA requested scope doesn't exist
login_requiredprompt=none was sent but the user has to sign in
consent_requiredprompt=none was sent but the user hasn't approved these scopes yet
When the client ID is unknown or the redirect URI isn't registered, the user is not sent back to your app, but sees an error page on MyPayIndia instead.

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.

POST https://mypayindia.com/oauth/token

Request Body (form encoded)

ParameterTypeDescription
grant_typestring requiredauthorization_code
codestring requiredThe code from the callback
redirect_uristring requiredThe same redirect URI used in the authorization request
code_verifierstring requiredThe PKCE code verifier the challenge was made from
client_idstring optionalRequired for public apps, and for confidential apps that send their secret in the body
client_secretstring optionalConfidential 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

ErrorHTTPDescription
invalid_client401Unknown client ID, wrong secret, or the app is disabled
invalid_grant400The code or refresh token is expired, already used, revoked, or the code verifier doesn't match
invalid_request400A required parameter is missing
unauthorized_client400The grant type isn't turned on for your app, for example device sign-in
unsupported_grant_type400The 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.

ScopeShown to the user asClaims
openidKnow which MyPayIndia account is yourssub
profileSee your username, profile link, avatar, pronouns and verified badgepreferred_username,profile,picture,pronouns,mpi_verified
emailSee your email address and its verification statusemail,email_verified
nameSee your first and last namename,given_name,family_name
offline_accessRetain access while you are not using itNone
sessionSign in to your account with access to the full MyPayIndia APINone

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

ClaimTypeDescription
substringThe user's MyPayIndia account ID. It never changes and is never reused, use it as the key for the user in your app.
preferred_usernamestringThe user's current username
profilestringURL of the user's MyPayIndia profile page
picturestringURL of the user's avatar
pronounsstringThe pronouns shown on the user's profil
mpi_verifiedbooleanWhether the user has the verified badge on MyPayIndia
emailstringThe user's email address
email_verifiedbooleanWhether the user has verified that email address
namestringThe user's first and last name
given_namestringThe user's first name
family_namestringThe user's last name
Claims with no value are left out.

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.

  1. Start sign-in at /oauth/authorize with scope=openid session. It cannot be combined with offline_access, and the device flow refuses it.
  2. The user types FULLACCESS on the approval screen to confirm. They are asked every time, even if they approved your app before.
  3. Exchange the code at /oauth/token as usual, then send the access token in the body of POST /api/v2/auth/oauth. The response has a session_id to use as Authorization: Bearer on 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:

  1. Fetch the keys from https://mypayindia.com/oauth/jwks and pick the one whose kid matches the token header. Cache them, and fetch again when you see a kid you don't know, because keys are rotated.
  2. Check the RS256 signature with that key.
  3. Check that iss is https://mypayindia.com, aud is your client ID, and exp is in the future.
  4. 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
}
ClaimDescription
issAlways https://mypayindia.com
audYour client ID
iat, expWhen the token was issued and when it expires, as Unix timestamps
auth_timeWhen the user last signed in to MyPayIndia
nonceThe nonce from your authorization request, if you sent one
at_hashHash 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.

GET https://mypayindia.com/oauth/userinfo

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
}
A 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.

Refresh tokens rotate. This means every refresh returns a new refresh token and the old one stops working. Save the new one before you use the access token. Sending an old refresh token again revokes every token your app holds for that user, and they have to sign in again.

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

POST https://mypayindia.com/oauth/device/code
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...
ErrorWhat to do
authorization_pendingThe user hasn't finished yet. Keep polling
slow_downYou polled too fast. Add 5 seconds to your interval and keep polling
access_deniedThe user denied your app. Stop polling
expired_tokenThe code expired. Start a new sign in request

Once the user approves, the poll returns the same response as the token exchange.

Users always see the approval screen for device codes, even if they approved your app before, so they can check the code really came from you.

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.

POST https://mypayindia.com/oauth/revoke
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.

TierBadgeWhat users see
UnreviewedA red warning that MyPayIndia hasn't reviewed the app. Only the app's owner and 10 other people can sign in.
UnverifiedA yellow warning that the app isn't verified. No limit on how many people can sign in.
VerifiedThe verified badge. Apps with this badge were reviewed and officially approved for use by MyPayIndia.
Official MyPayIndia ServiceReserved for MyPayIndia's own services.
Changing a verified app's name, logo or redirect URIs moves it back to Unverified until it is reviewed again.

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.