@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - /* |
|
5 | + /* |
|
6 | 6 | |-------------------------------------------------------------------------- |
7 | 7 | | Authentication Defaults |
8 | 8 | |-------------------------------------------------------------------------- |
@@ -13,12 +13,12 @@ discard block |
||
13 | 13 | | |
14 | 14 | */ |
15 | 15 | |
16 | - 'defaults' => [ |
|
17 | - 'guard' => 'web', |
|
18 | - 'passwords' => 'users', |
|
19 | - ], |
|
16 | + 'defaults' => [ |
|
17 | + 'guard' => 'web', |
|
18 | + 'passwords' => 'users', |
|
19 | + ], |
|
20 | 20 | |
21 | - /* |
|
21 | + /* |
|
22 | 22 | |-------------------------------------------------------------------------- |
23 | 23 | | Authentication Guards |
24 | 24 | |-------------------------------------------------------------------------- |
@@ -35,19 +35,19 @@ discard block |
||
35 | 35 | | |
36 | 36 | */ |
37 | 37 | |
38 | - 'guards' => [ |
|
39 | - 'web' => [ |
|
40 | - 'driver' => 'session', |
|
41 | - 'provider' => 'users', |
|
42 | - ], |
|
38 | + 'guards' => [ |
|
39 | + 'web' => [ |
|
40 | + 'driver' => 'session', |
|
41 | + 'provider' => 'users', |
|
42 | + ], |
|
43 | 43 | |
44 | - 'api' => [ |
|
45 | - 'driver' => 'passport', |
|
46 | - 'provider' => 'users', |
|
47 | - ], |
|
48 | - ], |
|
44 | + 'api' => [ |
|
45 | + 'driver' => 'passport', |
|
46 | + 'provider' => 'users', |
|
47 | + ], |
|
48 | + ], |
|
49 | 49 | |
50 | - /* |
|
50 | + /* |
|
51 | 51 | |-------------------------------------------------------------------------- |
52 | 52 | | User Providers |
53 | 53 | |-------------------------------------------------------------------------- |
@@ -64,19 +64,19 @@ discard block |
||
64 | 64 | | |
65 | 65 | */ |
66 | 66 | |
67 | - 'providers' => [ |
|
68 | - 'users' => [ |
|
69 | - 'driver' => 'eloquent', |
|
70 | - 'model' => App\Modules\Acl\AclUser::class, |
|
71 | - ], |
|
67 | + 'providers' => [ |
|
68 | + 'users' => [ |
|
69 | + 'driver' => 'eloquent', |
|
70 | + 'model' => App\Modules\Acl\AclUser::class, |
|
71 | + ], |
|
72 | 72 | |
73 | - // 'users' => [ |
|
74 | - // 'driver' => 'database', |
|
75 | - // 'table' => 'users', |
|
76 | - // ], |
|
77 | - ], |
|
73 | + // 'users' => [ |
|
74 | + // 'driver' => 'database', |
|
75 | + // 'table' => 'users', |
|
76 | + // ], |
|
77 | + ], |
|
78 | 78 | |
79 | - /* |
|
79 | + /* |
|
80 | 80 | |-------------------------------------------------------------------------- |
81 | 81 | | Resetting Passwords |
82 | 82 | |-------------------------------------------------------------------------- |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | | |
92 | 92 | */ |
93 | 93 | |
94 | - 'passwords' => [ |
|
95 | - 'users' => [ |
|
96 | - 'provider' => 'users', |
|
97 | - 'table' => 'password_resets', |
|
98 | - 'expire' => 60, |
|
99 | - ], |
|
100 | - ], |
|
94 | + 'passwords' => [ |
|
95 | + 'users' => [ |
|
96 | + 'provider' => 'users', |
|
97 | + 'table' => 'password_resets', |
|
98 | + 'expire' => 60, |
|
99 | + ], |
|
100 | + ], |
|
101 | 101 | |
102 | 102 | ]; |
@@ -7,81 +7,81 @@ |
||
7 | 7 | |
8 | 8 | class Handler extends ExceptionHandler |
9 | 9 | { |
10 | - /** |
|
11 | - * A list of the exception types that are not reported. |
|
12 | - * |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - protected $dontReport = [ |
|
16 | - \League\OAuth2\Server\Exception\OAuthServerException::class, |
|
17 | - ]; |
|
10 | + /** |
|
11 | + * A list of the exception types that are not reported. |
|
12 | + * |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + protected $dontReport = [ |
|
16 | + \League\OAuth2\Server\Exception\OAuthServerException::class, |
|
17 | + ]; |
|
18 | 18 | |
19 | - /** |
|
20 | - * A list of the inputs that are never flashed for validation exceptions. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $dontFlash = [ |
|
25 | - 'password', |
|
26 | - 'password_confirmation', |
|
27 | - ]; |
|
19 | + /** |
|
20 | + * A list of the inputs that are never flashed for validation exceptions. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $dontFlash = [ |
|
25 | + 'password', |
|
26 | + 'password_confirmation', |
|
27 | + ]; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Report or log an exception. |
|
31 | - * |
|
32 | - * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
|
33 | - * |
|
34 | - * @param \Exception $exception |
|
35 | - * @return void |
|
36 | - */ |
|
37 | - public function report(Exception $exception) |
|
38 | - { |
|
39 | - parent::report($exception); |
|
40 | - } |
|
29 | + /** |
|
30 | + * Report or log an exception. |
|
31 | + * |
|
32 | + * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
|
33 | + * |
|
34 | + * @param \Exception $exception |
|
35 | + * @return void |
|
36 | + */ |
|
37 | + public function report(Exception $exception) |
|
38 | + { |
|
39 | + parent::report($exception); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Render an exception into an HTTP response. |
|
44 | - * |
|
45 | - * @param \Illuminate\Http\Request $request |
|
46 | - * @param \Exception $exception |
|
47 | - * @return \Illuminate\Http\Response |
|
48 | - */ |
|
49 | - public function render($request, Exception $exception) |
|
50 | - { |
|
51 | - if ($request->wantsJson()) |
|
52 | - { |
|
53 | - if ($exception instanceof \Illuminate\Auth\AuthenticationException) |
|
54 | - { |
|
55 | - \ErrorHandler::unAuthorized(); |
|
56 | - } |
|
57 | - if ($exception instanceof \Illuminate\Database\QueryException) |
|
58 | - { |
|
59 | - \ErrorHandler::dbQueryError(); |
|
60 | - } |
|
61 | - else if ($exception instanceof \predis\connection\connectionexception) |
|
62 | - { |
|
63 | - \ErrorHandler::redisNotRunning(); |
|
64 | - } |
|
65 | - else if ($exception instanceof \GuzzleHttp\Exception\ClientException) |
|
66 | - { |
|
67 | - \ErrorHandler::connectionError(); |
|
68 | - } |
|
69 | - else if ($exception instanceof \Symfony\Component\HttpKernel\Exception\HttpException) |
|
70 | - { |
|
71 | - return \Response::json($exception->getMessage(), $exception->getStatusCode()); |
|
72 | - } |
|
73 | - else if ($exception instanceof \Illuminate\Validation\ValidationException) |
|
74 | - { |
|
75 | - return \Response::json($exception->errors(), 422); |
|
76 | - } |
|
77 | - else if ( ! $exception instanceof \Symfony\Component\Debug\Exception\FatalErrorException) |
|
78 | - { |
|
79 | - return parent::render($request, $exception); |
|
80 | - } |
|
81 | - } |
|
82 | - else |
|
83 | - { |
|
84 | - return parent::render($request, $exception); |
|
85 | - } |
|
86 | - } |
|
42 | + /** |
|
43 | + * Render an exception into an HTTP response. |
|
44 | + * |
|
45 | + * @param \Illuminate\Http\Request $request |
|
46 | + * @param \Exception $exception |
|
47 | + * @return \Illuminate\Http\Response |
|
48 | + */ |
|
49 | + public function render($request, Exception $exception) |
|
50 | + { |
|
51 | + if ($request->wantsJson()) |
|
52 | + { |
|
53 | + if ($exception instanceof \Illuminate\Auth\AuthenticationException) |
|
54 | + { |
|
55 | + \ErrorHandler::unAuthorized(); |
|
56 | + } |
|
57 | + if ($exception instanceof \Illuminate\Database\QueryException) |
|
58 | + { |
|
59 | + \ErrorHandler::dbQueryError(); |
|
60 | + } |
|
61 | + else if ($exception instanceof \predis\connection\connectionexception) |
|
62 | + { |
|
63 | + \ErrorHandler::redisNotRunning(); |
|
64 | + } |
|
65 | + else if ($exception instanceof \GuzzleHttp\Exception\ClientException) |
|
66 | + { |
|
67 | + \ErrorHandler::connectionError(); |
|
68 | + } |
|
69 | + else if ($exception instanceof \Symfony\Component\HttpKernel\Exception\HttpException) |
|
70 | + { |
|
71 | + return \Response::json($exception->getMessage(), $exception->getStatusCode()); |
|
72 | + } |
|
73 | + else if ($exception instanceof \Illuminate\Validation\ValidationException) |
|
74 | + { |
|
75 | + return \Response::json($exception->errors(), 422); |
|
76 | + } |
|
77 | + else if ( ! $exception instanceof \Symfony\Component\Debug\Exception\FatalErrorException) |
|
78 | + { |
|
79 | + return parent::render($request, $exception); |
|
80 | + } |
|
81 | + } |
|
82 | + else |
|
83 | + { |
|
84 | + return parent::render($request, $exception); |
|
85 | + } |
|
86 | + } |
|
87 | 87 | } |
@@ -57,29 +57,23 @@ |
||
57 | 57 | if ($exception instanceof \Illuminate\Database\QueryException) |
58 | 58 | { |
59 | 59 | \ErrorHandler::dbQueryError(); |
60 | - } |
|
61 | - else if ($exception instanceof \predis\connection\connectionexception) |
|
60 | + } else if ($exception instanceof \predis\connection\connectionexception) |
|
62 | 61 | { |
63 | 62 | \ErrorHandler::redisNotRunning(); |
64 | - } |
|
65 | - else if ($exception instanceof \GuzzleHttp\Exception\ClientException) |
|
63 | + } else if ($exception instanceof \GuzzleHttp\Exception\ClientException) |
|
66 | 64 | { |
67 | 65 | \ErrorHandler::connectionError(); |
68 | - } |
|
69 | - else if ($exception instanceof \Symfony\Component\HttpKernel\Exception\HttpException) |
|
66 | + } else if ($exception instanceof \Symfony\Component\HttpKernel\Exception\HttpException) |
|
70 | 67 | { |
71 | 68 | return \Response::json($exception->getMessage(), $exception->getStatusCode()); |
72 | - } |
|
73 | - else if ($exception instanceof \Illuminate\Validation\ValidationException) |
|
69 | + } else if ($exception instanceof \Illuminate\Validation\ValidationException) |
|
74 | 70 | { |
75 | 71 | return \Response::json($exception->errors(), 422); |
76 | - } |
|
77 | - else if ( ! $exception instanceof \Symfony\Component\Debug\Exception\FatalErrorException) |
|
72 | + } else if ( ! $exception instanceof \Symfony\Component\Debug\Exception\FatalErrorException) |
|
78 | 73 | { |
79 | 74 | return parent::render($request, $exception); |
80 | 75 | } |
81 | - } |
|
82 | - else |
|
76 | + } else |
|
83 | 77 | { |
84 | 78 | return parent::render($request, $exception); |
85 | 79 | } |
@@ -7,15 +7,15 @@ |
||
7 | 7 | |
8 | 8 | class BroadcastServiceProvider extends ServiceProvider |
9 | 9 | { |
10 | - /** |
|
11 | - * Bootstrap any application services. |
|
12 | - * |
|
13 | - * @return void |
|
14 | - */ |
|
15 | - public function boot() |
|
16 | - { |
|
17 | - Broadcast::routes(['middleware' => ['auth:api']]); |
|
10 | + /** |
|
11 | + * Bootstrap any application services. |
|
12 | + * |
|
13 | + * @return void |
|
14 | + */ |
|
15 | + public function boot() |
|
16 | + { |
|
17 | + Broadcast::routes(['middleware' => ['auth:api']]); |
|
18 | 18 | |
19 | - require base_path('routes/channels.php'); |
|
20 | - } |
|
19 | + require base_path('routes/channels.php'); |
|
20 | + } |
|
21 | 21 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | * Get the notification's delivery channels. |
29 | 29 | * |
30 | 30 | * @param mixed $notifiable |
31 | - * @return array |
|
31 | + * @return string[] |
|
32 | 32 | */ |
33 | 33 | public function via($notifiable) |
34 | 34 | { |
@@ -6,7 +6,6 @@ |
||
6 | 6 | use Illuminate\Notifications\Notification; |
7 | 7 | use Illuminate\Contracts\Queue\ShouldQueue; |
8 | 8 | use Illuminate\Notifications\Messages\MailMessage; |
9 | -use Illuminate\Notifications\Messages\BroadcastMessage; |
|
10 | 9 | |
11 | 10 | class ConfirmEmail extends Notification implements ShouldQueue |
12 | 11 | { |
@@ -10,41 +10,41 @@ |
||
10 | 10 | |
11 | 11 | class ConfirmEmail extends Notification implements ShouldQueue |
12 | 12 | { |
13 | - use Queueable; |
|
13 | + use Queueable; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Create a new notification instance. |
|
17 | - * |
|
18 | - * @return void |
|
19 | - */ |
|
20 | - public function __construct() |
|
21 | - { |
|
22 | - // |
|
23 | - } |
|
15 | + /** |
|
16 | + * Create a new notification instance. |
|
17 | + * |
|
18 | + * @return void |
|
19 | + */ |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | + // |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Get the notification's delivery channels. |
|
27 | - * |
|
28 | - * @param mixed $notifiable |
|
29 | - * @return array |
|
30 | - */ |
|
31 | - public function via($notifiable) |
|
32 | - { |
|
33 | - return ['mail']; |
|
34 | - } |
|
25 | + /** |
|
26 | + * Get the notification's delivery channels. |
|
27 | + * |
|
28 | + * @param mixed $notifiable |
|
29 | + * @return array |
|
30 | + */ |
|
31 | + public function via($notifiable) |
|
32 | + { |
|
33 | + return ['mail']; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Get the mail representation of the notification. |
|
38 | - * |
|
39 | - * @param mixed $notifiable |
|
40 | - * @return \Illuminate\Notifications\Messages\MailMessage |
|
41 | - */ |
|
42 | - public function toMail($notifiable) |
|
43 | - { |
|
44 | - return (new MailMessage) |
|
45 | - ->subject('Email verification') |
|
46 | - ->line('Email verification') |
|
47 | - ->line('To validate your email click on the button below') |
|
48 | - ->action('Verify your email', config('skeleton.confrim_email_url') . '/' . $notifiable->confirmation_code); |
|
49 | - } |
|
36 | + /** |
|
37 | + * Get the mail representation of the notification. |
|
38 | + * |
|
39 | + * @param mixed $notifiable |
|
40 | + * @return \Illuminate\Notifications\Messages\MailMessage |
|
41 | + */ |
|
42 | + public function toMail($notifiable) |
|
43 | + { |
|
44 | + return (new MailMessage) |
|
45 | + ->subject('Email verification') |
|
46 | + ->line('Email verification') |
|
47 | + ->line('To validate your email click on the button below') |
|
48 | + ->action('Verify your email', config('skeleton.confrim_email_url') . '/' . $notifiable->confirmation_code); |
|
49 | + } |
|
50 | 50 | } |
51 | 51 | \ No newline at end of file |
@@ -45,6 +45,6 @@ |
||
45 | 45 | ->subject('Email verification') |
46 | 46 | ->line('Email verification') |
47 | 47 | ->line('To validate your email click on the button below') |
48 | - ->action('Verify your email', config('skeleton.confrim_email_url') . '/' . $notifiable->confirmation_code); |
|
48 | + ->action('Verify your email', config('skeleton.confrim_email_url').'/'.$notifiable->confirmation_code); |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | \ No newline at end of file |
@@ -9,37 +9,37 @@ |
||
9 | 9 | |
10 | 10 | class Kernel extends ConsoleKernel |
11 | 11 | { |
12 | - /** |
|
13 | - * The Artisan commands provided by your application. |
|
14 | - * |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $commands = [ |
|
18 | - GenerateDoc::class, |
|
19 | - MakeNotificationsCommand::class |
|
20 | - ]; |
|
12 | + /** |
|
13 | + * The Artisan commands provided by your application. |
|
14 | + * |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $commands = [ |
|
18 | + GenerateDoc::class, |
|
19 | + MakeNotificationsCommand::class |
|
20 | + ]; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Define the application's command schedule. |
|
24 | - * |
|
25 | - * @param \Illuminate\Console\Scheduling\Schedule $schedule |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - protected function schedule(Schedule $schedule) |
|
29 | - { |
|
30 | - // $schedule->command('inspire') |
|
31 | - // ->hourly(); |
|
32 | - } |
|
22 | + /** |
|
23 | + * Define the application's command schedule. |
|
24 | + * |
|
25 | + * @param \Illuminate\Console\Scheduling\Schedule $schedule |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + protected function schedule(Schedule $schedule) |
|
29 | + { |
|
30 | + // $schedule->command('inspire') |
|
31 | + // ->hourly(); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Register the commands for the application. |
|
36 | - * |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - protected function commands() |
|
40 | - { |
|
41 | - $this->load(__DIR__.'/Commands'); |
|
34 | + /** |
|
35 | + * Register the commands for the application. |
|
36 | + * |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + protected function commands() |
|
40 | + { |
|
41 | + $this->load(__DIR__.'/Commands'); |
|
42 | 42 | |
43 | - require base_path('routes/console.php'); |
|
44 | - } |
|
43 | + require base_path('routes/console.php'); |
|
44 | + } |
|
45 | 45 | } |
@@ -5,105 +5,105 @@ |
||
5 | 5 | |
6 | 6 | class LoginProxy |
7 | 7 | { |
8 | - private $apiConsumer; |
|
9 | - |
|
10 | - private $auth; |
|
11 | - |
|
12 | - private $db; |
|
13 | - |
|
14 | - private $request; |
|
15 | - |
|
16 | - private $userRepository; |
|
17 | - |
|
18 | - public function __construct(Application $app) |
|
19 | - { |
|
20 | - |
|
21 | - $this->userRepository = $app->make('App\Modules\Acl\Repositories\UserRepository'); |
|
22 | - $this->apiConsumer = $app->make('apiconsumer'); |
|
23 | - $this->auth = $app->make('auth'); |
|
24 | - $this->db = $app->make('db'); |
|
25 | - $this->request = $app->make('request'); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Attempt to create an access token using user credentials. |
|
30 | - * |
|
31 | - * @param array $credentials |
|
32 | - * @param boolean $adminLogin |
|
33 | - * @return array |
|
34 | - */ |
|
35 | - public function login($credentials, $adminLogin = false) |
|
36 | - { |
|
37 | - $this->userRepository->login($credentials, $adminLogin); |
|
38 | - |
|
39 | - return $this->proxy('password', [ |
|
40 | - 'username' => $credentials['email'], |
|
41 | - 'password' => $credentials['password'] |
|
42 | - ]); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Attempt to refresh the access token useing the given refresh token. |
|
47 | - * |
|
48 | - * @param string $refreshToken |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - public function refreshtoken($refreshToken) |
|
52 | - { |
|
53 | - return $this->proxy('refresh_token', [ |
|
54 | - 'refresh_token' => $refreshToken |
|
55 | - ]); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Proxy a request to the OAuth server. |
|
60 | - * |
|
61 | - * @param string $grantType what type of grant type should be proxied |
|
62 | - * @param array |
|
63 | - */ |
|
64 | - public function proxy($grantType, array $data = []) |
|
65 | - { |
|
66 | - $data = array_merge($data, [ |
|
67 | - 'client_id' => config('skeleton.passport_client_id'), |
|
68 | - 'client_secret' => config('skeleton.passport_client_secret'), |
|
69 | - 'grant_type' => $grantType |
|
70 | - ]); |
|
71 | - |
|
72 | - $response = $this->apiConsumer->post('/oauth/token', $data); |
|
73 | - |
|
74 | - if ( ! $response->isSuccessful()) |
|
75 | - { |
|
76 | - if ($grantType == 'refresh_token') |
|
77 | - { |
|
78 | - \ErrorHandler::invalidRefreshToken(); |
|
79 | - } |
|
80 | - |
|
81 | - \ErrorHandler::loginFailed(); |
|
82 | - } |
|
83 | - |
|
84 | - $data = json_decode($response->getContent()); |
|
85 | - |
|
86 | - return [ |
|
87 | - 'access_token' => $data->access_token, |
|
88 | - 'refresh_token' => $data->refresh_token, |
|
89 | - 'expires_in' => $data->expires_in |
|
90 | - ]; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Logs out the user. We revoke access token and refresh token. |
|
95 | - */ |
|
96 | - public function logout() |
|
97 | - { |
|
98 | - $accessToken = $this->auth->user()->token(); |
|
99 | - |
|
100 | - $this->db |
|
101 | - ->table('oauth_refresh_tokens') |
|
102 | - ->where('access_token_id', $accessToken->id) |
|
103 | - ->update([ |
|
104 | - 'revoked' => true |
|
105 | - ]); |
|
106 | - |
|
107 | - $accessToken->revoke(); |
|
108 | - } |
|
8 | + private $apiConsumer; |
|
9 | + |
|
10 | + private $auth; |
|
11 | + |
|
12 | + private $db; |
|
13 | + |
|
14 | + private $request; |
|
15 | + |
|
16 | + private $userRepository; |
|
17 | + |
|
18 | + public function __construct(Application $app) |
|
19 | + { |
|
20 | + |
|
21 | + $this->userRepository = $app->make('App\Modules\Acl\Repositories\UserRepository'); |
|
22 | + $this->apiConsumer = $app->make('apiconsumer'); |
|
23 | + $this->auth = $app->make('auth'); |
|
24 | + $this->db = $app->make('db'); |
|
25 | + $this->request = $app->make('request'); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Attempt to create an access token using user credentials. |
|
30 | + * |
|
31 | + * @param array $credentials |
|
32 | + * @param boolean $adminLogin |
|
33 | + * @return array |
|
34 | + */ |
|
35 | + public function login($credentials, $adminLogin = false) |
|
36 | + { |
|
37 | + $this->userRepository->login($credentials, $adminLogin); |
|
38 | + |
|
39 | + return $this->proxy('password', [ |
|
40 | + 'username' => $credentials['email'], |
|
41 | + 'password' => $credentials['password'] |
|
42 | + ]); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Attempt to refresh the access token useing the given refresh token. |
|
47 | + * |
|
48 | + * @param string $refreshToken |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + public function refreshtoken($refreshToken) |
|
52 | + { |
|
53 | + return $this->proxy('refresh_token', [ |
|
54 | + 'refresh_token' => $refreshToken |
|
55 | + ]); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Proxy a request to the OAuth server. |
|
60 | + * |
|
61 | + * @param string $grantType what type of grant type should be proxied |
|
62 | + * @param array |
|
63 | + */ |
|
64 | + public function proxy($grantType, array $data = []) |
|
65 | + { |
|
66 | + $data = array_merge($data, [ |
|
67 | + 'client_id' => config('skeleton.passport_client_id'), |
|
68 | + 'client_secret' => config('skeleton.passport_client_secret'), |
|
69 | + 'grant_type' => $grantType |
|
70 | + ]); |
|
71 | + |
|
72 | + $response = $this->apiConsumer->post('/oauth/token', $data); |
|
73 | + |
|
74 | + if ( ! $response->isSuccessful()) |
|
75 | + { |
|
76 | + if ($grantType == 'refresh_token') |
|
77 | + { |
|
78 | + \ErrorHandler::invalidRefreshToken(); |
|
79 | + } |
|
80 | + |
|
81 | + \ErrorHandler::loginFailed(); |
|
82 | + } |
|
83 | + |
|
84 | + $data = json_decode($response->getContent()); |
|
85 | + |
|
86 | + return [ |
|
87 | + 'access_token' => $data->access_token, |
|
88 | + 'refresh_token' => $data->refresh_token, |
|
89 | + 'expires_in' => $data->expires_in |
|
90 | + ]; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Logs out the user. We revoke access token and refresh token. |
|
95 | + */ |
|
96 | + public function logout() |
|
97 | + { |
|
98 | + $accessToken = $this->auth->user()->token(); |
|
99 | + |
|
100 | + $this->db |
|
101 | + ->table('oauth_refresh_tokens') |
|
102 | + ->where('access_token_id', $accessToken->id) |
|
103 | + ->update([ |
|
104 | + 'revoked' => true |
|
105 | + ]); |
|
106 | + |
|
107 | + $accessToken->revoke(); |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | \ No newline at end of file |
@@ -2,9 +2,9 @@ discard block |
||
2 | 2 | |
3 | 3 | class CoreConfig |
4 | 4 | { |
5 | - public function getConfig() |
|
6 | - { |
|
7 | - return [ |
|
5 | + public function getConfig() |
|
6 | + { |
|
7 | + return [ |
|
8 | 8 | /** |
9 | 9 | * Specify what relations should be used for every model. |
10 | 10 | */ |
@@ -14,5 +14,5 @@ discard block |
||
14 | 14 | */ |
15 | 15 | 'cacheConfig' => config('skeleton.cache_config'), |
16 | 16 | ]; |
17 | - } |
|
17 | + } |
|
18 | 18 | } |
19 | 19 | \ No newline at end of file |
@@ -6,38 +6,38 @@ |
||
6 | 6 | |
7 | 7 | class ApiSkeletonServiceProvider extends ServiceProvider |
8 | 8 | { |
9 | - /** |
|
10 | - * Perform post-registration booting of services. |
|
11 | - * |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function boot() |
|
15 | - { |
|
16 | - $this->publishes([ |
|
17 | - __DIR__.'/Modules' => app_path('Modules'), |
|
18 | - __DIR__.'/Modules/Core/Resources/Assets' => base_path('public/doc/assets'), |
|
19 | - __DIR__.'/../lang' => base_path('resources/lang'), |
|
20 | - __DIR__.'/../files/Handler.php' => app_path('Exceptions/Handler.php'), |
|
21 | - __DIR__.'/../files/AuthServiceProvider.php' => app_path('Providers/AuthServiceProvider.php'), |
|
22 | - __DIR__.'/../files/BroadcastServiceProvider.php' => app_path('Providers/BroadcastServiceProvider.php'), |
|
23 | - __DIR__.'/../files/Kernel.php' => app_path('Console/Kernel.php'), |
|
24 | - ]); |
|
9 | + /** |
|
10 | + * Perform post-registration booting of services. |
|
11 | + * |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function boot() |
|
15 | + { |
|
16 | + $this->publishes([ |
|
17 | + __DIR__.'/Modules' => app_path('Modules'), |
|
18 | + __DIR__.'/Modules/Core/Resources/Assets' => base_path('public/doc/assets'), |
|
19 | + __DIR__.'/../lang' => base_path('resources/lang'), |
|
20 | + __DIR__.'/../files/Handler.php' => app_path('Exceptions/Handler.php'), |
|
21 | + __DIR__.'/../files/AuthServiceProvider.php' => app_path('Providers/AuthServiceProvider.php'), |
|
22 | + __DIR__.'/../files/BroadcastServiceProvider.php' => app_path('Providers/BroadcastServiceProvider.php'), |
|
23 | + __DIR__.'/../files/Kernel.php' => app_path('Console/Kernel.php'), |
|
24 | + ]); |
|
25 | 25 | |
26 | - $this->publishes([ |
|
27 | - __DIR__.'/../config/skeleton.php' => config_path('skeleton.php'), |
|
28 | - __DIR__.'/../files/auth.php' => config_path('auth.php'), |
|
29 | - ], 'config'); |
|
30 | - } |
|
26 | + $this->publishes([ |
|
27 | + __DIR__.'/../config/skeleton.php' => config_path('skeleton.php'), |
|
28 | + __DIR__.'/../files/auth.php' => config_path('auth.php'), |
|
29 | + ], 'config'); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Register any package services. |
|
34 | - * |
|
35 | - * @return void |
|
36 | - */ |
|
37 | - public function register() |
|
38 | - { |
|
39 | - $this->mergeConfigFrom( |
|
40 | - __DIR__.'/../config/skeleton.php', 'skeleton' |
|
41 | - ); |
|
42 | - } |
|
32 | + /** |
|
33 | + * Register any package services. |
|
34 | + * |
|
35 | + * @return void |
|
36 | + */ |
|
37 | + public function register() |
|
38 | + { |
|
39 | + $this->mergeConfigFrom( |
|
40 | + __DIR__.'/../config/skeleton.php', 'skeleton' |
|
41 | + ); |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -2,117 +2,117 @@ |
||
2 | 2 | |
3 | 3 | class ErrorHandler |
4 | 4 | { |
5 | - public function unAuthorized() |
|
6 | - { |
|
7 | - $error = ['status' => 401, 'message' => trans('core::errors.unAuthorized')]; |
|
8 | - abort($error['status'], $error['message']); |
|
9 | - } |
|
10 | - |
|
11 | - public function invalidRefreshToken() |
|
12 | - { |
|
13 | - $error = ['status' => 400, 'message' => trans('core::errors.invalidRefreshToken')]; |
|
14 | - abort($error['status'], $error['message']); |
|
15 | - } |
|
16 | - |
|
17 | - public function noPermissions() |
|
18 | - { |
|
19 | - $error = ['status' => 403, 'message' => trans('core::errors.noPermissions')]; |
|
20 | - abort($error['status'], $error['message']); |
|
21 | - } |
|
22 | - |
|
23 | - public function loginFailed() |
|
24 | - { |
|
25 | - $error = ['status' => 400, 'message' => trans('core::errors.loginFailed')]; |
|
26 | - abort($error['status'], $error['message']); |
|
27 | - } |
|
28 | - |
|
29 | - public function noSocialEmail() |
|
30 | - { |
|
31 | - $error = ['status' => 400, 'message' => trans('core::errors.noSocialEmail')]; |
|
32 | - abort($error['status'], $error['message']); |
|
33 | - } |
|
34 | - |
|
35 | - public function userAlreadyRegistered() |
|
36 | - { |
|
37 | - $error = ['status' => 400, 'message' => trans('core::errors.userAlreadyRegistered')]; |
|
38 | - abort($error['status'], $error['message']); |
|
39 | - } |
|
40 | - |
|
41 | - public function connectionError() |
|
42 | - { |
|
43 | - $error = ['status' => 400, 'message' => trans('core::errors.connectionError')]; |
|
44 | - abort($error['status'], $error['message']); |
|
45 | - } |
|
46 | - |
|
47 | - public function redisNotRunning() |
|
48 | - { |
|
49 | - $error = ['status' => 400, 'message' => trans('core::errors.redisNotRunning')]; |
|
50 | - abort($error['status'], $error['message']); |
|
51 | - } |
|
52 | - |
|
53 | - public function dbQueryError() |
|
54 | - { |
|
55 | - $error = ['status' => 400, 'message' => trans('core::errors.dbQueryError')]; |
|
56 | - abort($error['status'], $error['message']); |
|
57 | - } |
|
58 | - |
|
59 | - public function cannotCreateSetting() |
|
60 | - { |
|
61 | - $error = ['status' => 400, 'message' => trans('core::errors.cannotCreateSetting')]; |
|
62 | - abort($error['status'], $error['message']); |
|
63 | - } |
|
64 | - |
|
65 | - public function cannotUpdateSettingKey() |
|
66 | - { |
|
67 | - $error = ['status' => 400, 'message' => trans('core::errors.cannotUpdateSettingKey')]; |
|
68 | - abort($error['status'], $error['message']); |
|
69 | - } |
|
70 | - |
|
71 | - public function userIsBlocked() |
|
72 | - { |
|
73 | - $error = ['status' => 403, 'message' => trans('core::errors.userIsBlocked')]; |
|
74 | - abort($error['status'], $error['message']); |
|
75 | - } |
|
76 | - |
|
77 | - public function emailNotConfirmed() |
|
78 | - { |
|
79 | - $error = ['status' => 403, 'message' => trans('core::errors.emailNotConfirmed')]; |
|
80 | - abort($error['status'], $error['message']); |
|
81 | - } |
|
82 | - |
|
83 | - public function emailAlreadyConfirmed() |
|
84 | - { |
|
85 | - $error = ['status' => 403, 'message' => trans('core::errors.emailAlreadyConfirmed')]; |
|
86 | - abort($error['status'], $error['message']); |
|
87 | - } |
|
88 | - |
|
89 | - public function invalidResetToken() |
|
90 | - { |
|
91 | - $error = ['status' => 400, 'message' => trans('core::errors.invalidResetToken')]; |
|
92 | - abort($error['status'], $error['message']); |
|
93 | - } |
|
94 | - |
|
95 | - public function invalidResetPassword() |
|
96 | - { |
|
97 | - $error = ['status' => 400, 'message' => trans('core::errors.invalidResetPassword')]; |
|
98 | - abort($error['status'], $error['message']); |
|
99 | - } |
|
100 | - |
|
101 | - public function invalidOldPassword() |
|
102 | - { |
|
103 | - $error = ['status' => 400, 'message' => trans('core::errors.invalidOldPassword')]; |
|
104 | - abort($error['status'], $error['message']); |
|
105 | - } |
|
106 | - |
|
107 | - public function notFound($text) |
|
108 | - { |
|
109 | - $error = ['status' => 404, 'message' => trans('core::errors.notFound', ['replace' => $text])]; |
|
110 | - abort($error['status'], $error['message']); |
|
111 | - } |
|
112 | - |
|
113 | - public function generalError() |
|
114 | - { |
|
115 | - $error = ['status' => 400, 'message' => trans('core::errors.generalError')]; |
|
116 | - abort($error['status'], $error['message']); |
|
117 | - } |
|
5 | + public function unAuthorized() |
|
6 | + { |
|
7 | + $error = ['status' => 401, 'message' => trans('core::errors.unAuthorized')]; |
|
8 | + abort($error['status'], $error['message']); |
|
9 | + } |
|
10 | + |
|
11 | + public function invalidRefreshToken() |
|
12 | + { |
|
13 | + $error = ['status' => 400, 'message' => trans('core::errors.invalidRefreshToken')]; |
|
14 | + abort($error['status'], $error['message']); |
|
15 | + } |
|
16 | + |
|
17 | + public function noPermissions() |
|
18 | + { |
|
19 | + $error = ['status' => 403, 'message' => trans('core::errors.noPermissions')]; |
|
20 | + abort($error['status'], $error['message']); |
|
21 | + } |
|
22 | + |
|
23 | + public function loginFailed() |
|
24 | + { |
|
25 | + $error = ['status' => 400, 'message' => trans('core::errors.loginFailed')]; |
|
26 | + abort($error['status'], $error['message']); |
|
27 | + } |
|
28 | + |
|
29 | + public function noSocialEmail() |
|
30 | + { |
|
31 | + $error = ['status' => 400, 'message' => trans('core::errors.noSocialEmail')]; |
|
32 | + abort($error['status'], $error['message']); |
|
33 | + } |
|
34 | + |
|
35 | + public function userAlreadyRegistered() |
|
36 | + { |
|
37 | + $error = ['status' => 400, 'message' => trans('core::errors.userAlreadyRegistered')]; |
|
38 | + abort($error['status'], $error['message']); |
|
39 | + } |
|
40 | + |
|
41 | + public function connectionError() |
|
42 | + { |
|
43 | + $error = ['status' => 400, 'message' => trans('core::errors.connectionError')]; |
|
44 | + abort($error['status'], $error['message']); |
|
45 | + } |
|
46 | + |
|
47 | + public function redisNotRunning() |
|
48 | + { |
|
49 | + $error = ['status' => 400, 'message' => trans('core::errors.redisNotRunning')]; |
|
50 | + abort($error['status'], $error['message']); |
|
51 | + } |
|
52 | + |
|
53 | + public function dbQueryError() |
|
54 | + { |
|
55 | + $error = ['status' => 400, 'message' => trans('core::errors.dbQueryError')]; |
|
56 | + abort($error['status'], $error['message']); |
|
57 | + } |
|
58 | + |
|
59 | + public function cannotCreateSetting() |
|
60 | + { |
|
61 | + $error = ['status' => 400, 'message' => trans('core::errors.cannotCreateSetting')]; |
|
62 | + abort($error['status'], $error['message']); |
|
63 | + } |
|
64 | + |
|
65 | + public function cannotUpdateSettingKey() |
|
66 | + { |
|
67 | + $error = ['status' => 400, 'message' => trans('core::errors.cannotUpdateSettingKey')]; |
|
68 | + abort($error['status'], $error['message']); |
|
69 | + } |
|
70 | + |
|
71 | + public function userIsBlocked() |
|
72 | + { |
|
73 | + $error = ['status' => 403, 'message' => trans('core::errors.userIsBlocked')]; |
|
74 | + abort($error['status'], $error['message']); |
|
75 | + } |
|
76 | + |
|
77 | + public function emailNotConfirmed() |
|
78 | + { |
|
79 | + $error = ['status' => 403, 'message' => trans('core::errors.emailNotConfirmed')]; |
|
80 | + abort($error['status'], $error['message']); |
|
81 | + } |
|
82 | + |
|
83 | + public function emailAlreadyConfirmed() |
|
84 | + { |
|
85 | + $error = ['status' => 403, 'message' => trans('core::errors.emailAlreadyConfirmed')]; |
|
86 | + abort($error['status'], $error['message']); |
|
87 | + } |
|
88 | + |
|
89 | + public function invalidResetToken() |
|
90 | + { |
|
91 | + $error = ['status' => 400, 'message' => trans('core::errors.invalidResetToken')]; |
|
92 | + abort($error['status'], $error['message']); |
|
93 | + } |
|
94 | + |
|
95 | + public function invalidResetPassword() |
|
96 | + { |
|
97 | + $error = ['status' => 400, 'message' => trans('core::errors.invalidResetPassword')]; |
|
98 | + abort($error['status'], $error['message']); |
|
99 | + } |
|
100 | + |
|
101 | + public function invalidOldPassword() |
|
102 | + { |
|
103 | + $error = ['status' => 400, 'message' => trans('core::errors.invalidOldPassword')]; |
|
104 | + abort($error['status'], $error['message']); |
|
105 | + } |
|
106 | + |
|
107 | + public function notFound($text) |
|
108 | + { |
|
109 | + $error = ['status' => 404, 'message' => trans('core::errors.notFound', ['replace' => $text])]; |
|
110 | + abort($error['status'], $error['message']); |
|
111 | + } |
|
112 | + |
|
113 | + public function generalError() |
|
114 | + { |
|
115 | + $error = ['status' => 400, 'message' => trans('core::errors.generalError')]; |
|
116 | + abort($error['status'], $error['message']); |
|
117 | + } |
|
118 | 118 | } |
119 | 119 | \ No newline at end of file |