-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbankidSign.php
More file actions
61 lines (51 loc) · 1.83 KB
/
bankidSign.php
File metadata and controls
61 lines (51 loc) · 1.83 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
use Qvickly\Api\Auth\AuthAPI;
require __DIR__ . '/../../vendor/autoload.php';
use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__ . '/../..');
$dotenv->load();
$authAPI = new AuthAPI();
$token = $authAPI->login($_ENV['USERNAME'], $_ENV['PASSWORD']);
$signature = '';
$step1 = $authAPI->bankidSign($token, "test", "sv", "Detta ar ett test");
if(is_array($step1) && array_key_exists('error', $step1)) {
var_dump($step1);
exit;
}
var_dump($step1);
for ($i = 0; $i < 29; $i++) {
echo "Loop $i\n";
// Find hash code
$signLink = $step1['signList'][$i];
// Create QR Code from auth code
// ... create the QR Code here
system("qrencode -o /tmp/test.png '$signLink'"); // Replace this with your QR Code generator
// Show the QR Code to the user
// ... show the QR Code here
system("open '/tmp/test.png'"); // Replace this with your QR Code viewer
// Wait for the user to scan the QR Code
sleep(1);
// Check if the user has scanned the QR Code
$step2 = $authAPI->bankidSignCollect($token, $step1['orderRef']);
var_dump($step2);
if(is_array($step2) && array_key_exists('status', $step2)) {
if($step2['status'] === 'complete') {
echo "BankID sign complete\n";
$signature = $step2['completionData']['signature'];
break;
} elseif ($step2['status'] === 'failed') {
throw new Exception('Failed to collect bankid');
} elseif ($step2['status'] === 'pending') {
echo "Waiting for user to auth with BankID\n";
} else {
throw new Exception('Failed to collect bankid');
}
} else {
throw new Exception('Failed to collect bankid');
}
}
if($signature === '') {
throw new Exception('Failed to sign with bankid');
}
echo "Signature: $signature\n";