Skip to content

Commit df3e6e1

Browse files
author
Andrey Helldar
committed
Added the ability to reset the authorization token
`UnauthorizedException: Token is not active`
1 parent ce1c47a commit df3e6e1

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
"require": {
2626
"php": "^7.3|^8.0",
2727
"ext-json": "*",
28-
"andrey-helldar/contracts": "^1.9",
28+
"andrey-helldar/contracts": "^1.14",
2929
"andrey-helldar/simple-data-transfer-object": "^1.0",
3030
"andrey-helldar/support": "^4.0",
3131
"illuminate/support": "^6.0|^7.0|^8.0"
3232
},
3333
"require-dev": {
34-
"andrey-helldar/cashier": "^1.1",
34+
"andrey-helldar/cashier": "^1.9",
3535
"orchestra/testbench": "^4.0|^5.0|^6.0",
3636
"phpunit/phpunit": "^9.0",
3737
"symfony/var-dumper": "^4.3.4|^5.0"

src/Auth.php

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public function body(): array
6868
return $this->request->getRawBody();
6969
}
7070

71+
public function refresh(): void
72+
{
73+
Hash::make()->forget($this->model, $this->scope);
74+
}
75+
7176
protected function getAccessToken(): AccessToken
7277
{
7378
return Hash::make()->get($this->model, $this->request->uri(), $this->scope);

src/Facades/Cache.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
/**
2828
* @method static AccessToken get(Query $client, callable $request)
29+
* @method static void forget(Query $client)
2930
*/
3031
class Cache extends Facade
3132
{

src/Support/Cache.php

+19-5
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,38 @@
2727

2828
class Cache
2929
{
30-
public function get(Query $client, callable $request): AccessToken
30+
public function get(Query $query, callable $request): AccessToken
3131
{
32-
$key = $this->key($client);
32+
$key = $this->key($query);
3333

3434
if ($this->doesnt($key)) {
35-
$response = $this->request($client, $request);
35+
$response = $this->request($query, $request);
3636

3737
$this->set($key, $response->getExpiresIn(), $response->getAccessToken());
3838

3939
return $response;
4040
}
4141

42-
return $this->from($key, $client);
42+
return $this->from($key, $query);
43+
}
44+
45+
public function forget(Query $query): void
46+
{
47+
$key = $this->key($query);
48+
49+
if ($this->exists($key)) {
50+
Repository::forget($key);
51+
}
52+
}
53+
54+
protected function exists(string $key): bool
55+
{
56+
return Repository::has($key);
4357
}
4458

4559
protected function doesnt(string $key): bool
4660
{
47-
return ! Repository::has($key);
61+
return ! $this->exists($key);
4862
}
4963

5064
protected function from(string $key, Query $client): AccessToken

src/Support/Hash.php

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ public function get(Model $model, Builder $uri, string $scope): AccessToken
4949
});
5050
}
5151

52+
public function forget(Model $model, string $scope): void
53+
{
54+
$query = $this->query($model, $scope);
55+
56+
CacheRepository::forget($query);
57+
}
58+
5259
protected function post(RequestContract $request): array
5360
{
5461
return Http::post($request, $this->exceptions());

0 commit comments

Comments
 (0)