This guide walks you through configuring X OAuth for your app’s authentication. Your app’s users will be able to sign in with their X accounts.
Prerequisites
- A published Replit app (you need a deployment URL like
your-app.replit.app)
- An X Developer account (free tier available)
Step 1: Publish your app
Before configuring custom OAuth credentials, you need a published deployment URL. You’ll need the URL when setting up your custom X credentials.
- Publish your app from the Replit workspace
- Note your published URL (e.g.,
https://your-app.replit.app)
Step 2: Set up X Developer app
Create a developer account (if needed)
- Navigate to X Developer Portal
- Apply for a developer account if you don’t have one
- Complete the application describing your use case
Create or select an app
- In the X Developer Portal, go to Projects & Apps
- Use an existing app or select Add App
- Enter an app name and select Next
- Select App settings
- Scroll to User authentication settings
- Select Set up
App permissions:
Select minimum permission level:
- Read - Required for user profile (minimum)
- Write - For posting on behalf of users (optional)
- Direct Messages - For DM access (optional)
Permissions must match scopes requested. If your app requests tweet.write but you only enabled Read, authentication will fail.
Type of app:
Select Web App, Automated App or Bot
App info:
- Callback URI / Redirect URL: The callback URI is your published domain followed by
/__clerk/v1/oauth_callback. Enter the following, replacing your-app.replit.app with your actual published domain:
https://your-app.replit.app/__clerk/v1/oauth_callback
- Website URL: Your published app URL:
https://your-app.replit.app
- Select Save
- Save your Client ID and Client Secret
Store your Client Secret securely. If lost, regenerating it invalidates the old one.
Step 4: Enter credentials in Replit
- In your Repl, navigate to the Auth pane
- Select the Configure tab
- Select Production environment
- Select the Edit button next to X
- Toggle on Use custom credentials
- Paste your Client ID and Client Secret
- Select Save changes
- Toggle X to Enabled
Step 5: Test your integration
- Open your published app’s login page
- Select Sign in with X
- Authorize the app on X
- Verify successful authentication
Troubleshooting
Redirect URI mismatch
- Verify the Callback URI is exactly
https://your-app.replit.app/__clerk/v1/oauth_callback
- Check for typos or incorrect protocols
- No trailing slashes
Invalid client
- Double-check Client ID and Client Secret
- Ensure no extra spaces
- Verify you are using OAuth 2.0 credentials (not OAuth 1.0a)
Scope/permission errors
- Verify scopes match permissions enabled in X Developer Portal
- Ensure Read permission is enabled at minimum
App in development mode
- X apps start in development mode with limited users
- You may need to apply for elevated access for production use
Not working on custom domain
- Update the Website URL in your X app settings to your custom domain
- Update the Callback URI to
https://your-custom-domain.com/__clerk/v1/oauth_callback
- Republish your app
Additional resources