Authentication
Authenticate requests to the Unzer API.
Overview
The Unzer API uses bearer token authentication over HTTPS. To authenticate, you first exchange your private key for a short-lived access token, then include that token in the Authorization header of your API requests.
Private key
Your private key allows you to identify yourself while sending Unzer API requests on the server side. Your private key has multiple permissions, so be sure to keep it safe. You should never make your private key accessible on the web.
Public key
Your public key allows you to identify yourself while sending Unzer API requests on the client side. This is utilized when integrating using Unzer UI components.
Authentication
Authenticate your API requests in two steps: first obtain an access token, then use it as a bearer token.
Step 1: Get an access token
Send an empty POST request to the token endpoint, authenticating with your private key using HTTP Basic Auth:
curl https://token.upcgw.com/v1/auth/token \
-X POST \
-u s-priv-xxxxxxxxxx:
The response contains your access token:
{
"accessToken": "eyJraWQiOiJhbGlhcy9jb25uZWN0aXZpdHktdjItdG9rZW4ta21zIiwiYWxnIjoiUlMyNTY..."
}
| Environment | Token endpoint |
|---|---|
| Sandbox | https://token.test.upcgw.com/v1/auth/token |
| Production | https://token.upcgw.com/v1/auth/token |
- Cache the token on your server and reuse it for multiple requests. Do not request a new token for every API call.
- A requested token is currently valid for 7 minutes, but this may change. Check the
expclaim of the JWT to determine the actual expiry time. - On a
401 Unauthorizedresponse, request a new token and retry the call. - There is a rate limit of 2 token creations per second.
Step 2: Use the bearer token
Include the access token in the Authorization header of your API requests:
curl https://api.unzer.com/v1/keypair \
-H 'Authorization: Bearer <access_token>'
// You do not need to handle tokens manually because it is done for you by the SDK.
// You can just create the Unzer object and pass your private key as parameter one
$unzer = new Unzer('s-priv-xxxxxxxxxx', SupportedLocale::GERMAN_GERMAN);
// Use the public key when calling Unzer API on the client side.
var unzer = new Unzer('s-pub-xxxxxxxxxx');
// Use the public key when calling Unzer API on the client side.
var unzer = new Unzer('s-pub-xxxxxxxxxx');
Unzer instance. You do not need to manage tokens manually.Legacy: Basic Authentication
HTTP basic authentication requires a username and password. In the Unzer API, the username is your API key, and the password is empty. To provide an empty password, add a colon (:) at the end of your key. Remember to encode your API key with a Base64 encoder.
curl https://api.unzer.com/v1/keypair \
--header "Authorization: Basic cy1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxOg=="
Unzer API keys
If you request for a test account, you will receive two sandbox API keys:
- Your sandbox public key (for example,
s-pub-xxxxxxxxxx) - Your sandbox private key (for example,
s-priv-xxxxxxxxxx)
Sandbox keys allow you to make test transactions.
After signing your Unzer contract, you get your production API keys:
- Your production public key (for example,
p-pub-xxxxxxxxxx) - Your production private key (for example,
p-priv-xxxxxxxxxx)
Your API keys are configured with permissions valid for your specific account. They are specific to you as a merchant.
| Key | Infix | Sandbox key example | Production key example |
|---|---|---|---|
| Public key | pub | s-pub-xxxxxxxxxx | p-pub-xxxxxxxxxx |
| Private key | priv | s-priv-xxxxxxxxxx | p-priv-xxxxxxxxxx |
Depending on the resource and method used, you either need your public key or your private key to authenticate your request. For details on which features require a public key or a private key, as shown in the following table.
| Endpoint | POST | GET | PUT | DELETE |
|---|---|---|---|---|
/payments/authorize | Private key | Private key | Not allowed | Not allowed |
/payments/charges | Private key | Private key | Not allowed | Not allowed |
/payments/authorize/cancels | Private key | Private key | Not allowed | Not allowed |
/payments/charges/cancels | Private key | Private key | Not allowed | Not allowed |
/payments/shipments | Private key | Private key | Not allowed | Not allowed |
/customers | Public key | Private key | Public key | Private key |
/types/{paymentType} | Public key | Private key | Not allowed | Not allowed |
See also
Check your key configuration:
