-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_invalidate.php
More file actions
58 lines (45 loc) · 1.48 KB
/
test_invalidate.php
File metadata and controls
58 lines (45 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Zone\Wildduck\WildduckClient;
use Zone\Wildduck\Dto\User\CreateUserRequestDto;
use Zone\Wildduck\Dto\Authentication\AuthenticateRequestDto;
$client = new WildduckClient([
'api_base' => 'http://localhost:8080',
'access_token' => 'secret-token',
]);
// Create a test user
$username = 'testuser_' . uniqid();
$password = 'TestPassword123!';
$email = 'test_' . uniqid() . '@example.com';
$createUserDto = new CreateUserRequestDto(
username: $username,
password: $password,
address: $email
);
try {
$userResult = $client->users()->create($createUserDto);
echo "User created: {$userResult->id}\n";
// Authenticate
$authDto = new AuthenticateRequestDto(
username: $username,
password: $password,
scope: 'master'
);
$authResult = $client->authentication()->authenticate($authDto);
echo "Token: {$authResult->token}\n";
// Create client with user token
$userClient = new WildduckClient([
'api_base' => 'http://localhost:8080',
'access_token' => $authResult->token,
]);
// Invalidate token
echo "Invalidating token...\n";
$result = $userClient->authentication()->invalidateToken();
echo "Result: ";
var_dump($result);
// Cleanup
$client->users()->delete($userResult->id);
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
echo "Trace:\n" . $e->getTraceAsString() . "\n";
}