Passed
Push — master ( df7a06...000e40 )
by Tim
03:26
created

StaticProcessHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 37
rs 10
c 3
b 0
f 0
eloc 25
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A saveStateAndRedirect() 0 6 1
A prepareState() 0 14 1
A prepareStatePasswordlessAuth() 0 11 1
1
<?php
2
3
namespace SimpleSAML\Module\webauthn\WebAuthn;
4
5
use SimpleSAML\Auth;
6
use SimpleSAML\Module;
7
use SimpleSAML\Module\webauthn\WebAuthn\StateData;
8
use SimpleSAML\Utils;
9
10
class StaticProcessHelper
11
{
12
    public static function saveStateAndRedirect(array &$state): void
13
    {
14
        $id = Auth\State::saveState($state, 'webauthn:request');
15
        $url = Module::getModuleURL('webauthn/webauthn');
16
        $httpUtils = new Utils\HTTP();
17
        $httpUtils->redirectTrustedURL($url, ['StateId' => $id]);
18
    }
19
20
    public static function prepareState(StateData $stateData, array &$state): void
21
    {
22
        $state['requestTokenModel'] = $stateData->requestTokenModel;
23
        $state['webauthn:store'] = $stateData->store;
24
        $state['FIDO2Tokens'] = $stateData->store->getTokenData($state['Attributes'][$stateData->usernameAttrib][0]);
25
        $state['FIDO2Scope'] = $stateData->scope;
26
        $state['FIDO2DerivedScope'] = $stateData->derivedScope;
27
        $state['FIDO2AttributeStoringUsername'] = $stateData->usernameAttrib;
28
        $state['FIDO2Username'] = $state['Attributes'][$stateData->usernameAttrib][0];
29
        $state['FIDO2Displayname'] = $state['Attributes'][$stateData->displaynameAttrib][0];
30
        $state['FIDO2SignupChallenge'] = hash('sha512', random_bytes(64));
31
        $state['FIDO2WantsRegister'] = false;
32
        $state['FIDO2AuthSuccessful'] = false;
33
        $state['FIDO2PasswordlessAuthMode'] = false;
34
    }
35
36
    public static function prepareStatePasswordlessAuth(StateData $stateData, array &$state): void
37
    {
38
        $state['webauthn:store'] = $stateData->store;
39
        $state['FIDO2Scope'] = $stateData->scope;
40
        $state['FIDO2DerivedScope'] = $stateData->derivedScope;
41
        $state['FIDO2AttributeStoringUsername'] = $stateData->usernameAttrib;
42
        $state['FIDO2SignupChallenge'] = hash('sha512', random_bytes(64));
43
        $state['FIDO2PasswordlessAuthMode'] = true;
44
        $state['FIDO2AuthSuccessful'] = false;     
45
        
46
        $state['FIDO2WantsRegister'] = false;
47
    }
48
}
49