OAuth 2.0

Administrators can register OAuth 2.0 clients so users can authorize external applications to access their Nextcloud accounts. Nextcloud supports confidential clients using the authorization code flow. PKCE is not supported. See RFC 6749 for the OAuth 2.0 specification.

Register a client

In the administrator Security settings, add an OAuth 2.0 client.

../_images/oauth2-settings.png

Enter a name and the redirect URL provided by the external application. Copy the client ID and client secret into the application’s OAuth 2.0 configuration. Store the secret securely: it cannot be retrieved after leaving the settings page.

The application should use the following endpoints:

  • Authorization: https://cloud.example.org/apps/oauth2/authorize

  • Token: https://cloud.example.org/apps/oauth2/api/v1/token

Replace https://cloud.example.org with your Nextcloud base URL, including any installation subdirectory. If pretty URLs are not configured, include index.php in both endpoint URLs, for example:

  • https://cloud.example.org/index.php/apps/oauth2/authorize

  • https://cloud.example.org/index.php/apps/oauth2/api/v1/token

Access tokens

The application sends the access token as a bearer token in the HTTP Authorization header:

Authorization: Bearer <TOKEN>

Note

Ensure your web server passes this header to PHP. The configuration required for Apache depends on how PHP is deployed; see the Apache installation guidance.

Access tokens expire after one hour. Clients can use a refresh token to obtain a new access token; each successful refresh replaces both tokens, invalidating the previous ones.

Security considerations

Nextcloud does not support OAuth scope negotiation. A newly authorized client initially receives broad access to the user’s account, including read and write access to files. Only register trusted applications, and store client secrets and tokens securely.

Added in version 36: Users can restrict a token’s access in their security settings using Edit access .

Note

OAuth 2.0 is an authorization protocol, not an authentication protocol. Because clients receive broad account permissions by default, using a Nextcloud instance solely as a user sign-in (SSO) provider is not recommended.

Skip the initial login prompt

The default OAuth 2.0 flow shows an initial login prompt and a separate authorization step. For a trusted application, you can skip the initial prompt by setting skipAuthPickerApplications with occ:

sudo -E -u www-data php occ config:app:set oauth2 skipAuthPickerApplications --type array --value '["myapplication"]'

Replace myapplication with the registered client name and www-data with your HTTP user if different. This command replaces the existing list, so include all client names that should skip the prompt. The authorization step is still shown.