Overview
The Mangopay PHP SDK uses OAuth 2.0 authentication to secure API requests. The SDK automatically manages authentication tokens, including creation, storage, and renewal.Authentication Flow
The SDK handles authentication through two main components:- AuthorizationTokenManager - Manages token lifecycle
- AuthenticationManager - Creates OAuth tokens
Token Management
Tokens are automatically managed by the SDK. When you make an API request:- The SDK checks if a valid token exists
- If the token is expired or missing, a new one is created
- The token is stored using the configured storage strategy
- All subsequent requests use the stored token
Tokens are cached and automatically renewed when they expire, so you don’t need to manage them manually.
Configuration
Set up authentication when initializing the SDK:Environment URLs
Sandbox
https://api.sandbox.mangopay.comUse for testing and developmentProduction
https://api.mangopay.comUse for live transactionsCustom Token Storage
By default, tokens are stored in temporary files. You can implement custom storage by creating a class that implementsIStorageStrategy:
Token Information
The OAuth token contains:- access_token - The authentication token
- token_type - Always “Bearer”
- expires_in - Token lifetime in seconds
Connection Timeouts
You can configure connection and response timeouts:Proxy Configuration
If you need to use a proxy:SSL Certificate Verification
For production environments, you can specify a custom CA certificate bundle:Best Practices
Store credentials securely
Store credentials securely
Never hardcode credentials in your source code. Use environment variables or secure configuration files that are not committed to version control.
Use different credentials for environments
Use different credentials for environments
Maintain separate API credentials for sandbox and production environments.
Implement custom storage for production
Implement custom storage for production
The default file-based token storage is suitable for development, but consider using a database or cache system for production.
Monitor token errors
Monitor token errors
Implement logging to track authentication failures and token renewal issues.
Next Steps
Users
Learn about user management
Wallets
Understand wallet operations