New to OAuth2? No worries! Just follow the code examples for your
integration type - most developers are authenticated within 5 minutes.
Which Authentication Flow Do I Need?
Get Your Access Token
- User Applications
- POS & Server Systems
Authorization Code Flow with PKCE
Best for: Mobile apps, web applications, any app where users log in with their ClearLine credentialsGenerate PKCE Challenge
Create a code verifier and challenge for security.
Redirect User to Login
Send the user to ClearLine’s login page using the GET /Account/Login endpoint.The user logs in and authorizes your app. ClearLine redirects back to your
redirect_uri with an authorization code:Exchange Code for Access Token
Trade the authorization code for an access token using the POST /connect/token endpoint.Response:
JWT access token - include in
Authorization: Bearer {token} header for all API requestsAlways “Bearer”
Token lifetime in seconds (typically 3600 = 1 hour)
Use to obtain new access tokens without re-authenticating the user
Granted scopes (e.g., “clearline_api openid profile”)
You’re authenticated! Use the
access_token in your API requests. See Using Your Access Token below.Using Your Access Token
Once you have an access token, include it in theAuthorization header of all API requests:
Token Lifecycle
Active Token (0-3600 seconds)
Active Token (0-3600 seconds)
Use your token normally for API requests. It’s valid and working.
Expiring Soon (< 5 minutes remaining)
Expiring Soon (< 5 minutes remaining)
Best practice: Refresh your token proactively before it expires.
Expired Token (> 3600 seconds)
Expired Token (> 3600 seconds)
Authorization Code Flow: Use your
refresh_token to get a new access token without re-authenticating the user.Client Credentials Flow: Request a new token using the same process as before.Invalid Token (any time)
Invalid Token (any time)
If you receive a
401 Unauthorized error, your token is invalid. Re-authenticate from the beginning.Common causes: token manually revoked, credentials changed, or security policy violation.OAuth Scopes
Request the appropriate scopes based on your integration needs:| Scope | Description | Typical Use |
|---|---|---|
clearline_api | General API access for user applications | User-facing apps |
pos_integration | Full POS integration (transactions, loyalty, coupons) | POS terminals |
coupons_integration | Coupon-specific integration access | Coupon providers |
openid | User identity information (required for user auth) | User-facing apps |
profile | User profile data (name, email, etc.) | User-facing apps |
Environments
ClearLine provides three environments for different stages of development:| Environment | Auth Base URL | Purpose |
|---|---|---|
| Test | logintest.clearline.me | Development and integration testing |
| Demo | logindemo.clearline.me | Client demonstrations and UAT |
| Production | login.clearline.me | Live production environment |
Troubleshooting
invalid_grant: The authorization code is invalid or expired
invalid_grant: The authorization code is invalid or expired
invalid_client: Client authentication failed
invalid_client: Client authentication failed
Cause: Your
client_id or client_secret is incorrect, or the Basic Auth header is malformed.Solution:- Verify credentials in the ClearLine Admin Portal
- Ensure Basic Auth header format:
Basic {base64(client_id:client_secret)} - Check for spaces or special characters in your credentials
- Test your base64 encoding:
client_id:client_secretshould encode properly
invalid_request: code_verifier is required
invalid_request: code_verifier is required
Cause: Missing
code_verifier parameter when exchanging authorization code (PKCE flow).Solution:- Save the
code_verifierbefore redirecting to login - Include it in the token request body
- The verifier must exactly match the one used to generate
code_challenge
unauthorized_client: The client is not authorized to use this grant type
unauthorized_client: The client is not authorized to use this grant type
invalid_scope: The requested scope is invalid
invalid_scope: The requested scope is invalid
Cause: You’re requesting a scope that doesn’t exist or your client isn’t authorized for.Solution:
- Use valid scopes:
clearline_api,pos_integration,coupons_integration,openid,profile - Check scope spelling and formatting (lowercase, underscore-separated)
- Verify your client has permission for the requested scopes in Admin Portal
Security Best Practices
Protect Client Secrets
Never expose
client_secret in:- Mobile app code
- Browser JavaScript
- Public repositories
- Client-side storage
Validate State Parameter
Always validate the
state parameter in OAuth callbacks to prevent CSRF attacks.Use HTTPS Only
Always use HTTPS for:
- Redirect URIs
- Token endpoints
- All API requests
Implement Proactive Token Refresh
Don’t wait for 401 errors - refresh tokens before they expire:
Next Steps
Detailed Implementation Guides
Step-by-step guides with complete code examples and advanced scenarios
Quick Start Tutorial
Make your first authenticated API request in 5 minutes
API Environments
Learn about test, demo, and production environment configurations
POS Integration Workflows
Explore all available POS integration patterns and use cases