Authentication Overview
Loyalty.lt provides multiple authentication methods depending on the API layer you’re using and your integration requirements. This guide explains each method and when to use them.Authentication Methods
Choose the authentication method that best fits your integration needs and security requirements.
API Credentials
Best for: Shop APIs, server-to-server communication
- Simple header-based authentication
 - API Key + Secret combination
 - Suitable for backend integrations
 
JWT Tokens
Best for: SDK APIs, user-based applications
- Secure token-based authentication
 - User-specific permissions
 - Real-time features support
 
OAuth 2.0
Best for: Third-party integrations
- Industry standard authorization
 - Granular permission scopes
 - Secure delegation of access
 
Webhooks
Best for: Event-driven integrations
- HMAC signature verification
 - Secure event delivery
 - Real-time notifications
 
API Credentials Authentication
Overview
API Credentials are the simplest authentication method, using a combination of API Key and API Secret sent as HTTP headers.- Usage
 - Obtaining Credentials
 - Best Practices
 
Endpoints: Shop APIs (
Method: HTTP Headers
Security: HTTPS required
/api/*)Method: HTTP Headers
Security: HTTPS required
Example Implementation
JWT Token Authentication
Overview
JWT (JSON Web Tokens) provide secure, user-specific authentication for SDK and Partner APIs with support for permissions and real-time features.- Token Flow
 - Token Structure
 - Permissions
 
- Initial Authentication: Use API credentials to request JWT
 - Token Usage: Include JWT in Authorization header
 - Token Refresh: Renew tokens before expiration
 - Logout: Invalidate tokens when done
 
Obtaining JWT Tokens
Using JWT Tokens
Token Refresh
OAuth 2.0 Authentication
Overview
OAuth 2.0 provides secure, standardized authorization for third-party applications that need to access Loyalty.lt APIs on behalf of users.- Grant Types
 - Scopes
 - Registration
 
Authorization Code: For web applications with server-side code
Client Credentials: For server-to-server communication
Implicit: For single-page applications (deprecated)
Client Credentials: For server-to-server communication
Implicit: For single-page applications (deprecated)
Authorization Code Flow
1
Authorization Request
Redirect user to authorization server:
2
User Authorization
User grants permission and is redirected back:
3
Token Exchange
Exchange authorization code for access token:
4
API Access
Use access token to make API requests:
Webhook Authentication
Overview
Webhooks use HMAC-SHA256 signatures to verify that events are sent from Loyalty.lt and haven’t been tampered with.- Signature Verification
 - Setup
 - Event Types
 
Each webhook includes a signature header:Verify using your webhook secret:
Webhook Implementation
Error Handling
Authentication Errors
401 Unauthorized
401 Unauthorized
403 Forbidden
403 Forbidden
Cause: Valid credentials but insufficient permissions
Solution: Check required permissions for endpoint
Solution: Check required permissions for endpoint
429 Rate Limited
429 Rate Limited
Cause: Too many requests in time window
Solution: Implement exponential backoff
Solution: Implement exponential backoff
Best Practices
Token Management
- Implement automatic token refresh
 - Store tokens securely
 - Handle token expiration gracefully
 - Log authentication events
 
Error Handling
- Implement retry logic with backoff
 - Handle network timeouts
 - Log authentication failures
 - Provide user-friendly error messages
 
Security
- Use HTTPS for all requests
 - Validate webhook signatures
 - Rotate credentials regularly
 - Monitor for suspicious activity
 
Performance
- Cache tokens until expiration
 - Use connection pooling
 - Implement rate limiting
 - Monitor API usage