aboutsummaryrefslogtreecommitdiff
path: root/Psso/Challenge/Totp.php
blob: 4fd47f4e5bd3b13ebe4fa23d6e5e6286fa33a59b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
namespace Psso\Challenge;
use Psso\{Challenge, AuthProvider, ChallengeResult, Context, Input, AuthInterface};

class Totp extends Challenge {
    public static function create(Context $context): static {
        self::requireKnownUser($context);
        return new self($context);
    }

    public function getInputs(): array {
        return [new Input('otp', Input::NUMERIC, 'challenge.input.otp')];
    }

    public function validate(
        AuthProvider $provider, array $inputData
    ): ChallengeResult {
        self::requireInterface($provider, AuthInterface\Totp::class);
        $success = $provider->validateTotp(
            $this->context->user, $inputData['otp']
        );
        return new ChallengeResult(
            self::class, $success, null,
            $success ? null : 'challenge.message.wrong-otp'
        );
    }
}