Skip to content

Commit 10e417f

Browse files
committed
save
1 parent 1e4cf49 commit 10e417f

File tree

5 files changed

+333
-69
lines changed

5 files changed

+333
-69
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "authing-sdk/php",
33
"description": "authing-php-sdk",
44
"minimum-stability": "stable",
5-
"version": "4.1.4",
5+
"version": "4.1.6",
66
"require": {
77
"php": ">=5.4",
88
"ext-curl": "*",

src/BaseClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ abstract class BaseClient
2121

2222
private $_type = "SDK";
2323

24-
private $_version = "php:4.1.1";
24+
private $_version = "php:4.1.6";
2525

2626
private $publicKey
2727
= <<<PUBLICKKEY

src/Mgmt/AclManagementClient.php

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Authing\Types\AuthorizeResourceParam;
88
use Authing\Types\CommonMessage;
99
use Authing\Types\IsActionAllowedParam;
10+
use Error;
1011
use Exception;
1112
use stdClass;
1213

@@ -37,7 +38,7 @@ function randomString(int $randomLenth = 32)
3738
$n = '';
3839

3940
for ($i = 0; $i < $randomLenth; $i++) {
40-
$n .= t[rand(0, $a)];
41+
$n .= $t[rand(0, $a - 1)];
4142
}
4243
return $n;
4344
}
@@ -114,6 +115,7 @@ public function getResources(array $options)
114115
];
115116
$params = http_build_query($array);
116117
$data = $this->client->httpGet("/api/v2/resources?$params");
118+
return $data;
117119
}
118120

119121
public function createResource(array $options)
@@ -158,10 +160,10 @@ public function createProgrammaticAccessAccount(string $appId, array $options =
158160

159161
public function disableProgrammaticAccessAccount(string $programmaticAccessAccountId)
160162
{
161-
$data = new stdClass();
162-
$data->id = $programmaticAccessAccountId;
163-
$data->enabled = false;
164-
$res = $this->client->httpPatch('/api/v2/applications/programmatic-access-accounts', $data);
163+
$res = $this->client->httpPatch('/api/v2/applications/programmatic-access-accounts', [
164+
'id' => $programmaticAccessAccountId,
165+
'enabled' => false,
166+
]);
165167
return $res;
166168
}
167169

@@ -173,21 +175,22 @@ public function deleteProgrammaticAccessAccount(string $programmaticAccessAccoun
173175

174176
public function enableProgrammaticAccessAccount(string $programmaticAccessAccountId)
175177
{
176-
$data = new stdClass();
177-
$data->id = $programmaticAccessAccountId;
178-
$data->enabled = true;
179-
$res = $this->client->httpPatch("/api/v2/applications/programmatic-access-accounts", $data);
178+
$res = $this->client->httpPatch("/api/v2/applications/programmatic-access-accounts", [
179+
'id' => $programmaticAccessAccountId,
180+
'enabled' => true,
181+
]);
180182
return $res;
181183
}
182184

183185
public function refreshProgrammaticAccessAccountSecret(string $programmaticAccessAccountId, string $programmaticAccessAccountSecret = '')
184186
{
185-
$programmaticAccessAccountSecret = randomString(32);
186-
$data = [
187+
if (!isset($programmaticAccessAccountSecret) || $programmaticAccessAccountSecret === '') {
188+
$programmaticAccessAccountSecret = randomString(32);
189+
}
190+
$res = $this->client->httpPatch('/api/v2/applications/programmatic-access-accounts', [
187191
'id' => $programmaticAccessAccountId,
188192
'secret' => $programmaticAccessAccountSecret,
189-
];
190-
$res = $this->client->httpPatch('/api/v2/applications/programmatic-access-accounts', $data);
193+
]);
191194
return $res;
192195
}
193196

@@ -196,7 +199,7 @@ public function authorizeResource(array $params)
196199
$namespace = $params['namespace'];
197200
$resource = $params['resource'];
198201
$opts = $params['opts'];
199-
$param = (new AuthorizeResourceParam())->withNamespace($namespace)->withOpts($ops)->withResource($resource);
202+
$param = (new AuthorizeResourceParam())->withNamespace($namespace)->withOpts($opts)->withResource($resource);
200203
$res = $this->client->request($param->createRequest());
201204
return $res;
202205
}
@@ -208,9 +211,10 @@ public function listResourcePermissions()
208211

209212
public function getApplicationAccessPolicies(array $options)
210213
{
211-
if ($options['appId']) {
214+
if (!$options['appId']) {
212215
throw new Error('请传入 appId');
213216
}
217+
$options = (object) $options;
214218
$appId = $options->appId;
215219
$page = $options->page ?? 1;
216220
$limit = $options->limit ?? 10;
@@ -220,51 +224,52 @@ public function getApplicationAccessPolicies(array $options)
220224

221225
public function enableApplicationAccessPolicy(array $options)
222226
{
223-
if ($options['appId']) {
227+
if (!$options['appId']) {
224228
throw new Error('请传入 appId');
225229
}
226-
if ($options['targetType']) {
230+
if (!$options['targetType']) {
227231
throw new Error(
228232
'请传入主体类型,可选值为 USER、ROLE、ORG、GROUP,含义为用户、角色、组织机构节点、用户分组'
229233
);
230234
}
231-
if ($options['targetIdentifiers']) {
235+
if (!$options['targetIdentifiers']) {
232236
throw new Error('请传入主体 id');
233237
}
234238
extract($options, EXTR_OVERWRITE);
235239
$data = [
236240
'targetType' => $targetType,
237-
'namespace' => $namespace,
241+
'namespace' => $namespace ?? null,
238242
'targetIdentifiers' => $targetIdentifiers,
239-
'inheritByChildren' => $inheritByChildren,
243+
'inheritByChildren' => $inheritByChildren ?? null,
240244
];
241245
$this->client->httpPost("/api/v2/applications/$appId/authorization/enable-effect", $data);
242-
$_ = new stdClass();
243-
$_->code = 200;
244-
$_->message = '启用应用访问控制策略成功';
245-
return $_;
246+
return (object) [
247+
'code' => 200,
248+
'message' => '启用应用访问控制策略成功',
249+
];
246250
}
247251

248252
public function disableApplicationAccessPolicy(array $options)
249253
{
250-
if ($options['appId']) {
254+
if (!$options['appId']) {
251255
throw new Error('请传入 appId');
252256
}
253-
if ($options['targetType']) {
257+
if (!$options['targetType']) {
254258
throw new Error(
255259
'请传入主体类型,可选值为 USER、ROLE、ORG、GROUP,含义为用户、角色、组织机构节点、用户分组'
256260
);
257261
}
258-
if ($options['targetIdentifiers']) {
262+
if (!$options['targetIdentifiers']) {
259263
throw new Error('请传入主体 id');
260264
}
261265
extract($options, EXTR_OVERWRITE);
262266
$data = [
263267
'targetType' => $targetType,
264-
'namespace' => $namespace,
268+
'namespace' => $namespace ?? null,
265269
'targetIdentifiers' => $targetIdentifiers,
266-
'inheritByChildren' => $inheritByChildren,
270+
'inheritByChildren' => $inheritByChildren ?? null,
267271
];
272+
268273
$this->client->httpPost("/api/v2/applications/$appId/authorization/disable-effect", $data);
269274
$_ = new stdClass();
270275
$_->code = 200;
@@ -274,24 +279,25 @@ public function disableApplicationAccessPolicy(array $options)
274279

275280
public function deleteApplicationAccessPolicy(array $options)
276281
{
277-
if ($options['appId']) {
282+
if (!$options['appId']) {
278283
throw new Error('请传入 appId');
279284
}
280-
if ($options['targetType']) {
285+
if (!$options['targetType']) {
281286
throw new Error(
282287
'请传入主体类型,可选值为 USER、ROLE、ORG、GROUP,含义为用户、角色、组织机构节点、用户分组'
283288
);
284289
}
285-
if ($options['targetIdentifiers']) {
290+
if (!$options['targetIdentifiers']) {
286291
throw new Error('请传入主体 id');
287292
}
288293
extract($options, EXTR_OVERWRITE);
289294
$data = [
290295
'targetType' => $targetType,
291-
'namespace' => $namespace,
296+
'namespace' => $namespace ?? null,
292297
'targetIdentifiers' => $targetIdentifiers,
293-
'inheritByChildren' => $inheritByChildren,
298+
'inheritByChildren' => $inheritByChildren ?? null,
294299
];
300+
295301
$this->client->httpPost("/api/v2/applications/$appId/authorization/revoke", $data);
296302
$_ = new stdClass();
297303
$_->code = 200;
@@ -301,24 +307,25 @@ public function deleteApplicationAccessPolicy(array $options)
301307

302308
public function allowAccessApplication(array $options)
303309
{
304-
if ($options['appId']) {
310+
if (!$options['appId']) {
305311
throw new Error('请传入 appId');
306312
}
307-
if ($options['targetType']) {
313+
if (!$options['targetType']) {
308314
throw new Error(
309315
'请传入主体类型,可选值为 USER、ROLE、ORG、GROUP,含义为用户、角色、组织机构节点、用户分组'
310316
);
311317
}
312-
if ($options['targetIdentifiers']) {
318+
if (!$options['targetIdentifiers']) {
313319
throw new Error('请传入主体 id');
314320
}
315321
extract($options, EXTR_OVERWRITE);
316322
$data = [
317323
'targetType' => $targetType,
318-
'namespace' => $namespace,
324+
'namespace' => $namespace ?? null,
319325
'targetIdentifiers' => $targetIdentifiers,
320-
'inheritByChildren' => $inheritByChildren,
326+
'inheritByChildren' => $inheritByChildren ?? null,
321327
];
328+
322329
$this->client->httpPost("/api/v2/applications/$appId/authorization/allow", $data);
323330
$_ = new stdClass();
324331
$_->code = 200;
@@ -328,24 +335,25 @@ public function allowAccessApplication(array $options)
328335

329336
public function denyAccessApplication(array $options)
330337
{
331-
if ($options['appId']) {
338+
if (!$options['appId']) {
332339
throw new Error('请传入 appId');
333340
}
334-
if ($options['targetType']) {
341+
if (!$options['targetType']) {
335342
throw new Error(
336343
'请传入主体类型,可选值为 USER、ROLE、ORG、GROUP,含义为用户、角色、组织机构节点、用户分组'
337344
);
338345
}
339-
if ($options['targetIdentifiers']) {
346+
if (!$options['targetIdentifiers']) {
340347
throw new Error('请传入主体 id');
341348
}
342349
extract($options, EXTR_OVERWRITE);
343350
$data = [
344351
'targetType' => $targetType,
345-
'namespace' => $namespace,
352+
'namespace' => $namespace ?? null,
346353
'targetIdentifiers' => $targetIdentifiers,
347-
'inheritByChildren' => $inheritByChildren,
354+
'inheritByChildren' => $inheritByChildren ?? null,
348355
];
356+
349357
$this->client->httpPost("/api/v2/applications/$appId/authorization/deny", $data);
350358
$_ = new stdClass();
351359
$_->code = 200;
@@ -355,10 +363,10 @@ public function denyAccessApplication(array $options)
355363

356364
public function updateDefaultApplicationAccessPolicy(array $options)
357365
{
358-
if ($options['appId']) {
366+
if (!$options['appId']) {
359367
throw new Error('请传入 appId');
360368
}
361-
if ($options['defaultStrategy']) {
369+
if (!$options['defaultStrategy']) {
362370
throw new Error(
363371
'请传入默认策略,可选值为 ALLOW_ALL、DENY_ALL,含义为默认允许所有用户登录应用、默认拒绝所有用户登录应用'
364372
);
@@ -371,5 +379,4 @@ public function updateDefaultApplicationAccessPolicy(array $options)
371379
return $res;
372380
}
373381

374-
375382
}

0 commit comments

Comments
 (0)