forked from bigbank-as/digidoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authentication.php
39 lines (29 loc) · 1.41 KB
/
authentication.php
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
28
29
30
31
32
33
34
35
36
37
38
39
<?php
use Bigbank\DigiDoc\DigiDoc;
use Bigbank\DigiDoc\Services\MobileId\AuthenticatorInterface;
use Bigbank\DigiDoc\Soap\InteractionStatus;
include './vendor/autoload.php';
// Instantiate the main class - use DigiDoc testing API
$digiDocService = new DigiDoc(DigiDoc::URL_TEST);
// Ask for the authentication service
/** @var AuthenticatorInterface $authenticator */
$authenticator = $digiDocService->getService(AuthenticatorInterface::class);
printf("Trying to authenticate with mobile ID (using testing API)...\n");
// Make an authentication request to SK using testing inputs (see http://www.id.ee/?id=36373)
$response = $authenticator->authenticate('14212128025', '+37200007', 'Testimine', 'My Application');
print_r($response);
// The testing service simulates a delay while the imaginary "user" confirms authentication with his/her phone
printf(
"Authentication code (%d) sent to %s, waiting for confirmation (< 4min)...\n\n",
$response['ChallengeID'],
$response['UserCN']
);
// Wait for the user to respond to the authentication.
// This will either end with a success, failure or a timeout (~4min).
// If a blocking call is not desired, use the `askStatus` function to poll.
echo $authenticator->waitForAuthentication(function ($status) {
if ($status === InteractionStatus::USER_AUTHENTICATED) {
return "\nAuthentication OK\n";
}
return sprintf("\nFailure. Status was %s.\n", $status);
});