|
| 1 | +Authentication guide - Nextcloud (self-hosted) |
| 2 | +=== |
| 3 | + |
| 4 | +*This has been constructed using the [Nextcloud OAuth2 Documentation](https://docs.nextcloud.com/server/14/admin_manual/configuration_server/oauth2.html?highlight=oauth2) combined with [this issue comment on the nextcloud bugtracker](https://github.com/nextcloud/server/issues/5694#issuecomment-314761326).* |
| 5 | + |
| 6 | +This guide uses the generic OAuth2 module for compatibility with Nextcloud 13 and above (this guide has been tested successfully with Nextcloud 14). |
| 7 | + |
| 8 | +1. Sign-in with an administrator account to your Nextcloud server |
| 9 | + |
| 10 | +2. Navigate to the OAuth integration settings: Profile Icon (top right) --> Settings |
| 11 | + Then choose Security Settings from the *Administration* part of the list - Don't confuse this with Personal Security Settings, where you would change your personal password! |
| 12 | + At the top there's OAuth 2.0-Clients. |
| 13 | +  |
| 14 | + |
| 15 | +3. Add your CodiMD instance by giving it a *name* (perhaps CodiMD, but could be anything) and a *Redirection-URI*. The Redirection-URI will be `\<your-codimd-url\>/auth/oauth2/callback`. Click <kbd>Add</kbd>. |
| 16 | +  |
| 17 | + |
| 18 | + |
| 19 | +4. You'll now see a line containing a *client identifier* and a *Secret*. |
| 20 | +  |
| 21 | + |
| 22 | +5. That's it for Nextcloud, the rest is configured in your CodiMD `config.json` or via the `CMD_` environment variables! |
| 23 | + |
| 24 | +6. Add the Client ID and Client Secret to your `config.json` file or pass them as environment variables. Make sure you also replace `<your-nextcloud-domain>` with the right domain name. |
| 25 | + * `config.json`: |
| 26 | + ```javascript |
| 27 | + { |
| 28 | + "production": { |
| 29 | + "oauth2": { |
| 30 | + "clientID": "ii4p1u3jz7dXXXXXXXXXXXXXXX", |
| 31 | + "clientSecret": "mqzzx6fydbXXXXXXXXXXXXXXXX", |
| 32 | + "authorizationURL": "https://<your-nextcloud-domain>/apps/oauth2/authorize", |
| 33 | + "tokenURL": "https://<your-nextcloud-domain>/apps/oauth2/api/v1/token", |
| 34 | + "userProfileURL": "https://<your-nextcloud-domain>/ocs/v2.php/cloud/user?format=json", |
| 35 | + "userProfileUsernameAttr": "ocs.data.id", |
| 36 | + "userProfileDisplayNameAttr": "ocs.data.display-name", |
| 37 | + "userProfileEmailAttr": "ocs.data.email" |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + ``` |
| 42 | + * environment variables: |
| 43 | + ```sh |
| 44 | + CMD_OAUTH2_CLIENT_ID=ii4p1u3jz7dXXXXXXXXXXXXXXX |
| 45 | + CMD_OAUTH2_CLIENT_SECRET=mqzzx6fydbXXXXXXXXXXXXXXXX |
| 46 | + CMD_OAUTH2_AUTHORIZATION_URL=https://<your-nextcloud-domain>/apps/oauth2/authorize |
| 47 | + CMD_OAUTH2_TOKEN_URL=https://<your-nextcloud-domain>/apps/oauth2/api/v1/token |
| 48 | + CMD_OAUTH2_USER_PROFILE_URL=https://<your-nextcloud-domain>/ocs/v2.php/cloud/user?format=json |
| 49 | + CMD_OAUTH2_USER_PROFILE_USERNAME_ATTR=ocs.data.id |
| 50 | + CMD_OAUTH2_USER_PROFILE_DISPLAY_NAME_ATTR=ocs.data.display-name |
| 51 | + CMD_OAUTH2_USER_PROFILE_EMAIL_ATTR=ocs.data.email |
| 52 | + ``` |
0 commit comments