Skip to content

Commit 897bd06

Browse files
committed
fix: don't use token in URL
1 parent 415b840 commit 897bd06

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

docs/more-pushmsg.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ All examples assume Gotify is running on `http://localhost:8008`. Replace `<appt
1111
TITLE="My Title"
1212
MESSAGE="Hello: ![](https://gotify.net/img/logo.png)"
1313
PRIORITY=5
14-
URL="http://localhost:8008/message?token=<apptoken>"
14+
TOKEN="<apptoken>"
15+
URL="http://localhost:8008/message"
1516

16-
curl -s -S --data '{"message": "'"${MESSAGE}"'", "title": "'"${TITLE}"'", "priority":'"${PRIORITY}"', "extras": {"client::display": {"contentType": "text/markdown"}}}' -H 'Content-Type: application/json' "$URL"
17+
curl -s -S --data '{"message": "'"${MESSAGE}"'", "title": "'"${TITLE}"'", "priority":'"${PRIORITY}"', "extras": {"client::display": {"contentType": "text/markdown"}}}' -H 'Content-Type: application/json' -H "X-Gotify-Key: $TOKEN" "$URL"
1718
```
1819

1920
## Python
2021

2122
```python
2223
import requests #pip install requests
23-
resp = requests.post('http://localhost:8008/message?token=<apptoken>', json={
24+
resp = requests.post('http://localhost:8008/message', headers={"X-Gotify-Key": "<apptoken>"}, json={
2425
"message": "Well hello there.",
2526
"priority": 2,
2627
"title": "This is my title"
@@ -35,11 +36,15 @@ package main
3536
import (
3637
"net/http"
3738
"net/url"
39+
"strings"
3840
)
3941

4042
func main() {
41-
http.PostForm("http://localhost:8008/message?token=<apptoken>",
42-
url.Values{"message": {"My Message"}, "title": {"My Title"}})
43+
form := url.Values{"message": {"My Message"}, "title": {"My Title"}}
44+
req, _ := http.NewRequest("POST", "http://localhost:8008/message", strings.NewReader(form.Encode()))
45+
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
46+
req.Header.Set("X-Gotify-Key", "<apptoken>")
47+
http.DefaultClient.Do(req)
4348
}
4449
```
4550

@@ -54,10 +59,11 @@ $data = [
5459

5560
$data_string = json_encode($data);
5661

57-
$url = "http://localhost:8008/message?token=<apptoken>";
62+
$url = "http://localhost:8008/message";
5863

5964
$headers = [
60-
"Content-Type: application/json; charset=utf-8"
65+
"Content-Type: application/json; charset=utf-8",
66+
"X-Gotify-Key: <apptoken>"
6167
];
6268

6369
$ch = curl_init();
@@ -98,7 +104,7 @@ switch ($code) {
98104
```javascript
99105
const axios = require('axios');
100106

101-
const url = 'http://localhost:8008/message?token=<apptoken>';
107+
const url = 'http://localhost:8008/message';
102108
const bodyFormData = {
103109
title: 'Hello from Javascript',
104110
message: 'Test Push Service from Node.js',
@@ -109,6 +115,7 @@ axios({
109115
method: 'post',
110116
headers: {
111117
'Content-Type': 'application/json',
118+
'X-Gotify-Key': '<apptoken>',
112119
},
113120
url: url,
114121
data: bodyFormData,
@@ -157,11 +164,13 @@ public class GotifyClient {
157164
}
158165

159166
private final String gotifyUrl;
167+
private final String token;
160168
private final HttpClient httpClient;
161169
private final ObjectMapper objectMapper;
162170

163171
public GotifyClient(String baseUrl, String token) {
164-
this.gotifyUrl = String.format("%s/message?token=%s", baseUrl, token);
172+
this.gotifyUrl = baseUrl + "/message";
173+
this.token = token;
165174
this.httpClient = HttpClient.newHttpClient();
166175
this.objectMapper = new ObjectMapper();
167176
}
@@ -172,6 +181,7 @@ public class GotifyClient {
172181
final var request = HttpRequest.newBuilder()
173182
.uri(URI.create(gotifyUrl))
174183
.header("Content-Type", "application/json")
184+
.header("X-Gotify-Key", token)
175185
.POST(HttpRequest.BodyPublishers.ofString(bodyData))
176186
.build();
177187

@@ -205,7 +215,8 @@ public class GotifyClient {
205215
## VB/VBA
206216

207217
```vb
208-
Const GOTIFY_URL As String = "http://localhost:8008/message?token=<apptoken>"
218+
Const GOTIFY_URL As String = "http://localhost:8008/message"
219+
Const GOTIFY_TOKEN As String = "<apptoken>"
209220

210221
'--- Based on pushover-vba by Mauricio Arieira (https://github.com/makah/pushover-vba)
211222
Public Function PushToGotify(ByVal title As String, ByVal message As String, ByVal priority As Integer) As String
@@ -215,6 +226,7 @@ Public Function PushToGotify(ByVal title As String, ByVal message As String, ByV
215226
With xhttp
216227
.Open "POST", GOTIFY_URL, False
217228
.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
229+
.setRequestHeader "X-Gotify-Key", GOTIFY_TOKEN
218230
.Send params
219231
PushToGotify = .responseText
220232
End With
@@ -234,5 +246,5 @@ subject="wget"
234246
message="Test push from wget"
235247
priority=5
236248

237-
wget "http://localhost:8008/message?token=$token" --post-data "title=$subject&message=$message&priority=$priority" -O /dev/null
249+
wget "http://localhost:8008/message" --header "X-Gotify-Key: $token" --post-data "title=$subject&message=$message&priority=$priority" -O /dev/null
238250
```

docs/pushmsg.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ The token is returned when creating the application. Starting with Gotify 3, tok
1313
Now you can use [curl](https://curl.se/), [HTTPie](https://httpie.io/) or any other HTTP client to push messages.
1414

1515
```bash
16-
$ curl "https://push.example.de/message?token=<apptoken>" -F "title=my title" -F "message=my message" -F "priority=5"
17-
$ http -f POST "https://push.example.de/message?token=<apptoken>" title="my title" message="my message" priority="5"
16+
$ curl "https://push.example.de/message" -H "X-Gotify-Key: <apptoken>" -F "title=my title" -F "message=my message" -F "priority=5"
17+
$ http -f POST "https://push.example.de/message" "X-Gotify-Key:<apptoken>" title="my title" message="my message" priority="5"
1818
```
1919

2020
On Microsoft PowerShell, you can use the built-in `Invoke-RestMethod` or `Invoke-WebRequest` cmdlets.
2121

2222
```powershell
23-
PS> Invoke-RestMethod -Uri "https://push.example.de/message?token=<apptoken>" -Method POST -Body @{title="my title"; message="my message"; priority=5} # return is automatically parsed into a PowerShell object
24-
PS> Invoke-WebRequest -Uri "https://push.example.de/message?token=<apptoken>" -Method POST -Body @{title="my title"; message="my message"; priority=5} # return is as raw response
23+
PS> Invoke-RestMethod -Uri "https://push.example.de/message" -Headers @{"X-Gotify-Key"="<apptoken>"} -Method POST -Body @{title="my title"; message="my message"; priority=5} # return is automatically parsed into a PowerShell object
24+
PS> Invoke-WebRequest -Uri "https://push.example.de/message" -Headers @{"X-Gotify-Key"="<apptoken>"} -Method POST -Body @{title="my title"; message="my message"; priority=5} # return is as raw response
2525
```
2626

2727
> The message API takes an `extras` property that carries extra information with the message and describes how clients should handle it.

0 commit comments

Comments
 (0)