Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e8052d

Browse files
committed
Removed the token parameter and fixed the TransportFactory to work without user parameter
per the discussion on the PR symfony#53594
1 parent 88cb509 commit 0e8052d

File tree

5 files changed

+12
-22
lines changed

5 files changed

+12
-22
lines changed

src/Symfony/Component/Notifier/Bridge/Ntfy/NtfyTransport.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ final class NtfyTransport extends AbstractTransport
3030
protected const HOST = 'ntfy.sh';
3131
private ?string $user = null;
3232
private ?string $password = null;
33-
private ?string $token = null;
3433

3534
public function __construct(private string $topic, private bool $secureHttp = true, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
3635
{
@@ -42,13 +41,6 @@ public function getTopic(): string
4241
return $this->topic;
4342
}
4443

45-
public function setToken(?string $token): self
46-
{
47-
$this->token = $token;
48-
49-
return $this;
50-
}
51-
5244
public function setPassword(?string $password): self
5345
{
5446
$this->password = $password;
@@ -92,8 +84,8 @@ protected function doSend(MessageInterface $message): SentMessage
9284

9385
if (null !== $this->user && null !== $this->password) {
9486
$headers['Authorization'] = 'Basic '.rtrim(base64_encode($this->user.':'.$this->password), '=');
95-
} elseif (null !== $this->token) {
96-
$headers['Authorization'] = 'Bearer '.$this->token;
87+
} elseif (null !== $this->password) {
88+
$headers['Authorization'] = 'Bearer '. $this->password;
9789
}
9890

9991
$response = $this->client->request('POST', ($this->secureHttp ? 'https' : 'http').'://'.$this->getEndpoint(), [

src/Symfony/Component/Notifier/Bridge/Ntfy/NtfyTransportFactory.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ public function create(Dsn $dsn): TransportInterface
4141
$transport->setPort($port);
4242
}
4343

44-
if (!empty($token = $dsn->getOption('token'))) {
45-
$transport->setToken($token);
44+
if (!empty($user = $dsn->getUser())) {
45+
$transport->setUser($user);
4646
}
4747

48-
if (!empty($user = $dsn->getUser()) && !empty($password = $dsn->getPassword())) {
49-
$transport->setUser($user);
48+
if (!empty($password = $dsn->getPassword())) {
5049
$transport->setPassword($password);
5150
}
5251

src/Symfony/Component/Notifier/Bridge/Ntfy/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ DSN example
77
-----------
88

99
```
10-
NTFY_DSN=ntfy://[USER:PASSWORD]@default[:PORT]/TOPIC?[secureHttp=[on]]&[token=[:TOKEN]]
10+
NTFY_DSN=ntfy://[USER:PASSWORD]@default[:PORT]/TOPIC?[secureHttp=[on]]
1111
```
1212
where:
1313
- `URL` is the ntfy server which you are using
1414
- if `default` is provided, this will default to the public ntfy server hosted on [ntfy.sh](https://ntfy.sh/).
1515
- `TOPIC` is the topic on this ntfy server.
1616
- `PORT` is an optional specific port.
1717
- `USER`and `PASSWORD` are username and password in case of access control supported by the server
18-
- `TOKEN` is the access token in case of access control supported by the server
1918

2019
In case of a non-secure server, you can disable https by setting `secureHttp=off`. For example if you use a local [Ntfy Docker image](https://hub.docker.com/r/binwiederhier/ntfy) during development or testing.
2120

src/Symfony/Component/Notifier/Bridge/Ntfy/Tests/NtfyTransportFactoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ public static function createProvider(): iterable
3232
'ntfy://user:password@default/test',
3333
];
3434
yield [
35-
'ntfy://ntfy.sh:8888/test',
36-
'ntfy://user:password@default:8888/test?secureHttp=off',
35+
'ntfy://ntfy.sh/test',
36+
'ntfy://:password@default/test',
3737
];
3838
yield [
39-
'ntfy://ntfy.sh/test',
40-
'ntfy://default/test?secureHttp=off&token=testToken',
39+
'ntfy://ntfy.sh:8888/test',
40+
'ntfy://user:password@default:8888/test?secureHttp=off',
4141
];
4242
}
4343

src/Symfony/Component/Notifier/Bridge/Ntfy/Tests/NtfyTransportTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function testSend()
8585
$this->assertSame('2BYIwRmvBKcv', $sentMessage->getMessageId());
8686
}
8787

88-
public function testSendWithToken()
88+
public function testSendWithPassword()
8989
{
9090
$response = $this->createMock(ResponseInterface::class);
9191
$response->expects($this->exactly(2))
@@ -104,7 +104,7 @@ public function testSendWithToken()
104104
return $response;
105105
});
106106

107-
$transport = $this->createTransport($client)->setToken('testtokentesttoken');
107+
$transport = $this->createTransport($client)->setPassword('testtokentesttoken');
108108

109109
$sentMessage = $transport->send(new PushMessage('Hello', 'World'));
110110

0 commit comments

Comments
 (0)