Skip to main content

Authentication Guide

COMPASS API uses OAuth 2.0 for authentication and JSON Web Tokens (JWT) for session management. This guide covers the complete authentication flow and best practices for secure integration.

Authentication Overview

Supported OAuth Providers

COMP COMP API supports authentication with:
  • Google OAuth 2.0
  • Microsoft Azure AD
Both providers return the same JWT token format and user data structure.

Authentication Flow

Step 1: Redirect to OAuth Provider

Step 2: Exchange Authorization Code for JWT

Google Sign-In

Microsoft Sign-In

Step 3: Receive JWT Token and User Data

Using JWT Tokens

Authorization Header

All authenticated requests must include the JWT token in the Authorization header:

Token Structure

JWT tokens contain three parts separated by dots:

Payload

Session Management

Validate Session

Logout

Code Examples

React Authentication Hook

Node.js Authentication Middleware

Python Authentication Example

Security Best Practices

Token Storage

✅ Recommended:
  • Use localStorage for web applications
  • Use secure HTTP-only cookies for server-side apps
  • Implement token refresh mechanisms
❌ Avoid:
  • Storing tokens in URL parameters
  • Hardcoding tokens in source code
  • Using sessionStorage for persistent sessions

Token Validation

Always validate tokens on the server side:

Error Handling

Permission-Based Access

Check User Permissions

Server-Side Permission Check

Troubleshooting

Common Issues

”Invalid token” Error

  • Check if token is properly formatted
  • Verify token hasn’t expired
  • Ensure JWT secret matches between services

”Unauthorized” Error

  • Verify Authorization header format: Bearer <token>
  • Check token is included in the request
  • Check network connectivity

”Forbidden” Error

  • User lacks required permissions
  • Check user role and department assignments
  • Verify permission configuration

Debug Mode

Enable debug logging for troubleshooting:

Next Steps

Now that you understand authentication:
  1. Explore User Management - Learn to manage users
  2. Browse All APIs - Discover available endpoints
  3. Check Permissions - Understand permission system
  4. Build Your Integration - Start building with COMPASS API
Need help? Check our troubleshooting guide or contact support.