Completed
Push — master ( efc296...9cc4ef )
by Stefan
18s queued 13s
created

StaticProcessHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareState() 0 13 1
A saveStateAndRedirect() 0 5 1
1
<?php
2
3
namespace SimpleSAML\Module\webauthn\WebAuthn;
4
5
use SimpleSAML\Auth;
6
use SimpleSAML\Module;
7
use SimpleSAML\Utils;
8
9
class StaticProcessHelper
10
{
11
    public static function saveStateAndRedirect(&$state)
12
    {
13
        $id = Auth\State::saveState($state, 'webauthn:request');
14
        $url = Module::getModuleURL('webauthn/webauthn.php');
15
        Utils\HTTP::redirectTrustedURL($url, ['StateId' => $id]);
16
    }
17
18
    public static function prepareState($stateData, &$state)
19
    {
20
        $state['requestTokenModel'] = $stateData->requestTokenModel;
21
        $state['webauthn:store'] = $stateData->store;
22
        $state['FIDO2Tokens'] = $stateData->store->getTokenData($state['Attributes'][$stateData->usernameAttrib][0]);
23
        $state['FIDO2Scope'] = $stateData->scope;
24
        $state['FIDO2DerivedScope'] = $stateData->derivedScope;
25
        $state['FIDO2Username'] = $state['Attributes'][$stateData->usernameAttrib][0];
26
        $state['FIDO2Displayname'] = $state['Attributes'][$stateData->displaynameAttrib][0];
27
        $state['FIDO2SignupChallenge'] = hash('sha512', random_bytes(64));
28
        $state['FIDO2WantsRegister'] = false;
29
        $state['FIDO2AuthSuccessful'] = false;
30
        $state['UseInflowRegistration'] = $stateData->useInflowRegistration;
31
    }
32
}
33