Skip to content

Commit

Permalink
feat(ntfy): Add access token authentication
Browse files Browse the repository at this point in the history
This fixes #757
  • Loading branch information
ffflorian committed Nov 19, 2024
1 parent cf3c1f9 commit 1132e81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/ntfy/src/NtfyClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ export async function publish<T extends Config>(config: T): Promise<ResponseData

if (config.authorization) {
axiosConfig.withCredentials = true;
axiosConfig.auth = config.authorization;
if (typeof config.authorization === 'string') {
axiosConfig.headers.Authorization = config.authorization;
} else {
axiosConfig.auth = config.authorization;
}
}

if (config.delay) {
Expand Down
6 changes: 4 additions & 2 deletions packages/ntfy/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {AxiosBasicCredentials as HTTPAuth, Method as HTTPMethod} from 'axios';
import type {AxiosBasicCredentials, Method as HTTPMethod} from 'axios';

export enum MessagePriority {
/** Really long vibration bursts, default notification sound with a pop-over notification. */
Expand Down Expand Up @@ -141,8 +141,10 @@ export interface BaseConfig {
* Depending on whether the server is configured to support
* [access control](https://docs.ntfy.sh/config/#access-control), some topics may be read/write protected so that only
* users with the correct credentials can subscribe or publish to them.
*
* Use either basic credentials or an access token.
*/
authorization?: HTTPAuth;
authorization?: AxiosBasicCredentials | string;
/**
* You can define which URL to open when a notification is clicked. This may be useful if your notification is related
* to a Zabbix alert or a transaction that you'd like to provide the deep-link for. Tapping the notification will open
Expand Down

0 comments on commit 1132e81

Please sign in to comment.