
Enables you to login to your WordPress site with your Nextcloud account with OAuth2
| Author: | Tim Oxendale (profile at wordpress.org) |
| WordPress version required: | 5.6 |
| WordPress version tested: | 7.2 |
| Plugin version: | 2.1.0 |
| Added to WordPress repository: | 11-02-2022 |
| Last updated: | 15-09-2026 |
| Rating, %: | 100 |
| Rated by: | 8 |
| Plugin URI: | https://www.timoxendale.co.uk/plugins/wordpre... |
| Total downloads: | 6 673 |
| Active installs: | 200+ |
![]() Click to start download |
|
Just a simple OAuth2 plugin so you can login to your WordPress site from Nextcloud, there is an option to add a login button on the WordPress login page and a shortcode so you can generate your own button. You can set what Nextcloud user groups get mapped to what WordPress user role and what page the users get redirected to on successful login. If you’re using the External sites app in Nextcloud you can set the URL as www.example.com/wp-login.php?nc-sso=redirect and it will auto redirect the user to your Nextcloud install to login without them having to click the login button.
The plugin has been tested with Nextcloud 20.0.14 to 34.0.4.
If you have any problems please reach out on the support forum or directly here.
Note this isn’t an official plugin from Nextcloud, it’s just from someone that uses it with WordPress alot.
Screenshots

Options Page

Options Page Step 4 User Actions Register

Options Page Step 4 User Actions Custom

Login Page
How do I set the plugin up?
If you go to the settings page (Settings -> Nextcloud OAuth2) it gives you a simple breakdown of what’s needed to setup the OAuth2 connection with your Nextcloud install.
- Login to your Nextcloud install
- Go to Settings -> Security
- Then under “OAuth 2.0 clients” add a new client
- Set the name to anything you like and the redirect URL to your site URL
- Then copy the Client Identifier and Secret keys in the form
What’s my Nextcloud URL?
This is the URL that you have installed Nextcloud at e.g. https://cloud.example.com/, if you have installed it in a subfolder, please include that e.g. https://example.com/cloud/. If your Nextcloud URLs look like https://example.com/index.php/apps/dashboard/ then please include the /index.php/ in the URL e.g. https://example.com/index.php/.
Where is the settings page?
It’s under Settings and called “Nextcloud OAuth2”
Is there a shortcode to add a login button?
Yes, it’s [nextcloud_login class=”btn”]button text[/nextcloud_login] and there is an option to enable a button on the WordPress login screen, or you can use the URL www.example.com/wp-login.php?nc-sso=redirect
How are Nextcloud accounts matched to WordPress accounts?
Each WordPress account is linked to a Nextcloud user ID, which Nextcloud users can’t change. Accounts the plugin creates are linked automatically. Existing WordPress users can link their account from their profile page (Users -> Profile -> Link my Nextcloud account), or an administrator can enter the Nextcloud user ID on the user’s edit screen. The Users list has a Nextcloud column showing who is linked.
The “Match Nextcloud users to existing WordPress accounts that aren’t linked yet” option (Settings -> Nextcloud OAuth2 -> Step 4) decides what happens the first time someone without a linked account logs in:
- “Nextcloud user ID only – existing users link from their profile (recommended)” – existing WordPress accounts are never matched, users link their account from their profile page. This is the default for new installs.
- “Nextcloud user ID, or email address on first login” – an existing account with the same email address as the Nextcloud user is linked on their first login.
- “Nextcloud user ID, or username on first login” – an existing account with a WordPress username the same as the Nextcloud user ID is linked on their first login.
Whichever you choose, once an account is linked every login after that uses the Nextcloud user ID. Only use the email address or username options if you control every Nextcloud account and users can’t change their own email address. Privileged accounts (administrators, editors, shop managers etc.) are never linked automatically.
I’ve updated to 2.1.0, will my site keep working?
Yes, your existing setup carries on working. Your Nextcloud URL, client ID, secret, roles, redirects and login button settings are all kept.
The old “How to match Nextcloud users to WordPress users” option has been replaced by “Match Nextcloud users to existing WordPress accounts that aren’t linked yet” in Settings -> Nextcloud OAuth2 -> Step 4. Your previous setting is carried over:
- “Email Address” becomes “Nextcloud user ID, or email address on first login”
- “Username” becomes “Nextcloud user ID, or username on first login”
Subscribers, customers and anyone else without editing or admin access carry on logging in with Nextcloud exactly as before. The first time each of them logs in their account is linked to their Nextcloud user ID, and from then on the Nextcloud user ID is used, even if they change their email address in Nextcloud.
If you create accounts for new users, that carries on working too. New accounts are linked to the Nextcloud user ID when they’re created.
The one change is for administrators, editors, authors, shop managers and any other account with editing or admin access. These are no longer matched by email address or username, as that’s what allowed someone to take over an administrator account. They need linking once, either:
- Log in with your WordPress username and password, go to Users -> Profile and click “Link my Nextcloud account”, or
- An administrator enters their Nextcloud user ID on their user edit screen (Users -> Edit -> Nextcloud account), or
- Link lots of users at once with WP-CLI (see “Can I link lots of users at once?” below).
After updating, a notice in the WordPress admin lists the accounts that still need linking, with a button to link your own account. Accounts the plugin created for privileged users have a random password, so use “Lost your password” on the login page to get in and link, or have an administrator enter their Nextcloud user ID.
Once everyone is linked you can switch Step 4 to “Nextcloud user ID only”, or click “Only match by Nextcloud user ID” in the notice, so accounts are never matched by email address or username again.
Are there any filters available so I can make my own changes?
Yes, there is:
tims_nso_authorize_url which is the Nextcloud URL the user gets redirected to, and is also the last hook before they go off to your install of Nextcloud, example:
add_filter('tims_nso_authorize_url', 'custom_function_name_one');
function custom_function_name_one($authorize_url){
// custom code
return $authorize_url;
}
tims_nso_successful_login_redirect which is the URL the user goes to after successfully coming back from Nextcloud, example:
add_filter('tims_nso_successful_login_redirect', 'custom_function_name_two');
function custom_function_name_two($redirect_url){
// custom code
return $redirect_url;
}
tims_nso_nextcloud_login_button_url which is the URL the login button and shortcode login button uses, example:
add_filter('tims_nso_nextcloud_login_button_url', 'custom_function_name_three');
function custom_function_name_three($url){
// custom code
return $url;
}
tims_nso_nextcloud_user_matched which is the WordPress WP_User (Object) and the user data (Object) from Nextcloud for the successful matched user, example:
add_filter('tims_nso_nextcloud_user_matched', 'custom_function_name_four', 10, 2);
function custom_function_name_four($user,$nextcloud){
// custom code
return $user;
}
tims_nso_is_privileged_user decides which accounts are never linked automatically by email address or username. By default this is any account that can do more than a subscriber or WooCommerce customer (edit posts, upload files, manage users, manage WooCommerce etc.). The example below also protects a custom capability:
add_filter('tims_nso_is_privileged_user', 'custom_function_name_five', 10, 2);
function custom_function_name_five($is_privileged, $user){
if(user_can($user, 'my_custom_capability')){
return true;
}
return $is_privileged;
}
Only make this return false if you control every Nextcloud account and users can’t change their own email address, otherwise someone could take over an administrator account.
tims_nso_instance which is the name of the Nextcloud server saved with each linked account (by default the host and path of your Nextcloud URL, e.g. cloud.example.org). Links made with a different server are ignored, so if you move Nextcloud to a new address you can use this to keep the existing links working, example:
add_filter('tims_nso_instance', 'custom_function_name_six');
function custom_function_name_six($instance){
// Nextcloud moved from cloud.old-example.org, keep using the old links
return 'cloud.old-example.org';
}
Are there any actions available?
Yes, tims_nso_user_linked runs when a WordPress account is linked to a Nextcloud account (from the profile page, by an administrator, when an account is created, or when it is linked automatically), and tims_nso_user_unlinked runs when the link is removed, example:
add_action('tims_nso_user_linked', 'custom_function_name_seven', 10, 2);
function custom_function_name_seven($user_id, $nextcloud_user_id){
// custom code
}
add_action('tims_nso_user_unlinked', 'custom_function_name_eight');
function custom_function_name_eight($user_id){
// custom code
}
The standard WordPress wp_login action also runs after a successful Nextcloud login.
Are there any settings I can add to wp-config.php?
Yes, there are:
NEXTCLOUD_SECRET to store your Nextcloud secret key in wp-config.php instead of the database:
define('NEXTCLOUD_SECRET', 'Your Secret key');
TIMS_NSO_LOG_FILE to choose where the debug log is saved, ideally somewhere outside your web root. By default it’s saved in wp-content/uploads/tims-nso-logs/ with a random file name:
define('TIMS_NSO_LOG_FILE', '/home/example/logs/nextcloud-sso.log');
Can I link lots of users at once?
Yes, the link is saved in two user meta fields, tims_nso_nc_uid (the Nextcloud user ID) and tims_nso_nc_instance (the Nextcloud server, see the tims_nso_instance filter above). For example, with WP-CLI:
wp user meta update 12 tims_nso_nc_uid "jsmith"
wp user meta update 12 tims_nso_nc_instance "cloud.example.org"
Use the Nextcloud user ID (login name), not the display name. The Nextcloud column on the Users list shows who is linked, and shows “(other server)” if the instance doesn’t match.
I’m getting a “Nextcloud server returned but with an invalid state for this session” error
Before you go off to Nextcloud the site needs to store a unique key to verify the response when you come back, if this key is removed before you come back this is when you see this message.
By default, the key is stored in the PHP session but if you’re having trouble you can go into the plugin options and set the “Storage Type” to use a Cookie and this should solve the issue.
I’m stuck on my Nextcloud install when I click “Grant access”, it doesn’t do anything?
If you check the JS console log and see a message like “Refused to send form data to … because it violates the following Content Security Policy directive….” then you need to edit your Nextcloud config file, usually located at nextcloud/config/config.php and add the line: ‘overwriteprotocol’ => ‘https’,
Can I test new versions before they are released?
Sometimes a new version is available to test before it is released. If there is one, you can download it from the Advanced tab on this plugin’s page (Development Version, under Previous Versions). Please test it on a staging site first, and let me know how it goes on the support forum. Your site will update to the full release automatically when it comes out.
A test version of 2.2.0 is available now. It adds an option to keep WordPress roles in sync with Nextcloud groups on every login.
Is there a paid version?
Nope, just a simple free plugin to enable you to login to your site with Nextcloud.
Where do I report security bugs found in this plugin?
Please report security bugs found in the source code of the Tim’s Nextcloud SSO OAuth2 plugin through the Patchstack Vulnerability Disclosure Program. The Patchstack team will assist you with verification, CVE assignment, and notify the developers of this plugin.
I need help
If you have any problems please reach out on the support forum or directly here. I’ll try my best to help.
2.1.0
Release Date: 26th November 2026
Security fix, please update.
- Security: WordPress accounts are now linked to the Nextcloud user ID, which Nextcloud users can’t change. The email address and username from Nextcloud are no longer used to log in once an account is linked
- Security: Administrators, editors, shop managers and other privileged accounts are never matched automatically by email address or username, they need linking once from their profile page or by an administrator
- Security: Matching existing accounts by email address or username is now off by default for new installs. Existing sites keep their current setting so normal users carry on as before and are linked on their next login
- Security: Added a nonce check to the Test Connection option
- Security: The debug log now has a random file name in a protected folder and access tokens are removed. The old log file is deleted
- Security: The state cookie is now signed and HttpOnly, and the Nextcloud secret is no longer shown in the settings page source
- Security: The login button URL is now escaped in the shortcode
- New: Link or unlink your Nextcloud account from your WordPress profile page
- New: Administrators can set a user’s Nextcloud user ID on the user edit screen, and the Users list shows who is linked
- New: Admin notice listing accounts that still need linking, with an option to only match by Nextcloud user ID
- New: The wp_login action now runs after a Nextcloud login, so security and activity log plugins record it
- Fix: Disabled Nextcloud users now see the correct error message
- Fix: The plugin no longer interferes with other plugins that return to the site with state and code in the URL
- Updated the FAQ and translation files
- Tested with WordPress 7.2 and Nextcloud 35.0.3
2.0.3
Release Date: 22nd May 2025
- Improvements made to the Test Connection option in the settings
- Updated compatibility with WordPress 6.8.1 and Nextcloud 31.0.4
2.0.2
Release Date: 10th August 2023
- Implemented a feature request: When matching Nextcloud user groups to WordPress roles If no role matches there is now an option to select a default role for the user
- Corrected spelling mistakes on the options page
2.0.1
Release Date: 1st July 2022
- Added some filter hooks
2.0.0
Release Date: 27th June 2022
- Revamped the options page to be more visually pleasing
- Added the option to redirect the user back to where they were
- The shortcode login button is now hidden if the user is already logged in
- Debug log contains more information
1.9
Release Date: 23rd May 2022
- Organised the options page
- Added a button to test the Nextcloud URL
- Added some filter hooks
1.8
Release Date: 19th May 2022
- Added additional checks when entering the Nextcloud URL
1.7
Release Date: 6th May 2022
- Updated compatibility with WordPress 6.1 and Nextcloud 24.0.0
- Added some more FAQs
- Made an error message more descriptive
1.6
Release Date: 18th March 2022
- Made improvements to the way session data is stored when going between WordPress and Nextcloud
1.5
Release Date: 17th March 2022
- Built in an option to store unique keys that are needed to verify the response back from Nextcloud as a PHP session or Cookie.
1.4
Release Date: 17th March 2022
- Made improvements to the way session data is stored when going between WordPress and Nextcloud
- Tested compatibility with WordPress 5.9.3
1.3
Release Date: 25th February 2022
- Updated to be compatible with older Nextcloud installs
- Logs more useful information to debug file when enabled
1.2
Release Date: 25th February 2022
- Fixed issues with URLs that include /index.php/
1.1
Release Date: 25th February 2022
- Added a new option to log debug information to a file
1.0
Release Date: 11th February 2022
- Initial release.
