Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ntfy trigger not working with authentication on a selfhosted instance #482

Closed
nstoik opened this issue Nov 12, 2024 · 4 comments · Fixed by #483
Closed

Ntfy trigger not working with authentication on a selfhosted instance #482

nstoik opened this issue Nov 12, 2024 · 4 comments · Fixed by #483
Assignees
Labels
bug Something isn't working

Comments

@nstoik
Copy link

nstoik commented Nov 12, 2024

When trying to configure a Ntfy trigger to my selfhosted Ntfy instance using authentication, the WUD docker logs show error 403 forbidden.

I have tried with both username and password and a token with the same result. Both the username and password and the token were verified to be working outside of the WUD container.

I configured it to connect to the public ntfy.sh server and the notification worked as expected. It is only when sending to my selfhosted instance that requires authentication that it is failing.

Docker compose environment options for WUD:

    environment:
        - WUD_TRIGGER_NTFY_SELFHOSTED_URL=https://xxxxxxxxxxxxxxx
        - WUD_TRIGGER_NTFY_SELFHOSTED_TOPIC=wud
        - WUD_TRIGGER_NTFY_SELFHOSTED_PRIORITY=2
        - WUD_TRIGGER_NTFY_SELFHOSTED_AUTH_USER=xxxxxxx
        - WUD_TRIGGER_NTFY_SELFHOSTED_AUTH_PASSWORD=xxxxxxxxxxxxxxxxxxxxx
        - WUD_TRIGGER_NTFY_SELFHOSTED_MODE=batch
        - WUD_WATCHER_LOCAL_SOCKET=/var/run/docker.sock

WUD docker logs:

01:13:35.842  INFO whats-up-docker/watcher.docker.local: Cron finished (6 containers watched, 0 errors, 5 available updates)
01:13:35.986  WARN whats-up-docker/trigger.ntfy.selfhosted: Error (403 - {"code":40301,"http":403,"error":"forbidden","link":"https://ntfy.sh/docs/publish/#authentication"})
01:13:35.987 DEBUG whats-up-docker/trigger.ntfy.selfhosted: 403 - {"code":40301,"http":403,"error":"forbidden","link":"https://ntfy.sh/docs/publish/#authentication"}
    StatusCodeError: 403 - {"code":40301,"http":403,"error":"forbidden","link":"https://ntfy.sh/docs/publish/#authentication"}
        at new StatusCodeError (/home/node/app/node_modules/request-promise-native/node_modules/request-promise-core/lib/errors.js:32:15)
        at plumbing.callback (/home/node/app/node_modules/request-promise-native/node_modules/request-promise-core/lib/plumbing.js:104:33)
        at Request.RP$callback [as _callback] (/home/node/app/node_modules/request-promise-native/node_modules/request-promise-core/lib/plumbing.js:46:31)
        at self.callback (/home/node/app/node_modules/request/request.js:185:22)
        at Request.emit (node:events:517:28)
        at Request.emit (node:domain:489:12)
        at Request.<anonymous> (/home/node/app/node_modules/request/request.js:1154:10)
        at Request.emit (node:events:517:28)
        at Request.emit (node:domain:489:12)
        at IncomingMessage.<anonymous> (/home/node/app/node_modules/request/request.js:1076:12)
        at Object.onceWrapper (node:events:631:28)
        at IncomingMessage.emit (node:events:529:35)
        at IncomingMessage.emit (node:domain:489:12)
        at endReadableNT (node:internal/streams/readable:1400:12)
        at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
@joost471
Copy link

joost471 commented Nov 12, 2024

First: thanks for the new feature! Now I can stop using a nodered-service to reformat a WUD-post-request so ntfy can understand it :).

Unfortunately I'm also unable to get authentication working.

Looking at the code, I think the issue is at the if-structures at line 78 (user/password) and 84 (bearer-token) in the ntfy.js file.
The if-clause checks this.configuration.user and this.configuration.password but then uses this.configuration.auth.user and this.configuration.auth.password.
(I'm unfamiliar with this programming language, so I could be wrong.)

 if (this.configuration.auth && this.configuration.user && this.configuration.password) {
     options.auth = {
         user: this.configuration.auth.user,
         pass: this.configuration.auth.password,
     };
 }

Should be

 if (this.configuration.auth && this.configuration.auth.user && this.configuration.auth.password) {
     ...
 }

Same for the token-if: checks this.configuration.token, uses this.configuration.auth.bearer

        if (this.configuration.auth && this.configuration.token) {
            options.auth = {
                bearer: this.configuration.auth.bearer,
            };
        }

Should be (using this.configuration.auth.token as per the docs, but could be wrong here)

        if (this.configuration.auth && this.configuration.auth.token) {
            options.auth = {
                bearer: this.configuration.auth.token,
            };
        }

@fmartinou fmartinou self-assigned this Nov 12, 2024
@fmartinou fmartinou added the bug Something isn't working label Nov 12, 2024
@fmartinou
Copy link
Collaborator

Thank you both for your feedback and your analysis 👍 .

Actually I didn't test that part by a lack of time (or laziness 🤔 )...
@joost471 you're right; there is a glitch with the condition; I'm going to fix it.

@fmartinou fmartinou linked a pull request Nov 12, 2024 that will close this issue
@fmartinou
Copy link
Collaborator

Released in 7.1.1

@joost471
Copy link

And it works! Thanks for the great app and the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants