Zoho SSO Integration
Simple WordPress and Zoho SSO Integration
by Adam · github.com/mrunknown0001/wordpress-zoho-sso-integration
★ 0stars
0forks
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/mrunknown0001/wordpress-zoho-sso-integration/archive/refs/heads/main.zipZoho SSO WordPress Plugin
Simple Zoho Single Sign-On integration for WordPress with subscription data support.
Features
- Single Sign-On with Zoho accounts
- Automatic user creation on first login
- Syncs user profile data (name, email)
- Fetches and stores Zoho Subscriptions data
- Helper functions to check subscription status
Installation
- Download the plugin files
- Create a folder
zoho-ssoin/wp-content/plugins/ - Upload
zoho-sso.phpto the folder - Activate the plugin from WordPress Admin → Plugins
Zoho OAuth Setup
Step 1: Create OAuth Client
- Go to Zoho API Console
- Click Add Client
- Select Server-based Applications
- Fill in the details:
- Client Name: Your WordPress Site
- Homepage URL: Your website URL
- Authorized Redirect URIs: (You'll get this from WordPress settings)
Step 2: Get Organization ID (for Subscriptions)
- Go to Zoho Subscriptions
- Navigate to Settings → Organization
- Copy your Organization ID
Step 3: Configure Scopes
Make sure your OAuth client has these scopes enabled:
AaaServer.profile.READZohoSubscriptions.subscriptions.READ
WordPress Configuration
- Go to Settings → Zoho SSO in WordPress admin
- Enter your Client ID from Zoho
- Enter your Client Secret from Zoho
- Select your Zoho Domain (.com, .eu, .in, etc.)
- Enter your Organization ID (optional, for subscriptions)
- Copy the Redirect URI shown
- Go back to Zoho API Console and add this Redirect URI to your OAuth client
- Click Save Changes
Usage
Login Button
A "Sign in with Zoho" button automatically appears on the WordPress login page.
Check Active Subscription
// Check if current user has active subscription
$user_id = get_current_user_id();
if (Zoho_SSO::has_active_subscription($user_id)) {
echo "You have an active subscription!";
} else {
echo "No active subscription found.";
}
Get Subscription Details
// Get all subscription data
$user_id = get_current_user_id();
$details = Zoho_SSO::get_subscription_details($user_id);
echo "Customer ID: " . $details['customer_id'];
echo "Last Updated: " . $details['last_updated'];
// Loop through subscriptions
foreach ($details['subscriptions'] as $sub) {
echo "Plan: " . $sub['plan']['name'];
echo "Status: " . $sub['status'];
echo "Amount: " . $sub['amount'];
echo "Next Billing: " . $sub['next_billing_at'];
}
Restrict Content by Subscription
// In your theme template
if (!is_user_logged_in()) {
echo "Please log in to view this content.";
return;
}
if (!Zoho_SSO::has_active_subscription(get_current_user_id())) {
echo "This content requires an active subscription.";
return;
}
// Show premium content
echo "Welcome, premium member!";
Access Raw User Meta
$user_id = get_current_user_id();
// Get customer ID
$customer_id = get_user_meta($user_id, 'zoho_customer_id', true);
// Get all subscriptions
$subscriptions = get_user_meta($user_id, 'zoho_subscriptions', true);
// Get last sync time
$updated = get_user_meta($user_id, 'zoho_subscription_updated', true);
Subscription Statuses
Common subscription statuses returned by Zoho:
live- Active subscriptionactive- Active subscriptionnon_renewing- Active but will not renewcancelled- Cancelled subscriptionexpired- Expired subscriptiontrial- Trial period
Sample Implementation
Restrict Admin Access
// Add to functions.php
add_action('admin_init', function() {
if (!current_user_can('administrator')) {
$user_id = get_current_user_id();
if (!Zoho_SSO::has_active_subscription($user_id)) {
wp_redirect(home_url());
exit;
}
}
});
Show Subscription Info in Profile
// Add to functions.php
add_action('show_user_profile', 'show_zoho_subscription_info');
add_action('edit_user_profile', 'show_zoho_subscription_info');
function show_zoho_subscription_info($user) {
$details = Zoho_SSO::get_subscription_details($user->ID);
if (!$details['subscriptions']) {
return;
}
echo '<h3>Zoho Subscription Info</h3>';
echo '<table class="form-table">';
foreach ($details['subscriptions'] as $sub) {
echo '<tr>';
echo '<th>Plan</th>';
echo '<td>' . esc_html($sub['plan']['name']) . '</td>';
echo '</tr>';
echo '<tr>';
echo '<th>Status</th>';
echo '<td>' . esc_html($sub['status']) . '</td>';
echo '</tr>';
}
echo '</table>';
}
Custom Login Redirect
// Redirect based on subscription status
add_filter('login_redirect', function($redirect_to, $request, $user) {
if (isset($user->ID)) {
if (Zoho_SSO::has_active_subscription($user->ID)) {
return admin_url('index.php'); // Dashboard
} else {
return home_url('/subscribe'); // Subscribe page
}
}
return $redirect_to;
}, 10, 3);
Troubleshooting
"Invalid Callback" Error
- Make sure the Redirect URI in WordPress settings matches exactly in Zoho OAuth settings
- Check that the redirect URI doesn't have trailing slashes
"0" on Login Button Click
- Clear WordPress cache
- Deactivate and reactivate the plugin
- Check if pretty permalinks are enabled
No Subscription Data
- Verify Organization ID is correct
- Ensure the OAuth scope includes
ZohoSubscriptions.subscriptions.READ - Check that the user's email exists as a customer in Zoho Subscriptions
Users Can't Login
- Verify Client ID and Secret are correct
- Check that the Zoho domain setting matches your account (.com, .eu, etc.)
- Review Zoho API Console for any error logs
Security Notes
- Users are auto-created on first login
- Random passwords are generated (users can't login with username/password)
- Client Secret is stored in WordPress options (keep your database secure)
- Subscription data is synced on each login
Support
For Zoho OAuth issues, visit Zoho API Documentation
For Zoho Subscriptions API, visit Zoho Subscriptions API Docs
License
This plugin is provided as-is for integration purposes.