Skip to main content
Connecting a user takes three requests: send them to Polar to approve access, exchange the code Polar returns for tokens, and call the API with the access token. You need an OAuth 2.0 client first. The examples use the sandbox. In production, use https://polar.sh for the authorization URL and https://api.polar.sh for the API.

Authorize

Redirect the user to the authorization URL:
The parameters follow the OpenID Connect specification. The main ones:
string
required
The authorization code flow, the only flow Polar supports.
string
required
The Client ID of your OAuth 2.0 client.
string
required
Where Polar sends the user after they approve access. It must be one of the client’s Redirect URIs.
string
required
Space-separated scopes to request. Each must be one of the client’s Scopes.
string
Optional. Makes the user pick exactly one organization on the consent screen, so the token is limited to it.
The user sees a consent screen listing the scopes you asked for. When they approve, Polar redirects them to your redirect_uri with a one-time code in the query string. Polar issues user-scoped access tokens, tied to the user who approved access. On the consent screen, the user can limit the token to specific organizations. By default it can access all of their organizations, including ones they join later. Access always follows the user’s current membership: if they leave an organization, the token loses access to it. To see which organizations a token is limited to, introspect it. The organizations array in the response is empty when the token isn’t limited.

Exchange the code for tokens

Send the code to the token endpoint, authenticated with your Client ID and Client Secret:
cURL
The response:
  • access_token authenticates API requests on behalf of the user, until expires_in seconds have passed.
  • refresh_token gets a new access token when the current one expires.
  • id_token is a signed JWT with the user’s identity, as defined by OpenID Connect.
The token endpoint is a standard OAuth 2.0 endpoint and doesn’t need a Polar-Version header. See Request Token.

Refresh the access token

cURL
Each refresh returns a new refresh token as well. Store it and use it next time.

Public clients

A public client can’t keep a secret, because its code runs on the user’s device: single-page apps, mobile and desktop apps. If, and only if, the client’s Client Type is Public Client, the token endpoint doesn’t need client_secret. Instead, the flow must use PKCE: send a code_challenge when you authorize, and the matching code_verifier when you exchange the code.

Make authenticated requests

Send the access token as a bearer token, like any other Polar token:
The token can only do what its scopes allow, in the organizations it can access. When it can access several organizations, pass organization_id on requests that create resources. To disconnect a user, revoke the token.

Learn more