Providers
Reddit Provider
Configure Reddit OAuth for Keyloom authentication - setup, scopes, and community platform integration.
Reddit Provider
Enable Reddit OAuth authentication in your Keyloom application for community and discussion platform integration.
Prerequisites
- Reddit app created at Reddit App Preferences
- Keyloom handler configured at
/api/auth/[...keyloom]
Setup
1. Create Reddit Application
- Go to Reddit App Preferences
- Click "Create App" or "Create Another App"
- Choose "web app" as the app type
- Fill in required information:
- Name: Your application name
- Description: Brief description of your app
- About URL: Your app's homepage (optional)
- Redirect URI:
${YOUR_APP_URL}/api/auth/oauth/reddit/callback
2. Get Credentials
From your Reddit app settings:
- Client ID: Found under your app name (short string)
- Client Secret: The "secret" field in your app settings
3. Environment Variables
REDDIT_CLIENT_ID=your_reddit_client_id
REDDIT_CLIENT_SECRET=your_reddit_client_secret4. Configure Provider
import { defineKeyloom } from "@keyloom/core";
import { reddit } from "@keyloom/providers";
export default defineKeyloom({
providers: [
reddit({
clientId: process.env.REDDIT_CLIENT_ID!,
clientSecret: process.env.REDDIT_CLIENT_SECRET!,
}),
],
// ... other config
});Configuration Options
reddit({
clientId: string;
clientSecret: string;
profileOverrides?: (profile: Profile) => Record<string, any>;
})Available Scopes
Reddit OAuth provides the following scopes:
identity- Access to user's basic identity information (username, account creation date)edit- Edit and delete user's comments and submissionsflair- Manage user and link flairhistory- Access user's voting historymodconfig- Manage configuration of subreddits user moderatesmodflair- Manage flair in subreddits user moderatesmodlog- Access moderation log in subreddits user moderatesmodposts- Approve, remove, mark nsfw, and distinguish content in subreddits user moderatesmodwiki- Change wiki pages in subreddits user moderatesmysubreddits- Access list of subreddits user moderates, contributes to, and subscribes toprivatemessages- Access user's inbox and send private messagesread- Read user's posts and commentsreport- Report content for rules violationssave- Save and unsave comments and submissionssubmit- Submit content to subredditssubscribe- Manage user's subreddit subscriptionsvote- Submit and change votes on comments and submissionswikiedit- Edit wiki pageswikiread- Read wiki pages
Recommended: Use minimal scopes (identity) unless you need specific Reddit functionality.
User Profile
Reddit returns the following user information:
{
id: string; // Reddit user ID
name: string | null; // Reddit username
email: null; // Email not provided by Reddit OAuth
image: string | null; // Profile icon URL (if available)
// Raw Reddit data available in profile
}Note: Reddit OAuth does not provide email addresses through the API.
Usage Example
import { useLogin } from "@keyloom/react";
export function RedditSignIn() {
const { login, loading } = useLogin();
const handleRedditLogin = async () => {
await login({
provider: "reddit",
callbackUrl: "/dashboard",
});
};
return (
<button onClick={handleRedditLogin} disabled={loading}>
{loading ? "Connecting..." : "Sign in with Reddit"}
</button>
);
}Reddit API Guidelines
When using Reddit OAuth, follow Reddit's API guidelines:
- Rate Limiting: Reddit has strict rate limits (60 requests per minute)
- User-Agent: Always include a descriptive User-Agent header
- OAuth Duration: Choose between temporary and permanent tokens
- API Rules: Follow Reddit's API Terms of Use
Use Cases
Reddit integration is ideal for:
- Community Applications: Building tools for Reddit communities
- Content Management: Managing posts and comments
- Moderation Tools: Creating moderation utilities
- Analytics: Analyzing Reddit activity and engagement
- Bot Applications: Creating Reddit bots (with proper permissions)
Troubleshooting
Invalid redirect URI
- Ensure redirect URI matches exactly in Reddit app settings
- Check for trailing slashes and protocol (http vs https)
- Verify the callback URL format
Rate limiting errors
- Implement proper rate limiting in your application
- Use exponential backoff for retries
- Monitor your API usage
Scope access denied
- Verify requested scopes are appropriate for your use case
- Some scopes require user consent during OAuth flow
- Check if your app type supports the requested scopes
Authentication failures
- Verify client ID and secret are correct
- Check that your app is configured as "web app" type
- Ensure User-Agent header is properly set
Security Considerations
- Store client secret securely (environment variables)
- Use HTTPS in production
- Follow Reddit's API Terms of Use
- Implement proper rate limiting
- Respect user privacy and Reddit's content policy
- Monitor for suspicious OAuth activity
Reddit API Best Practices
- Caching: Cache API responses to reduce rate limit usage
- Batch Requests: Group related API calls when possible
- Error Handling: Implement robust error handling for rate limits
- User-Agent: Use descriptive User-Agent strings
- Respect Limits: Stay well under rate limits to avoid blocking
See also
How is this guide?