Implementation of Nextcloud Authentication

My version of HedgeDoc is: 1.9.3 (Docker)

What I expected to happen:

I wanted to link Nextcloud to HedgeDoc, in order to enable the users authenticating from their Nextcloud account.

What actually happened:

Internal Server Error on the callback

I added these environment variables :

CMD_OAUTH2_CLIENT_ID=xxxxxxxxxx
CMD_OAUTH2_CLIENT_SECRET=xxxxxxxxxx
CMD_OAUTH2_AUTHORIZATION_URL=https://Nextcloud_URL/index.php/apps/oauth2/authorize
CMD_OAUTH2_TOKEN_URL=https://Nextcloud_URL/index.php/apps/oauth2/api/v1/token
CMD_OAUTH2_USER_PROFILE_URL=https://Nextcloud_URL/ocs/v2.php/cloud/user?format=json
CMD_OAUTH2_USER_PROFILE_USERNAME_ATTR=ocs.data.id
CMD_OAUTH2_USER_PROFILE_DISPLAY_NAME_ATTR=ocs.data.display-name
CMD_OAUTH2_USER_PROFILE_EMAIL_ATTR=ocs.data.email

I already tried:

  • To authenticate myself, I can display the button ‘connect from Nextcloud’, and the authentication form by ‘Nextcloud’ is OK.
  • After the authentication, I granted the access from Nextcloud to the HedgeDoc app, but after that, I have an Internal Server Error in the callback process.

Here is the log part :

InternalOAuthError: Failed to obtain access token
    at OAuth2CustomStrategy.OAuth2Strategy._createOAuthError (/hedgedoc/node_modules/passport-oauth2/lib/strategy.js:423:17)
    at /hedgedoc/node_modules/passport-oauth2/lib/strategy.js:177:45
    at /hedgedoc/node_modules/oauth/lib/oauth2.js:191:18
    at ClientRequest.<anonymous> (/hedgedoc/node_modules/oauth/lib/oauth2.js:162:5)
    at ClientRequest.emit (node:events:527:28)
    at Socket.socketErrorListener (node:_http_client:454:9)
    at Socket.emit (node:events:527:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
2022-06-22T09:40:09.399Z info: 	1.2.3.4 - - [22/Jun/2022:09:40:09 +0000] "GET /auth/oauth2/callback?state=ZgbaUeo8aGM8FkZE1ZJqCA7l&code=k4YYPHhqkIE7m8HXi7TJrErXYurjVVb7VscX6DSXJJCakeOHtxL7DLpBOUznlcCStEaiJw0xaGIzYhrg5tCkb5yvSD36iqpzjYqCl78diWDQ7qjCLQ77bb96oi5cHwPD HTTP/1.1" 500 148 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Firefox/102.0"

Thanks