Authentication and Authorization Overview
Overview
The NeoSpace platform implements a robust, multi-tenant authentication and authorization framework that supports multiple authentication methods, granular permission management, and seamless integration with enterprise identity providers. This system enables organizations to leverage their existing identity infrastructure while maintaining fine-grained control over user access and permissions across multiple tenants and spaces.
Key Features
- Multi-Authentication Support: OIDC (OpenID Connect), JWT tokens, and API keys
- Granular Permissions: Fine-grained, resource-based permission system with space-scoped access control
- Enterprise Integration: Native support for Microsoft Entra ID (Azure AD) and other OIDC-compliant providers
- Multi-Tenant Architecture: Complete tenant isolation with per-tenant identity provider configuration
- Security-First Design: PKCE, CSRF protection, token validation, and permission caching
How It Works
The authentication and authorization flow follows these steps:
- Authentication: Users authenticate via OIDC, API keys, or JWT tokens
- Seat Resolution: OIDC tokens contain
memberOfclaims that map to Seats in the system - Permission Mapping: Seats define permissions within specific spaces
- Token Generation: Internal JWT tokens are generated with space-seat mappings (
hash_perm) - Permission Validation: Each API request validates permissions by checking Seat permissions in Redis cache
Table of Contents
- OpenID Connect (OIDC) Foundation
- Authentication Methods
- Permission Validation Flow
- Related Documentation
OpenID Connect (OIDC) Foundation
What is OpenID Connect?
OpenID Connect (OIDC) is an identity layer built on top of the OAuth 2.0 protocol. It enables clients to verify the identity of end-users based on authentication performed by an authorization server, as well as to obtain basic profile information about the end-user in an interoperable and REST-like manner.
OIDC extends OAuth 2.0 with:
- ID Tokens: JSON Web Tokens (JWT) that contain identity information about the authenticated user
- UserInfo Endpoint: Standardized endpoint for retrieving user profile information
- Standardized Claims: Common claims (sub, email, name, etc.) for user identity
- Discovery: Well-known configuration endpoints for automatic provider discovery
Why We Chose OIDC
Industry Standard and Interoperability
OIDC is an industry-standard protocol (OpenID Foundation standard) that ensures interoperability across different identity providers and applications. This means:
- Universal Support: Works with major cloud providers (AWS, Azure, Google Cloud)
- Enterprise Compatibility: Native support in Microsoft Entra ID, Okta, Auth0, Keycloak, and others
- Future-Proof: Based on open standards, ensuring long-term compatibility and support
Cloud Provider Support
OIDC is natively supported by all major cloud providers:
- Microsoft Azure: Microsoft Entra ID (formerly Azure AD) provides full OIDC support
- AWS: AWS Cognito and AWS IAM Identity Center support OIDC
- Google Cloud: Google Workspace and Google Cloud Identity support OIDC
- Multi-Cloud: Enables organizations to use different identity providers across different cloud environments
Security Advantages
OIDC provides several security benefits:
- PKCE (Proof Key for Code Exchange): Prevents authorization code interception attacks
- State Parameter: CSRF protection through secure state validation
- Token Validation: Cryptographic verification of ID tokens using JWKS (JSON Web Key Set)
- Short-Lived Tokens: Access tokens and ID tokens have configurable expiration times
- No Credential Storage: Users authenticate with their identity provider, eliminating the need to store passwords
Single Sign-On (SSO) Capabilities
OIDC enables seamless SSO experiences:
- Centralized Authentication: Users authenticate once with their identity provider
- Cross-Application Access: Single authentication works across multiple applications
- Enterprise Directory Integration: Direct integration with Active Directory, LDAP, and other enterprise directories
- Reduced Password Fatigue: Users don't need separate credentials for each application
Multi-Tenant Architecture Support
OIDC is ideal for multi-tenant applications:
- Tenant-Specific Providers: Each tenant can use their own identity provider
- Isolated Authentication: Complete tenant isolation in authentication flows
- Flexible Configuration: Per-tenant OIDC configuration (issuer, client ID, scopes)
- Scalable: No shared authentication state between tenants
Developer Experience
OIDC provides excellent developer experience:
- Well-Defined Flows: Standardized authentication flows reduce implementation complexity
- Libraries and SDKs: Rich ecosystem of libraries and tools
- Discovery: Automatic provider configuration discovery reduces manual setup
- Documentation: Extensive documentation and community support
Authentication Methods
The platform supports three authentication methods, evaluated in priority order:
API Key Authentication (Priority 1)
Purpose: Service-to-service authentication and programmatic access
Header: x-api-Key
Key Format: sk_<base62_encoded_data>
The encoded data contains: {tenant_id}_{api_key_id}_{random}
Validation Process:
- Format validation (regex:
^sk_[A-Za-z0-9]+$) - Extract tenant ID from encoded key
- Database lookup in MongoDB
- Expiration check
- Revocation status check
Use Cases:
- Automated scripts and CI/CD pipelines
- Service-to-service communication
- Third-party integrations
- Background jobs and scheduled tasks
JWT Bearer Token Authentication (Priority 2)
Purpose: User authentication via internally generated JWT tokens
Header: Authorization: Bearer <jwt_token>
Token Structure:
{
"sub": "user_id",
"email": "[email protected]",
"tenant_id": "tenant1",
"is_sso": true,
"user_metadata": {
"email": "[email protected]",
"name": "John Doe",
"sub": "external_user_id"
},
"exp": 1234567890,
"iat": 1234567890,
"nbf": 1234567890
}
Validation Process:
- Token parsing and format validation
- Signature verification using HMAC
- Token validity check (CVE-2024-51744 fix)
- Expiration verification (exp, nbf claims)
- Claims extraction
Token Generation:
- Generated after successful OIDC authentication
- Contains user identity and metadata
- Signed with tenant-specific JWT secret
- Configurable expiration (default: 1 hour)
OIDC Authentication (Priority 3)
Purpose: Single Sign-On (SSO) with external identity providers
Flow: Authorization Code with PKCE
Supported Providers:
- Microsoft Entra ID (Azure AD)
- Auth0
- Keycloak
- Google Workspace
- Okta
- Any OIDC-compliant provider
Endpoints:
POST /auth/oidc/login- Initiate authenticationGET /auth/oidc/callback- Handle provider callbackPOST /auth/oidc/validate- Validate OIDC tokenPOST /auth/oidc/refresh- Refresh expired token
For detailed OIDC setup instructions, see the OIDC Setup Guide.
Permission Validation Flow
The following diagram illustrates the complete authentication and permission validation flow:
Flow Explanation
The permission validation flow consists of four main phases:
- OIDC Authentication: User authenticates with the OIDC provider and receives a token containing
memberOfclaims (Seat names) - Token Processing & Seat Resolution: The API extracts Seat names from the OIDC token and queries MongoDB to resolve Seats with their associated spaces and permissions
- JWT Creation: The API creates an internal JWT token with
hash_permarray containing space-seat mappings, and caches Seat permissions in Redis - API Request with Permission Check: On each API request, the system validates permissions by matching the space ID, extracting the Seat name, querying Redis for permissions, and validating the required permission
For detailed information about Seat management and permissions, see the Seat Management Guide.
Related Documentation
- Seat Management - Complete guide to managing Seats and permissions
- OIDC Setup Guide - Step-by-step instructions for configuring OIDC providers