|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace bSecure\UniversalCheckout\Controllers\SSO; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
//Helper |
|
9
|
|
|
use bSecure\UniversalCheckout\Helpers\AppException; |
|
|
|
|
|
|
10
|
|
|
use bSecure\UniversalCheckout\Helpers\Constant; |
|
11
|
|
|
use bSecure\UniversalCheckout\Helpers\ApiResponseHandler; |
|
12
|
|
|
use bSecure\UniversalCheckout\Helpers\Helper; |
|
13
|
|
|
|
|
14
|
|
|
//Facade |
|
15
|
|
|
use Validator; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
class VerifyClientController extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Author: Sara Hasan |
|
22
|
|
|
* Date: 26-November-2020 |
|
23
|
|
|
*/ |
|
24
|
|
|
public function verifyClient($state,$appType) |
|
25
|
|
|
{ |
|
26
|
|
|
try { |
|
27
|
|
|
|
|
28
|
|
|
$validationErrors = $this->_checkForValidationRule( $state ); |
|
29
|
|
|
|
|
30
|
|
|
if( count( $validationErrors ) > 0 ) |
|
31
|
|
|
{ |
|
32
|
|
|
return ApiResponseHandler::validationError( $validationErrors ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
$ssoPayload = $this->createSSODataStructure($state); |
|
37
|
|
|
|
|
38
|
|
|
if($appType == Constant::APP_TYPE['checkout']) |
|
39
|
|
|
{ |
|
40
|
|
|
$auth_url = $this->_createAuthenticationURL($ssoPayload); |
|
41
|
|
|
$response = [ |
|
42
|
|
|
'redirect_url' => $auth_url |
|
43
|
|
|
]; |
|
44
|
|
|
return ApiResponseHandler::success($response, trans('bSecure::messages.sso_sco.success')); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
else if ($appType == Constant::APP_TYPE['sdk']) |
|
47
|
|
|
{ |
|
48
|
|
|
$ssoResponse = Helper::verifyClient($ssoPayload); |
|
49
|
|
|
if($ssoResponse['error']) |
|
50
|
|
|
{ |
|
51
|
|
|
return ApiResponseHandler::failure($ssoResponse['message']); |
|
52
|
|
|
}else{ |
|
53
|
|
|
$response = $ssoResponse['body']; |
|
54
|
|
|
return ApiResponseHandler::success($response, trans('bSecure::messages.sso_sco.success')); |
|
55
|
|
|
} |
|
56
|
|
|
}else{ |
|
57
|
|
|
return ApiResponseHandler::failure('Invalid application type', []); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
} catch (\Exception $e) { |
|
61
|
|
|
return ApiResponseHandler::failure(trans('bSecure::messages.sso_sco.failure'), $e->getTraceAsString()); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Author: Sara Hasan |
|
67
|
|
|
* Date: 26-November-2020 |
|
68
|
|
|
*/ |
|
69
|
|
|
private function createSSODataStructure($state) |
|
70
|
|
|
{ |
|
71
|
|
|
$sso_client = []; |
|
72
|
|
|
|
|
73
|
|
|
$sso_client['client_id'] = config('bSecure.client_id'); |
|
|
|
|
|
|
74
|
|
|
$sso_client['scope'] = "profile"; |
|
75
|
|
|
$sso_client['response_type'] = "code"; |
|
76
|
|
|
$sso_client['state'] = $state; |
|
77
|
|
|
|
|
78
|
|
|
return $sso_client; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Author: Sara Hasan |
|
83
|
|
|
* Date: 27-November-2020 |
|
84
|
|
|
*/ |
|
85
|
|
|
private function _createAuthenticationURL($sso_client) |
|
86
|
|
|
{ |
|
87
|
|
|
$login_app_url = Constant::LOGIN_REDIRECT_URL; |
|
88
|
|
|
|
|
89
|
|
|
$client_id = $sso_client['client_id']; |
|
90
|
|
|
$scope = $sso_client['scope']; |
|
91
|
|
|
$response_type = $sso_client['response_type']; |
|
92
|
|
|
$state = $sso_client['state']; |
|
93
|
|
|
|
|
94
|
|
|
return $login_app_url.'?scope='.$scope.'&response_type='.$response_type.'&client_id='.$client_id.'&state='.$state; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Author: Sara Hasan |
|
100
|
|
|
* Date: 27-November-2020 |
|
101
|
|
|
*/ |
|
102
|
|
|
private function _checkForValidationRule($state ) |
|
103
|
|
|
{ |
|
104
|
|
|
$errors = []; |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
if( empty($state) ) |
|
108
|
|
|
{ |
|
109
|
|
|
$errors[] = trans('bSecure::messages.validation.state.required'); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return $errors; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths