How to Authenticate via OAuth2 in Nextcloud Apps

Hey everyone,

I’m working on an app integration with Nextcloud and need to implement OAuth2 authentication. I’ve checked the official Nextcloud OAuth2 documentation, but I’m still unclear on a few points:

  • How do I correctly register my app to get the client ID/secret?
  • What’s the proper flow for exchanging authorization codes with Nextcloud’s endpoints?
  • Any gotchas with token refresh or scopes I should watch out for?
  • How do you handle OAuth2 in mobile or desktop apps that integrate with Nextcloud?
  • Are there any example implementations or code snippets you can share (PHP, Python, JS)?

If anyone has step-by-step instructions or real-world examples of OAuth2 integration with Nextcloud apps, it’d be super helpful.

Thanks in advance!

Hey,

I am not sure what you want to achieve. Please elaborate bit more:

  • Do you want to allow users of a foreign app with NC such that they do no longer need to login using NC credentials but instead your app’s credentials?
  • Do you have an external app with independent users from these in NC. You want your users to access their own files stored in NC from within the external app?
  • You want to use NC as an auth provider for your external app?
  • Something else?

Unfortunately, OAuth2 is not trivial and one has to be super-precise on the goal before doing anything there (especially as it is security related).

Chris