Authentication

Authenticate to GAINS Connect with Basic credentials or a Bearer token, and what each authentication failure means.

Every GAINS Connect endpoint except GET /ping needs credentials in the Authorization header. GET /ping ignores any credentials you send. This page explains the two schemes GAINS Connect accepts, how to get a token, and what the API answers when credentials are missing or refused.

Choose a scheme

SchemeCredentialsUse it for
BasicThe user name and password of a GAINS userAll endpoints except partner endpoints
Bearer (OAuth 2.0)A client ID and secret, exchanged for a short-lived access tokenAll endpoints, and required for partner endpoints such as POST /partners/vendor-parameters

Ask your GAINS representative for either set of credentials. For Basic, a GAINS administrator creates the user in GAINS User Management; use a dedicated user for your integration rather than a person's account.

Basic authentication

Send the user name and password, joined by a colon and Base64-encoded, on every request.

curl https://acme.gainsystems.com/api/v1/customers \
  -u "integration.user:<password>"

Bearer authentication

Request a token

Send a POST to the token endpoint of the GAINS authorization server with an application/x-www-form-urlencoded body.

EnvironmentToken endpoint
Productionhttps://auth.gainsapps.com/realms/GAINSystems/protocol/openid-connect/token
Developmenthttps://auth-dev.gainsapps.com/realms/GAINSystems/protocol/openid-connect/token

These servers issue tokens only. They are the same for every customer and are not your GAINS Connect environment.

FieldValue
grant_typeclient_credentials
client_idThe client ID you were issued
client_secretThe client secret you were issued
curl -X POST https://auth.gainsapps.com/realms/GAINSystems/protocol/openid-connect/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials" \
  -d "client_id=<your client id>" \
  -d "client_secret=<your client secret>"
{
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJqTl9F...",
  "expires_in": 600,
  "token_type": "Bearer"
}
FieldMeaning
access_tokenThe token to send to GAINS Connect.
expires_inSeconds until the token expires.
token_typeAlways Bearer.

Use the token

Send the access_token on every request.

curl https://acme.gainsystems.com/api/v1/customers \
  -H "Authorization: Bearer <access_token>"

Reuse a token until shortly before expires_in runs out, then request a new one with the same client credentials. Requesting a token for every call is unnecessary.

What a token grants

A token is valid only for the GAINS Connect environment it was issued for. Your client is granted access to groups of endpoints, for example loading master data or reading replenishment orders. A token without access to an endpoint gets 403. Ask your GAINS representative to change what your client can call.

When authentication fails

Errors use the standard error body; see Errors Handling & Exceptions.

StatusReasonWhat to do
401The token is invalid or has expired. Please request a new token.Credentials are missing, or the token is invalid or expired. Request a new token.
401The credentials provided are not valid.GAINS refused the Basic user name or password. Check them.
401This endpoint accepts Bearer tokens only.Basic credentials were sent to a partner endpoint. Send a Bearer token.
403The token used has not been granted scope for this route.The token is valid but not for this endpoint. Ask your GAINS representative for access.
503Authentication service is currently unavailable. Please try again later.GAINS could not be reached to check Basic credentials. Retry later.
{
  "Reason": "The token is invalid or has expired. Please request a new token."
}

Related


Did this page help you?