1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Containers\Authentication\UI\API\Controllers; |
4
|
|
|
|
5
|
|
|
use Apiato\Core\Foundation\Facades\Apiato; |
6
|
|
|
use App\Containers\Authentication\Data\Transporters\ProxyApiLoginTransporter; |
7
|
|
|
use App\Containers\Authentication\Data\Transporters\ProxyRefreshTransporter; |
8
|
|
|
use App\Containers\Authentication\UI\API\Requests\LoginRequest; |
9
|
|
|
use App\Containers\Authentication\UI\API\Requests\LogoutRequest; |
10
|
|
|
use App\Containers\Authentication\UI\API\Requests\RefreshRequest; |
11
|
|
|
use App\Ship\Parents\Controllers\ApiController; |
12
|
|
|
use App\Ship\Transporters\DataTransporter; |
13
|
|
|
use Illuminate\Support\Facades\Config; |
14
|
|
|
use Illuminate\Support\Facades\Cookie; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Controller |
18
|
|
|
* |
19
|
|
|
* @author Mahmoud Zalt <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Controller extends ApiController |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param \App\Containers\Authentication\UI\API\Requests\LogoutRequest $request |
26
|
|
|
* |
27
|
|
|
* @return \Illuminate\Http\JsonResponse |
28
|
|
|
*/ |
29
|
|
|
public function logout(LogoutRequest $request) |
30
|
|
|
{ |
31
|
|
|
$dataTransporter = new DataTransporter($request); |
32
|
|
|
$dataTransporter->bearerToken = $request->bearerToken(); |
33
|
|
|
|
34
|
|
|
Apiato::call('[email protected]', [$dataTransporter]); |
35
|
|
|
|
36
|
|
|
return $this->accepted([ |
37
|
|
|
'message' => 'Token revoked successfully.', |
38
|
|
|
])->withCookie(Cookie::forget('refreshToken')); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* This `proxyLoginForAdminWebClient` exist only because we have `AdminWebClient` |
43
|
|
|
* The more clients (Web Apps). Each client you add in the future, must have |
44
|
|
|
* similar functions here, with custom route for dedicated for each client |
45
|
|
|
* to be used as proxy when contacting the OAuth server. |
46
|
|
|
* This is only to help the Web Apps (JavaScript clients) hide |
47
|
|
|
* their ID's and Secrets when contacting the OAuth server and obtain Tokens. |
48
|
|
|
* |
49
|
|
|
* @param \App\Containers\Authentication\UI\API\Requests\LoginRequest $request |
50
|
|
|
* |
51
|
|
|
* @return \Illuminate\Http\JsonResponse |
52
|
|
|
*/ |
53
|
|
|
public function proxyLoginForAdminWebClient(LoginRequest $request) |
54
|
|
|
{ |
55
|
|
|
$dataTransporter = new ProxyApiLoginTransporter( |
56
|
|
|
array_merge($request->all(), [ |
57
|
|
|
'client_id' => Config::get('authentication-container.clients.web.admin.id'), |
58
|
|
|
'client_password' => Config::get('authentication-container.clients.web.admin.secret') |
59
|
|
|
]) |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$result = Apiato::call('[email protected]', [$dataTransporter]); |
63
|
|
|
|
64
|
|
|
return $this->json($result['response_content'])->withCookie($result['refresh_cookie']); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Read the comment in the function `proxyLoginForAdminWebClient` |
69
|
|
|
* |
70
|
|
|
* @param \App\Containers\Authentication\UI\API\Requests\RefreshRequest $request |
71
|
|
|
* |
72
|
|
|
* @return \Illuminate\Http\JsonResponse |
73
|
|
|
*/ |
74
|
|
|
public function proxyRefreshForAdminWebClient(RefreshRequest $request) |
75
|
|
|
{ |
76
|
|
|
$dataTransporter = new ProxyRefreshTransporter( |
77
|
|
|
array_merge($request->all(), [ |
78
|
|
|
'client_id' => Config::get('authentication-container.clients.web.admin.id'), |
79
|
|
|
'client_password' => Config::get('authentication-container.clients.web.admin.secret'), |
80
|
|
|
// use the refresh token sent in request data, if not exist try to get it from the cookie |
81
|
|
|
'refresh_token' => $request->refresh_token ? : $request->cookie('refreshToken'), |
|
|
|
|
82
|
|
|
]) |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
$result = Apiato::call('[email protected]', [$dataTransporter]); |
86
|
|
|
|
87
|
|
|
return $this->json($result['response-content'])->withCookie($result['refresh-cookie']); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.