Status: DraftCreated: 2025-02-13Updated: 2025-02-13
Overview
The Platform API enables partners to create and manage Polar Organizations on behalf of their users, allowing seamless integration of monetization features into third-party platforms. This document outlines the technical architecture, authentication flow, and claim process for the Platform API.Core Entities
Platform Entity
A newPlatform entity will be introduced to represent partners with access to the Platform API:
- Purpose: Represents external platforms that can create and manage Organizations
- Key attributes:
id: Unique identifier for the Platformname: Human-readable name of the platformjwks_url: URL where the platform exposes its JWKS (JSON Web Key Set)created_at: Timestamp of platform creationupdated_at: Timestamp of last update
Organization Enhancements
The existingOrganization entity will be enhanced with platform-specific fields:
- New fields:
platform_id(nullable): Foreign key to the Platform that created/owns this Organizationplatform_external_id(nullable): The Organization’s ID on the external platformplatform_created_at(nullable): Timestamp when the Organization was created via Platform API
Authentication Flow
OIDC-based Authentication
The Platform API uses an OIDC approach with JWT tokens for authentication:- Platform Setup: Partner exposes JWKS at a public URL
- JWT Creation: Platform creates a JWT signed with their private key
- Token Exchange: JWT is sent to Polar’s OAuth2 token endpoint
- Validation: Polar validates the JWT using the platform’s public key
- Access Token: Polar returns an Organization Access Token
JWT Structure
We support two types of JWTs for different use cases:Organization JWT (for Organization Access Tokens)
Used when the platform wants to act on behalf of a specific organization:Platform JWT (for Platform Access Tokens)
Used when the platform wants to perform platform-level operations:- Organization JWT: Contains organization-specific claims (
sub= org external ID) - Platform JWT: Contains only platform claims (
sub=iss= platform ID) - Audience: Different
audvalues determine token type
Token Validation Process
The validation process differs based on the JWT type:Organization JWT Validation
- JWT Validation: Verify signature using platform’s JWKS
- Audience Check: Ensure
aud=polar:platform-organization - Claim Extraction: Extract
sub(platform_external_id) andiss(platform_id) - Organization Lookup: Query Organization by
platform_external_idandplatform_id - Organization Creation (if not exists):
- Create new Organization using
organization_nameandorganization_slugfrom JWT - Set
platform_idandplatform_external_id
- Create new Organization using
- Access Token Issuance: Return Organization Access Token
Platform JWT Validation
- JWT Validation: Verify signature using platform’s JWKS
- Audience Check: Ensure
aud=polar:platform - Claim Validation: Ensure
sub=iss= platform_id - Platform Verification: Verify platform exists and is active
- Access Token Issuance: Return Platform Access Token with requested scopes
Organization Claim Flow
Purpose
The claim flow allows a User to take ownership of an Organization created via the Platform API, enabling KYC completion and financial setup.Process
-
Claim Token Generation:
- Platform calls
/api/platform/organizations/{platform_external_id}/claim_token - Polar generates a short-lived, single-use claim token
- Token contains:
organization_id,platform_id, expiration
- Platform calls
-
User Onboarding:
- Platform presents claim token to their user
- User visits Polar’s onboarding flow with claim token
- User creates Polar account (or logs in)
-
Organization Claiming:
- User submits claim token during onboarding
- Polar validates token and links User to Organization
-
Post-Claim Process:
- User completes KYC verification
- User sets up financial/payout details
- Organization becomes fully active
Platform Access Tokens
Overview
In addition to Organization Access Tokens, we introduce Platform Access Tokens that allow platforms to manage multiple organizations and perform platform-level operations.Platform JWT Structure
Platforms can authenticate using a dedicated Platform JWT:subandissare both the Platform IDaudispolar:platform(vspolar:platform-organizationfor org-specific operations)- No organization-specific claims
Platform Access Token Capabilities
Platform Access Tokens enable:- Listing all organizations created by the platform
- Generating claim tokens for any platform organization
- Accessing platform-level analytics and reporting
- Managing platform configuration
Token Exchange for Platform Access
API Endpoints
Platform Authentication
POST /v1/oauth2/token- Exchange JWT for access tokensgrant_type: platformwithaud: polar:platform→ Platform Access Tokengrant_type: platformwithaud: polar:platform-organization→ Organization Access Token
Organization Management (Platform Access)
GET /api/platform/organizations/- List all platform organizations (requires Platform Access Token)GET /api/platform/organizations/{platform_external_id}- Get organization by external IDPOST /api/platform/organizations/{platform_external_id}/claim_token- Generate claim token
Organization Management (Organization Access)
- Standard Polar API endpoints (products, customers, subscriptions, etc.)

