Skip to content

Improve ntfy documentation on authorization and/or add authorization header #673

@codebude

Description

@codebude

Introduction

Ntfy supports two authorization types: username + password and tokens. (See: https://docs.ntfy.sh/publish/#authentication ) For server to server or application communication (as in the case of mqttwarn) tokens are the means of choice. Currently, the documentation of the mqttwarn ntfy service only assumes username + password (see: https://mqttwarn.readthedocs.io/en/latest/notifier-catalog.html#ntfy).
The login method shown in the documentation (via url-property: https://:@/) does not work for token authorization.

Proposal

I suggest adding another example that demonstrates how to use token authentication.

Solution A

(This variant works without the need to customize the ntfy service.)

Add something like the following to the documentation:

In addition to passing username+password via URI, you can authorize your requests with a token (or username + password), by appending the auth information to the auth parameter.

[config:ntfy]
targets  = {
    'test': 'http://localhost:5555/testdrive?auth=<auth_info>',
    }

The <auth_info> itself must be base64 encoded information in the following formats:

Solution B

(This variant needs work on the ntfy service.)

Instead of using the auth-query parameter authorization information could be passed via the Authorization http header. Unfortunately the ntfy-service doesn't pass this header. My proposal for solution B) would be add authorization to the list of allowed fields in NTFY_FIELD_NAMES (https://github.com/mqtt-tools/mqttwarn/blob/main/mqttwarn/services/ntfy.py#LL32C1-L32C17)

Then add the following example to the documention:

[config:ntfy]
targets  = {
    'test':  {
        'url': 'http://localhost:5555/testdrive',
        'authorization': 'Bearer tk_1234567890'
    }

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions