Authentication Guide

The mCards API supports two authentication methods: HMAC-SHA256 signatures for server-to-server integrations, and OAuth2 Bearer tokens for client applications with scoped access.

HMAC-SHA256 Authentication

HMAC authentication signs every request with your API secret, ensuring message integrity and authenticity.

How It Works

  1. Serialize the request body as JSON (use "" for GET requests with no body)
  2. Compute HMAC-SHA256 of the body using your API secret
  3. Base64-encode the signature
  4. Send the header: Authorization: HMAC_SHA256 {api_key};{base64_signature}

Signature Format

text
Authorization: HMAC_SHA256 {api_key};{base64(hmac_sha256(request_body, api_secret))}

TypeScript Example

typescript
import { McardsSdk } from '@mcards/sdk';

const client = new McardsSdk({
  apiKey: process.env.MCARDS_API_KEY,
  apiSecret: process.env.MCARDS_API_SECRET,
  baseUrl: 'https://api.mcards.com',
});

// All requests are automatically signed
const { data: profile } = await client.partner.getProfile();

Python Example

python
import os
from mcards_sdk import McardsSdk

client = McardsSdk(
    api_key=os.environ["MCARDS_API_KEY"],
    api_secret=os.environ["MCARDS_API_SECRET"],
    base_url="https://api.mcards.com",
)

# All requests are automatically signed
profile = client.partner.get_profile()

Manual Signature (cURL)

bash
API_KEY="your-api-key"
API_SECRET="your-api-secret"
BODY='""'

SIGNATURE=$(echo -n "$BODY" | openssl dgst -sha256 -hmac "$API_SECRET" -binary | base64)

curl -X GET https://api.mcards.com/api/v2/partner/profile \
  -H "Authorization: HMAC_SHA256 ${API_KEY};${SIGNATURE}" \
  -H "Content-Type: application/json"

Signing Rules

Request TypeBody to Sign
GET (no body)"" (empty string with quotes)
POST/PUT with JSONThe full JSON body string
POST form-encodedThe form body string
Important: The signature is computed over the exact byte string of the body. Whitespace differences will produce different signatures.

OAuth2 Bearer Token Authentication

OAuth2 uses the client credentials grant to exchange a client ID and secret for a time-limited access token.

Step 1: Create an OAuth Application

bash
curl -X POST https://api.mcards.com/api/v2/oauth/applications \
  -H "Authorization: HMAC_SHA256 ${API_KEY};${SIGNATURE}" \
  -H "Content-Type: application/json" \
  -d '{"name": "My App", "scopes": "partner:read wallets:read cards:read"}'

Step 2: Exchange for Access Token

bash
curl -X POST https://api.mcards.com/api/v2/oauth/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials&client_id=mcp_abc123&client_secret=secret_xyz789"

Step 3: Use the Token

bash
curl https://api.mcards.com/api/v2/partner/profile \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..."

Token Lifecycle

OperationEndpointAuth Required
Create tokenPOST /api/v2/oauth/tokenNone (client credentials in body)
Introspect tokenGET /api/v2/oauth/token_infoBearer token
Revoke tokenPOST /api/v2/oauth/revokeHMAC or Bearer
List appsGET /api/v2/oauth/applicationsHMAC or Bearer

Token Expiry

  • Access tokens expire after 1 hour (3600 seconds)
  • The expires_in field indicates seconds until expiry
  • Request a new token when the current one expires — there is no refresh token flow

API Scopes

Scopes control what resources a Bearer token can access. HMAC authentication has full access.

Available Scopes

ScopeDescription
partner:readRead partner profile, keys, roles
partner:writeUpdate partner settings
wallets:readList and view wallets
wallets:writeCreate and update wallets
cards:readList and view cards, balances
cards:writeIssue, activate, deactivate cards
transactions:readList and view transactions
cardholders:readList and view cardholders
cardholders:writeCreate and update cardholders
programs:readList and view programs
rewards:readList and view rewards
rewards:writeCreate and manage rewards
offers:readList and view offers
offers:writeCreate and manage offers
webhooks:readList and view webhooks
webhooks:writeCreate, update, delete webhooks
payments:readList payment gateways and accounts
branding:readView card designs
analytics:readView analytics and metrics
sandbox:readRead sandbox environment info
sandbox:writeExecute sandbox simulations

Shorthand Scopes

ShorthandExpands To
readAll read scopes
writeAll write scopes
adminAll scopes

Security Best Practices

  1. Never expose API secrets in client-side code — use HMAC only in server environments
  2. Use OAuth2 with minimal scopes for client-facing applications
  3. Rotate secrets periodically via the partner dashboard
  4. Store credentials in environment variables, never in source code
  5. Use HTTPS exclusively — the API rejects plaintext HTTP requests
  6. Monitor rate limits via X-RateLimit-* response headers