| Conditions | 8 |
| Paths | 49 |
| Total Lines | 67 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 26 | public function main(Request $request): Template |
||
| 27 | { |
||
| 28 | $this->logger::info('FIDO2 - Accessing Supercharged interface'); |
||
| 29 | |||
| 30 | $stateId = $request->query->get('StateId'); |
||
| 31 | if ($stateId === null) { |
||
| 32 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
| 33 | } |
||
| 34 | |||
| 35 | $state = $this->authState::loadState($stateId, 'webauthn:request'); |
||
| 36 | |||
| 37 | $templateFile = 'webauthn:supercharged.twig'; |
||
| 38 | |||
| 39 | // Make, populate and layout consent form |
||
| 40 | $t = new Template($this->config, $templateFile); |
||
| 41 | $t->data['UserID'] = $state['FIDO2Username']; |
||
| 42 | $t->data['FIDO2Tokens'] = $state['FIDO2Tokens']; |
||
| 43 | // in case IdPs want to override UI and display SP-specific content |
||
| 44 | $t->data['entityid'] = $state['SPMetadata']['entityid'] ?? 'WEBAUTHN-SP-NONE'; |
||
| 45 | |||
| 46 | $challenge = str_split($state['FIDO2SignupChallenge'], 2); |
||
| 47 | $configUtils = new Utils\Config(); |
||
| 48 | $username = str_split( |
||
| 49 | hash('sha512', $state['FIDO2Username'] . '|' . $configUtils->getSecretSalt()), |
||
| 50 | 2, |
||
| 51 | ); |
||
| 52 | |||
| 53 | $challengeEncoded = []; |
||
| 54 | foreach ($challenge as $oneChar) { |
||
| 55 | $challengeEncoded[] = hexdec($oneChar); |
||
| 56 | } |
||
| 57 | |||
| 58 | $credentialIdEncoded = []; |
||
| 59 | foreach ($state['FIDO2Tokens'] as $number => $token) { |
||
| 60 | $idSplit = str_split($token[0], 2); |
||
| 61 | $credentialIdEncoded[$number] = []; |
||
| 62 | foreach ($idSplit as $credIdBlock) { |
||
| 63 | $credentialIdEncoded[$number][] = hexdec($credIdBlock); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | $usernameEncoded = []; |
||
| 68 | foreach ($username as $oneChar) { |
||
| 69 | $usernameEncoded[] = hexdec($oneChar); |
||
| 70 | } |
||
| 71 | |||
| 72 | $frontendData = []; |
||
| 73 | $frontendData['challengeEncoded'] = $challengeEncoded; |
||
| 74 | $frontendData['state'] = []; |
||
| 75 | foreach (['FIDO2Scope','FIDO2Username','FIDO2Displayname','requestTokenModel'] as $stateItem) { |
||
| 76 | $frontendData['state'][$stateItem] = $state[$stateItem]; |
||
| 77 | } |
||
| 78 | |||
| 79 | $t->data['showExitButton'] = !array_key_exists('Registration', $state); |
||
| 80 | $frontendData['usernameEncoded'] = $usernameEncoded; |
||
| 81 | $frontendData['attestation'] = $state['requestTokenModel'] ? "indirect" : "none"; |
||
| 82 | $frontendData['credentialIdEncoded'] = $credentialIdEncoded; |
||
| 83 | $frontendData['FIDO2PasswordlessAuthMode'] = $state['FIDO2PasswordlessAuthMode']; |
||
| 84 | $t->data['hasPreviouslyDonePasswordless'] = $_COOKIE['SuccessfullyUsedPasswordlessBefore'] ?? "NO"; |
||
| 85 | $t->data['frontendData'] = json_encode($frontendData); |
||
| 86 | |||
| 87 | $t->data['authForm'] = ""; |
||
| 88 | $t->data['authURL'] = Module::getModuleURL('webauthn/authprocess?StateId=' . urlencode($stateId)); |
||
| 89 | $t->data['pushbackURL'] = Module::getModuleURL('webauthn/pushbackuserpass?StateId=' . urlencode($stateId)); |
||
| 90 | |||
| 91 | // dynamically generate the JS code needed for token registration |
||
| 92 | return $t; |
||
| 93 | } |
||
| 95 |