Skip to main content
FinConnect handles authentication automatically. When you call sdk.pay() or sdk.registerIpn(), the SDK authenticates with the provider using your credentials, retrieves a token, and attaches it to the request — you don’t need to manage tokens manually.
Never expose your API credentials in client-side code. FinConnect is a server-side SDK.

PesaPal authentication

PesaPal uses OAuth2. Before each request, the SDK calls POST /api/Auth/RequestToken with your consumer key and secret, then attaches the returned Bearer token to the Authorization header of the subsequent API call. Credentials required: Token request:
The response contains a token field. Subsequent requests include:
A fresh token is fetched on every sdk.pay() and sdk.registerIpn() call. The SDK does not cache tokens between calls.

ClickPesa authentication

ClickPesa uses JWT. Before each payment request, the SDK calls POST /third-parties/generate-token with your client ID and API key passed as request headers. The returned JWT is attached directly to the Authorization header of the payment request (without a Bearer prefix). Credentials required: Token request:
The response contains a token field. Subsequent requests include:

Loading credentials safely

Store all credentials as environment variables and load them with dotenv.
Your .env file should look like:
.env
Add .env to your .gitignore to keep credentials out of source control.