Skip to content

Commit 1132e81

Browse files
committed
feat(ntfy): Add access token authentication
This fixes #757
1 parent cf3c1f9 commit 1132e81

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/ntfy/src/NtfyClient.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ export async function publish<T extends Config>(config: T): Promise<ResponseData
125125

126126
if (config.authorization) {
127127
axiosConfig.withCredentials = true;
128-
axiosConfig.auth = config.authorization;
128+
if (typeof config.authorization === 'string') {
129+
axiosConfig.headers.Authorization = config.authorization;
130+
} else {
131+
axiosConfig.auth = config.authorization;
132+
}
129133
}
130134

131135
if (config.delay) {

packages/ntfy/src/interfaces.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {AxiosBasicCredentials as HTTPAuth, Method as HTTPMethod} from 'axios';
1+
import type {AxiosBasicCredentials, Method as HTTPMethod} from 'axios';
22

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

0 commit comments

Comments
 (0)