Conditions | 12 |
Paths | 385 |
Total Lines | 81 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 8 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
164 | public function main(Request $request): Template |
||
165 | { |
||
166 | $this->logger::info('FIDO2 - Accessing WebAuthn interface'); |
||
167 | |||
168 | $stateId = $request->query->get('StateId'); |
||
169 | if ($stateId === null) { |
||
170 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
171 | } |
||
172 | |||
173 | $state = $this->authState::loadState($stateId, 'webauthn:request'); |
||
174 | |||
175 | if ($this->workflowStateMachine($state) != self::STATE_AUTH_NOMGMT) { |
||
|
|||
176 | $templateFile = 'webauthn:webauthn.twig'; |
||
177 | } else { |
||
178 | $templateFile = 'webauthn:authentication.twig'; |
||
179 | } |
||
180 | |||
181 | // Make, populate and layout consent form |
||
182 | $t = new Template($this->config, $templateFile); |
||
183 | $t->data['UserID'] = $state['FIDO2Username']; |
||
184 | $t->data['FIDO2Tokens'] = $state['FIDO2Tokens']; |
||
185 | // in case IdPs want to override UI and display SP-specific content |
||
186 | $t->data['entityid'] = $state['SPMetadata']['entityid'] ?? 'WEBAUTHN-SP-NONE'; |
||
187 | |||
188 | $challenge = str_split($state['FIDO2SignupChallenge'], 2); |
||
189 | $configUtils = new Utils\Config(); |
||
190 | $username = str_split( |
||
191 | hash('sha512', $state['FIDO2Username'] . '|' . $configUtils->getSecretSalt()), |
||
192 | 2, |
||
193 | ); |
||
194 | |||
195 | $challengeEncoded = []; |
||
196 | foreach ($challenge as $oneChar) { |
||
197 | $challengeEncoded[] = hexdec($oneChar); |
||
198 | } |
||
199 | |||
200 | $credentialIdEncoded = []; |
||
201 | foreach ($state['FIDO2Tokens'] as $number => $token) { |
||
202 | $idSplit = str_split($token[0], 2); |
||
203 | $credentialIdEncoded[$number] = []; |
||
204 | foreach ($idSplit as $credIdBlock) { |
||
205 | $credentialIdEncoded[$number][] = hexdec($credIdBlock); |
||
206 | } |
||
207 | } |
||
208 | |||
209 | $usernameEncoded = []; |
||
210 | foreach ($username as $oneChar) { |
||
211 | $usernameEncoded[] = hexdec($oneChar); |
||
212 | } |
||
213 | |||
214 | $frontendData = []; |
||
215 | $frontendData['challengeEncoded'] = $challengeEncoded; |
||
216 | $frontendData['state'] = []; |
||
217 | foreach (['FIDO2Scope','FIDO2Username','FIDO2Displayname','requestTokenModel'] as $stateItem) { |
||
218 | $frontendData['state'][$stateItem] = $state[$stateItem]; |
||
219 | } |
||
220 | |||
221 | $t->data['showExitButton'] = !array_key_exists('Registration', $state); |
||
222 | $frontendData['usernameEncoded'] = $usernameEncoded; |
||
223 | $frontendData['attestation'] = $state['requestTokenModel'] ? "indirect" : "none"; |
||
224 | $frontendData['credentialIdEncoded'] = $credentialIdEncoded; |
||
225 | $frontendData['FIDO2PasswordlessAuthMode'] = $state['FIDO2PasswordlessAuthMode']; |
||
226 | $t->data['frontendData'] = json_encode($frontendData); |
||
227 | |||
228 | $t->data['FIDO2AuthSuccessful'] = $state['FIDO2AuthSuccessful']; |
||
229 | if ($this->workflowStateMachine($state) == self::STATE_MGMT) { |
||
230 | $t->data['regURL'] = Module::getModuleURL('webauthn/regprocess?StateId=' . urlencode($stateId)); |
||
231 | $t->data['delURL'] = Module::getModuleURL('webauthn/managetoken?StateId=' . urlencode($stateId)); |
||
232 | } |
||
233 | |||
234 | $t->data['authForm'] = ""; |
||
235 | if ( |
||
236 | $this->workflowStateMachine($state) == self::STATE_AUTH_ALLOWMGMT || |
||
237 | $this->workflowStateMachine($state) == self::STATE_AUTH_NOMGMT |
||
238 | ) { |
||
239 | $t->data['authURL'] = Module::getModuleURL('webauthn/authprocess?StateId=' . urlencode($stateId)); |
||
240 | $t->data['delURL'] = Module::getModuleURL('webauthn/managetoken?StateId=' . urlencode($stateId)); |
||
241 | } |
||
242 | |||
243 | // dynamically generate the JS code needed for token registration |
||
244 | return $t; |
||
245 | } |
||
247 |