|
16 | 16 | $clientId = $conf->getString(CSCMfa::CLIENT_ID, ''); |
17 | 17 | if (empty($clientId)) { |
18 | 18 | throw new Exception( |
19 | | - 'elixir:CSCMfa_continue: missing mandatory configuration option "' . CSCMfa::CLIENT_ID . |
20 | | - '" in configuration file "' . CSCMfa::CONFIG_FILE_NAME . '".' |
| 19 | + 'elixir:CSCMfa_continue: missing mandatory configuration option "' . CSCMfa::CLIENT_ID . '" in configuration file "' . CSCMfa::CONFIG_FILE_NAME . '".' |
21 | 20 | ); |
22 | 21 | } |
23 | 22 |
|
24 | 23 | $clientSecret = $conf->getString(CSCMfa::CLIENT_SECRET, ''); |
25 | 24 | if (empty($clientSecret)) { |
26 | 25 | throw new Exception( |
27 | | - 'elixir:CSCMfa_continue: missing mandatory configuration option "' . CSCMfa::CLIENT_SECRET . |
28 | | - '" in configuration file "' . CSCMfa::CONFIG_FILE_NAME . '".' |
| 26 | + 'elixir:CSCMfa_continue: missing mandatory configuration option "' . CSCMfa::CLIENT_SECRET . '" in configuration file "' . CSCMfa::CONFIG_FILE_NAME . '".' |
29 | 27 | ); |
30 | 28 | } |
31 | 29 |
|
32 | 30 | $openidConfigurationUrl = $conf->getString(CSCMfa::OPENID_CONFIGURATION_URL, ''); |
33 | 31 | if (empty($openidConfigurationUrl)) { |
34 | 32 | throw new Exception( |
35 | | - 'elixir:CSCMfa_continue: missing mandatory configuration option "' . CSCMfa::TOKEN_ENDPOINT . |
36 | | - '" in configuration file "' . CSCMfa::CONFIG_FILE_NAME . '".' |
| 33 | + 'elixir:CSCMfa_continue: missing mandatory configuration option "' . CSCMfa::TOKEN_ENDPOINT . '" in configuration file "' . CSCMfa::CONFIG_FILE_NAME . '".' |
37 | 34 | ); |
38 | 35 | } |
39 | 36 |
|
|
47 | 44 | $mfaUserInfoUrl = $metadata[CSCMfa::USERINFO_ENDPOINT]; |
48 | 45 | } |
49 | 46 |
|
50 | | -if ($mfaTokenUrl === null || $mfaUserInfoUrl === null) { |
| 47 | +if (null === $mfaTokenUrl || null === $mfaUserInfoUrl) { |
51 | 48 | throw new Exception( |
52 | | - 'elixir:CSCMfa_continue: Problem to get ' . CSCMfa::TOKEN_ENDPOINT . ' or ' . |
53 | | - CSCMfa::USERINFO_ENDPOINT . ' from Openid configuration.' |
| 49 | + 'elixir:CSCMfa_continue: Problem to get ' . CSCMfa::TOKEN_ENDPOINT . ' or ' . CSCMfa::USERINFO_ENDPOINT . ' from Openid configuration.' |
54 | 50 | ); |
55 | 51 | } |
56 | 52 |
|
57 | 53 | $redirectUri = Module::getModuleURL('elixir') . '/CSCMfa_continue.php'; |
58 | 54 |
|
59 | | -if (! isset($_GET['code'], $_GET['state'])) { |
| 55 | +if (!isset($_GET['code'], $_GET['state'])) { |
60 | 56 | throw new Exception('elixir:CSCMfa_continue: One of following required params: "code", "state" is missing.'); |
61 | 57 | } |
62 | 58 |
|
|
65 | 61 |
|
66 | 62 | $state = State::loadState($stateId, 'elixir:CSCMfa'); |
67 | 63 |
|
68 | | -# Prepare params for token endpoint |
| 64 | +// Prepare params for token endpoint |
69 | 65 | $params = [ |
70 | 66 | 'code' => $code, |
71 | 67 | 'grant_type' => 'authorization_code', |
|
75 | 71 | 'nonce' => time(), |
76 | 72 | ]; |
77 | 73 |
|
78 | | -# Request to token endpoint |
| 74 | +// Request to token endpoint |
79 | 75 | $ch = curl_init(); |
80 | 76 | curl_setopt($ch, CURLOPT_URL, $mfaTokenUrl); |
81 | 77 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
82 | 78 | curl_setopt($ch, CURLOPT_POST, true); |
83 | 79 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); |
84 | 80 | $response = curl_exec($ch); |
85 | 81 |
|
86 | | -if ($response === false) { |
| 82 | +if (false === $response) { |
87 | 83 | throw new \Exception("Request to token endpoint wasn't successful : " . curl_error($ch)); |
88 | 84 | } |
89 | 85 | $response = json_decode($response, true); |
|
102 | 98 | 'access_token' => $accessToken, |
103 | 99 | ]; |
104 | 100 |
|
105 | | -# Request to userinfo endpoint |
| 101 | +// Request to userinfo endpoint |
106 | 102 | $ch = curl_init(); |
107 | 103 | curl_setopt($ch, CURLOPT_URL, $mfaUserInfoUrl); |
108 | 104 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
109 | 105 | curl_setopt($ch, CURLOPT_POST, true); |
110 | 106 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); |
111 | 107 | curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $accessToken]); |
112 | 108 | $response = curl_exec($ch); |
113 | | -if ($response === false) { |
| 109 | +if (false === $response) { |
114 | 110 | throw new \Exception("Request to token endpoint wasn't successful : " . curl_error($ch)); |
115 | 111 | } |
116 | 112 |
|
|
0 commit comments