Authentication
The SDK authenticates against GoPay using OAuth2client_credentials.
You do not call the token endpoint yourself for normal API usage — the SDK caches access tokens and refreshes them before expiry.
How it works
On first API call:- The SDK sends a request to
POST /oauth2/token - It stores the token in cache with expiration timestamp
- It reuses that token until it approaches expiration
- It refreshes automatically before expiry (refresh margin)
Token endpoint request
The SDK sends:grant_type=client_credentials- configured
scope(payment-allby default) Authorization: Basic <base64(clientId:clientSecret)>
Token cache
By default,InMemoryTokenCache is used.
You can inject your own cache to share tokens across requests or processes:
Concurrency behavior
The token manager deduplicates concurrent token requests:- if multiple requests need a token at once, only one token HTTP call is executed
- all callers await the same in-flight promise
Recommended settings
- keep
tokenRefreshMarginSecondsdefault (30) unless your infra requires more buffer - keep credentials in environment variables or secret manager
- avoid rotating credentials without coordinated deployment across all nodes