getnet-oauth2-token

information icon
OAuth2 Token API — Authentication via Client Credentials Flow for the Getnet environment, issuing short-lived access tokens for applications consuming Getnet APIs.

Overview

getnet-oauth2-token is the authentication API that issues access tokens for applications consuming Getnet APIs. It implements the OAuth2 Client Credentials flow: an application exchanges its credentials (client_id and client_secret) for a short-lived access_token.
The returned token is mandatory and must be sent on all subsequent Getnet API calls, ensuring that only authorized applications can access protected resources.

Architecture

text
API Consumer (Application) │ │ 600;">POST /token (client_id + client_secret) ▼ ┌─────────────────────────────────────────┐ │ Getnet OAuth2 Authorization Server │ │ │ │ Validate credentials → issue JWT │ │ access_token (Bearer, expires_in) │ └─────────────────────────────────────────┘ │ │ access_token (Bearer, expires_in) ▼ Getnet Resource APIs Authorization: Bearer <access_token>

Key Design Decisions

ConcernSolution
Grant typeOAuth2 client_credentials (machine-to-machine, no end user)
Token formatJWT access_token returned as Bearer
Token lifetimeTime-boxed via expires_in (seconds); reuse until near expiry
Request encodingapplication/x-www-form-urlencoded
Error contractOAuth2 standard fields (error, error_description)
ScopeGranted permissions returned in scope (e.g. wlb:whitelabel:rw)

Environments

EnvironmentBase URLDescription
Homologhttps://api-homologacao.getnet.com.br/auth/oauth2Testing/homologation environment
Developmenthttps://developers.getnet.com.brDevelopment environment

API Endpoints

Get Access Token — POST /token

Generates an access token using the OAuth2 Client Credentials flow. The returned token must be used in subsequent calls to the Getnet API.

AttributeValue
MethodPOST
OperationgetAccessToken
CategoryAuthentication
Content-Typeapplication/x-www-form-urlencoded
Request parameters (body — form-urlencoded):
FieldTypeRequiredDescription
grant_typeStringYesOAuth2 grant type. Must always be client_credentials.
client_idStringYesUnique client identifier provided by Getnet.
client_secretString (password)YesClient secret key provided by Getnet.
Responses: 200 OK (token generated), 400 Bad Request, 401 Unauthorized, 500 Internal Server Error
Response body (200):
json
{ "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...", "token_type": "Bearer", "expires_in": 3600, "scope": "wlb:whitelabel:rw" }

Schemas

TokenResponse

FieldTypeRequiredDescription
access_tokenStringYesJWT access token for authenticating subsequent API calls.
token_typeStringYesToken type. Usually Bearer.
expires_inIntegerYesToken expiration time, in seconds.
scopeStringNoPermission scope granted to the token.

ErrorResponse

FieldTypeRequiredDescription
errorStringYesOAuth2 error code.
error_descriptionStringNoHuman-readable error description.

Authentication Flow

The Client Credentials flow is used for machine-to-machine (server-to-server) integrations, where no end user is involved. The application itself owns the credentials.
  1. Getnet provisions client_id + client_secret to the application
  2. Application → POST /token (grant_type=client_credentials, client_id, client_secret)
  3. Server validates credentials → returns access_token (+ token_type, expires_in, scope)
  4. Application calls Getnet APIs with header: Authorization: Bearer <access_token>
  5. On token expiry → repeat step 2 to obtain a new token

Error Handling

All error responses follow the OAuth2 standard, exposing error and error_description.
HTTP Statuserror (example)error_description (example)Meaning
400 Bad Requestinvalid_requestInvalid client credentialsMissing/incorrect parameters
401 Unauthorizedunauthorized_clientInvalid client secretInvalid credentials
500 Internal Server ErrorUnexpected server error
Error body example:
json
{ "error": "invalid_request", "error_description": "Invalid client credentials" }

Usage Example

Request the token (cURL):
text
600;">curl -X 600;">POST "https://api-homologacao.getnet.com.br/auth/oauth2/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=client_credentials" \ -d "client_id={CLIENT-ID}" \ -d "client_secret={CLIENT-SECRET}"
Use the token on subsequent calls:
text
600;">GET /some-getnet-api HTTP/1.1 Host: api-homologacao.getnet.com.br Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...

Best Practices

  • Reuse the token — valid for expires_in seconds (e.g. 3600s = 1h). Cache it and refresh only near expiry instead of requesting one per call.
  • Protect credentials — never expose client_id / client_secret in public source code, logs, or front-end code.
  • Respect scopes — use only the resources permitted by the granted scope.
  • Handle errors — treat 400/401 (review credentials/parameters) and 500 (controlled retry) distinctly.
  • Use the right environment — validate against the homolog URL before moving to production.

Getnet OAuth2 authentication — https://developers.getnet.com.br