Skip to Content
Clerk logo

Clerk Docs

Ctrl + K
Go to

Use Clerk as an OAuth 2 Provider

Learn how to use Clerk to facilitate Single Sign-On (SSO) with other clients that support the OAuth 2.0 protocol.

Clerk IDP Flow

Retrieve callback URL from the client application

Retrieve the Callback URL for the client application you want to configure. This is where your users will be redirected to after a successful authentication and is required to successfully create your OAuth application in the next step.

Create an OAuth application in Clerk

Next, you need to create an OAuth Application in Clerk via the Backend API by providing the Callback URL and a Name. Note that in this context the name is used to help you identify your application and is not displayed anywhere publicly.

POST /v1/oauth_applications
curl -X POST \ -H "Authorization: Bearer <CLERK_SECRET_KEY>" \ -H "Content-Type: application/json" \ -D {"callback_url":"", "name": "oauth_app_1"}

To create an OAuth Application that uses the authorization code flow with proof of key exchange (PKCE), set public to true in the POST request body.

{"callback_url":"", "name": "oauth_app_pkce", "public": true}

Clerk creates an OAuth application and returns it's configurations back to you.

{ "object":"oauth_application", "id":"oa_2O4BCh3zUONvWlZHtBXv6s6tm7u", "instance_id":"ins_2O4Ak02T4fDmKKv6tK5h0WJ8ou8", "name":"oauth_app_1", "client_id":"d9g4CT4WYiCBm7EU", "client_secret":"VVgbT7i6sPo7sTljq2zj12fjmg0jPL5k", "scopes":"profile email", "callback_url":"", "authorize_url":"", "token_fetch_url":"", "user_info_url":"", "created_at":1680809847940, "updated_at":1680810135145 }

For security reasons, Clerk does not store your Client Secret and cannot show it to you again, so we recommend you download the secret and store it someplace secure.

Configure OAuth application in client

Now that you have set up an OAuth application in Clerk, you will need to configure these settings in your Client.

  • Client ID: Public identifier of your OAuth application
  • Client Secret: Confidential secret used to authenticate your OAuth application
  • Authorization URL: Used by the Client to request authorization from your user
  • Token URL: Used by the Client to retrieve access tokens
  • Scopes: OAuth scopes used to grant access to the Client. Clerk only supports profile and email at this point
  • User Info URL: Used by the Client to retrieve the email address and profile (username, first and last name) associated to your user

What did you think of this content?

Clerk © 2023