Skip to content

Commit 6d1fd4d

Browse files
committed
save
1 parent 10e417f commit 6d1fd4d

14 files changed

+799
-214
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"ext-json": "*",
1010
"ext-openssl": "*",
1111
"guzzlehttp/guzzle": "^7.2",
12-
"symfony/yaml": "^5.2"
12+
"symfony/yaml": "^5.2",
13+
"firebase/php-jwt": "^5.2"
1314
},
1415
"require-dev": {
1516
"phpunit/phpunit": "^8"

composer.lock

Lines changed: 61 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Auth/AuthenticationClient.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
use GuzzleHttp\Psr7\Request;
4747
use Psr\Http\Message\ResponseInterface;
4848
use GuzzleHttp\Exception\RequestException;
49+
use Firebase\JWT\JWT;
50+
4951
use Error;
5052
use Exception;
5153
use stdClass;
@@ -85,6 +87,28 @@ public function __construct($userPoolIdOrFunc)
8587
parent::__construct($userPoolIdOrFunc);
8688
}
8789

90+
function checkLoggedIn() {
91+
$user = $this->getCurrentUser();
92+
if ($user) {
93+
return $user->id;
94+
}
95+
96+
if ($this->accessToken) {
97+
throw new Error('请先登录!');
98+
}
99+
// $tokenInfo = JWT::decode($this->accessToken);
100+
// $userId = $tokenInfo->sub ?? ($tokenInfo ->data ? $tokenInfo ->data ->id : '');
101+
// if ($userId) {
102+
// throw new Error('不合法的 accessToken');
103+
// }
104+
// return $userId;
105+
}
106+
107+
public function setToken(string $accessToken)
108+
{
109+
$this->setAccessToken($accessToken);
110+
}
111+
88112
public function setMfaAuthorizationHeader(string $token)
89113
{
90114
$this->mfaToken = $token;
@@ -446,8 +470,8 @@ function unBindPhone()
446470
*/
447471
function logout()
448472
{
449-
$param = new UpdateUserParam((new UpdateUserInput())->withTokenExpiredAt('0'));
450-
$this->request($param->createRequest());
473+
$appId = $this->options->appId;
474+
$this->httpGet("/api/v2/logout?app_id=$appId");
451475
$this->accessToken = '';
452476
}
453477

src/BaseClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function httpPost($path, $data, $flag = '')
156156
return $this->arrayToObject($result);
157157
}
158158

159-
public function httpPatch($path, $data)
159+
public function httpPatch($path, $data = [])
160160
{
161161
$result = $this->send($this->host . $path, $data, 'PATCH');
162162
return $this->arrayToObject($result);

src/Mgmt/ApplicationsManagementClient.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<?php
22

33
namespace Authing\Mgmt;
4+
use Authing\Mgmt\ManagementClient;
45

56
class ApplicationsManagementClient {
67
private array $options;
7-
private $client;
88

9-
public function __construct($client)
9+
/**
10+
* @var ManagementClient
11+
*/
12+
private ManagementClient $client;
13+
14+
public function __construct(ManagementClient $client)
1015
{
1116
$this->client = $client;
1217
}
@@ -24,5 +29,31 @@ public function findById(string $id)
2429
$data = $this->client->httpGet("/api/v2/applications/$id");
2530
return $data;
2631
}
32+
33+
public function create(array $options)
34+
{
35+
$res = $this->client->httpPost('/api/v2/applications', (object)$options);
36+
return $res;
37+
}
38+
39+
public function delete(string $appId)
40+
{
41+
$this->client->httpDelete("/api/v2/applications/$appId");
42+
return true;
43+
}
44+
45+
public function activeUsers(string $appId, int $page = 1, int $limit = 10)
46+
{
47+
$res = $this->client->httpGet("/api/v2/applications/$appId/active-users?page=$page&limit=$limit");
48+
return $res;
49+
}
50+
51+
public function refreshApplicationSecret(string $appId)
52+
{
53+
$res = $this->client->httpPatch("/api/v2/application/$appId/refresh-secret");
54+
return $res;
55+
}
56+
57+
2758
}
2859

src/Mgmt/RolesManagementClient.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,20 @@
1515
use Authing\Types\PolicyAssignmentsParam;
1616
use Authing\Types\PolicyAssignmentTargetType;
1717
use Authing\Types\RemovePolicyAssignmentsParam;
18+
use Authing\Types\RemoveUdvParam;
1819
use Authing\Types\RevokeRoleParam;
1920
use Authing\Types\Role;
2021
use Authing\Types\RoleParam;
2122
use Authing\Types\RolesParam;
2223
use Authing\Types\RoleWithUsersParam;
2324
use Authing\Types\SetUdfValueBatchInput;
25+
use Authing\Types\SetUdfValueBatchParam;
2426
use Authing\Types\SetUdvBatchParam;
2527
use Authing\Types\UDFDataType;
2628
use Authing\Types\UDFTargetType;
2729
use Authing\Types\UdfValueBatchParam;
2830
use Authing\Types\UdvParam;
2931
use Authing\Types\UpdateRoleParam;
30-
use Authing\Types\SetUdfValueBatchParam;
31-
use Authing\Types\RemoveUdvParam;
32-
3332
use Exception;
3433
use stdClass;
3534

@@ -52,6 +51,25 @@ function formatAuthorizedResources($obj)
5251
return $res;
5352
}
5453

54+
function convertUdv(array $data)
55+
{
56+
foreach ($data as $item) {
57+
$dataType = $item->dataType;
58+
$value = $item->value;
59+
if ($dataType === UDFDataType::NUMBER) {
60+
$item->value = json_encode($value);
61+
} else if ($dataType === UDFDataType::BOOLEAN) {
62+
$item->value = json_encode($value);
63+
} else if ($dataType === UDFDataType::DATETIME) {
64+
// set data time
65+
// $item->value = intval($value);
66+
} else if ($dataType === UDFDataType::OBJECT) {
67+
$item->value = json_encode($value);
68+
}
69+
}
70+
return $data;
71+
}
72+
5573
function convertUdvToKeyValuePair(array $data)
5674
{
5775
foreach ($data as $item) {
@@ -68,7 +86,7 @@ function convertUdvToKeyValuePair(array $data)
6886
$item->value = json_encode($value);
6987
}
7088
}
71-
;
89+
7290
$ret = new stdClass();
7391
foreach ($data as $item) {
7492
$key = $item->key;

src/Mgmt/UdfManagementClient.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
namespace Authing\Mgmt;
55

66

7-
use Authing\Types\CommonMessage;
8-
use Authing\Types\RemoveUdfParam;
7+
use Exception;
8+
use Authing\Mgmt\Utils;
9+
use Authing\Types\UdfParam;
10+
use Authing\Types\UdvParam;
11+
use Authing\Mgmt\convertUdv;
912
use Authing\Types\SetUdfParam;
1013
use Authing\Types\UDFDataType;
11-
use Authing\Types\UdfParam;
14+
use Authing\Types\CommonMessage;
1215
use Authing\Types\UDFTargetType;
16+
use Authing\Types\RemoveUdfParam;
17+
18+
use Authing\Types\SetUdvBatchParam;
1319
use Authing\Types\UserDefinedField;
14-
use Exception;
1520

1621
class UdfManagementClient
1722
{
@@ -71,4 +76,25 @@ public function remove($targetType, $key)
7176
$param = new RemoveUdfParam($targetType, $key);
7277
return $this->client->request($param->createRequest());
7378
}
79+
80+
public function listUdv(string $targetType, string $targetId)
81+
{
82+
$param = new UdvParam($targetType, $targetId);
83+
$res = $this->client->request($param->createRequest());
84+
$list = $res->udv;
85+
return convertUdv($list);
86+
}
87+
88+
public function setUdvBatch(string $targetType, string $targetId, array $udvList)
89+
{
90+
$data = array_map(function($item) {
91+
return (object)[
92+
'key' => $item->key,
93+
'value' => json_encode($item->value)
94+
];
95+
}, $udvList);
96+
$param = (new SetUdvBatchParam($targetType, $targetId))->withUdvList($data);
97+
$list = $this->client->request($param->createRequest())->setUdvBatch;
98+
return Utils::convertUdv($list);
99+
}
74100
}

src/Mgmt/Utils.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Authing\Mgmt;
4+
5+
6+
class Utils
7+
{
8+
public static function convertUdv(array $data)
9+
{
10+
foreach ($data as $item) {
11+
$dataType = $item->dataType;
12+
$value = $item->value;
13+
if ($dataType === UDFDataType::NUMBER) {
14+
$item->value = json_encode($value);
15+
} else if ($dataType === UDFDataType::BOOLEAN) {
16+
$item->value = json_encode($value);
17+
} else if ($dataType === UDFDataType::DATETIME) {
18+
// set data time
19+
// $item->value = intval($value);
20+
} else if ($dataType === UDFDataType::OBJECT) {
21+
$item->value = json_encode($value);
22+
}
23+
}
24+
return $data;
25+
}
26+
}

0 commit comments

Comments
 (0)