membergate / membergate-api
Client for the Membergate API: signed requests, every API method, hosted sign-in helpers.
Package info
github.com/membergate/membergate-sdk
Language:ColdFusion
pkg:composer/membergate/membergate-api
Requires
- php: >=8.1
- ext-curl: *
- ext-hash: *
- ext-json: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Official clients for the Membergate API, for Python, JavaScript/TypeScript, PHP and ColdFusion (CFML).
Each one signs your requests, has a method for every API call, checks your arguments before anything is sent, and includes helpers for hosted sign-in. They have no dependencies.
| Language | Folder | Install |
|---|---|---|
| Python 3.9+ | python/ | pip install "git+https://github.com/membergate/membergate-sdk.git#subdirectory=python" |
| JavaScript / TypeScript (Node 18+, Deno, Bun, Workers) | javascript/ | download the javascript folder, then npm install ./javascript |
| PHP 8.1+ | php/ | composer require membergate/membergate-api |
| ColdFusion 2021+ / Lucee 5.4+ | cfml/ | copy the cfml folder into your application, for example as /lib/membergate |
Each folder's README has a quick start, the full list of calls, and examples.
Before you start
- On your Membergate site, open the API Keys page in the Control Panel and make a key pair for your app.
- Keep the secret key on your server. Never put it in a web page or a phone app. For a phone app, use hosted sign-in (below) and let your server make the API calls.
A first call
from membergate_api import Membergate mg = Membergate('https://www.yoursite.com', public_key='...', secret_key='...') r = mg.member.validate_member_login(userid='jdoe', password='...') print(r.ok, r.status, r.message)
import { Membergate } from '@membergate/api'; const mg = new Membergate({ siteUrl: 'https://www.yoursite.com', publicKey: '...', secretKey: '...' }); const r = await mg.member.validateMemberLogin({ userid: 'jdoe', password: '...' }); console.log(r.ok, r.status, r.message);
$mg = new Membergate\Api\Client('https://www.yoursite.com', '...', '...'); $r = $mg->member->validateMemberLogin(['userid' => 'jdoe', 'password' => '...']); echo $r->ok ? 'ok' : $r->message;
mg = new lib.membergate.Membergate(siteUrl="https://www.yoursite.com", publicKey="...", secretKey="..."); r = mg.member.validateMemberLogin(userid="jdoe", password="..."); writeOutput(r.ok ? "ok" : r.message);
Every call returns the API's answer: ok, status and subcode (for example 401 and 101 for a wrong password), message and data. A refusal from the API is an ordinary answer with ok set to false. The SDKs throw only when the API can't be reached.
Hosted sign-in
With hosted sign-in, members sign in on your Membergate site, by any method the site offers, and come back to your app with a one-time code. Your app never sees their password. Each SDK has helpers to make the PKCE pair and the sign-in address; then you swap the code with member.exchangeSignInCode. See ExchangeSignInCode in the API docs.
What's here
spec/membergate-api.json the API: every method an app key can call, and its arguments
spec/signing-vectors.json signing test cases worked out by the Membergate server
python/ javascript/ php/ cfml/
The methods in each SDK are generated from spec/membergate-api.json, so all four always cover the same calls.
How a request is signed
You don't need this to use the SDKs. It's here for anyone writing their own client.
- Every argument is sent as a string.
- Booleans become
true/false, and numbers their decimal form. - Lists and objects become a compact JSON string.
- Null is left out.
- Booleans become
- Argument names must be unique ignoring case, and may use only letters, digits,
_,-and.. - The canonical form is
{"name":"value",...}:- Names are sorted by their lower-case form.
- Values are exactly as sent, with no escaping.
- With no arguments, it's
{}. - Query values are signed percent-encoded (RFC 3986), as they appear in the URL.
- The signing key is an HMAC-SHA256 chain over the timestamp (UTC,
YYYY-MM-DDTHH:MM:SS), the HTTP method, the component and the API method. It starts from"MGAPI" + secret key, and each step uses the previous step's upper-case hex digest as text. - The string to sign is these lines joined with
\n:HMACSHA256- the timestamp
- the HTTP method
- the component
- the API method
- the SHA-256 of the canonical query
- the SHA-256 of the canonical body
- The headers are
publickey,timestamp,component,methodandsignature. The request goes tohttps://<site>/api/request.cfmover https only. - Each signature is accepted once. The SDKs add a random
mgnoncevalue to the query, so identical calls made in the same second are still accepted.
spec/signing-vectors.json has worked cases for every step.
Live tests
Each SDK has a live test that runs the same nine checks against a site, using a key pair you supply (MG_SITE, MG_PUBLIC_KEY, MG_SECRET_KEY). Use a test site, not your live one.
Support and license
Report problems at github.com/membergate/membergate-sdk/issues. The SDKs are released under the MIT License.