-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmobileBankIdSample.php
90 lines (77 loc) · 2.8 KB
/
mobileBankIdSample.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
session_start();
require_once '../vendor/autoload.php';
if (!isset($_GET['authType']))
{
echo '<strong>Select Mobile BankID Method</strong><br><a href="?authType=0">QR Code</a> - <a href="?authType=1">Same Device</a>';
exit;
}
$bankApp = 'swedbank'; // Select bank app
$auth = null;
$sameDevice = (bool)$_GET['authType'];
try
{
// Step 1 - Start the authentication process
if (!isset($_SESSION['swedbankjson_auth']))
{
$appData = new SwedbankJson\AppData($bankApp, __DIR__.'/AppData.json');
$auth = new SwedbankJson\Auth\MobileBankID($appData);
$auth->sameDevice($sameDevice);
$auth->initAuth();
if ($sameDevice)
{
// Automatic redirect back to script from BankID app, replace "null" with URL to this script. Eg. "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"
$redirectURL = urlencode('null');
$bankIdAppUrl = sprintf('https://app.bankid.com/?autostarttoken=%s&redirect=%s', $auth->getAutoStartToken(), $redirectURL);
echo '<strong>Instructions: Sign in with Mobile BankID on same device</strong>';
printf('
<ol>
<li><a href="%s">Use this link to authenticate in BankID app</a></li>
<li>Go back to this page and reload it</li>
</ol>',
$bankIdAppUrl
);
}
else
{
// Need to reload page
echo '<meta http-equiv="refresh" content="0">';
}
exit;
}
// Step 2 - Verify authentication
$auth = unserialize($_SESSION['swedbankjson_auth']);
if (!$auth->verify())
{
if ($sameDevice)
{
echo '<p>Waiting for verification. This page will update automatically.</p>';
}
else
{
// Reload page once per 2 seconds.
echo '<meta http-equiv="refresh" content="2">';
echo '<strong>Instructions</strong>
<ol>
<li>Open the BankID app</li>
<li>Press "Scan QR code" and scan the QR code below.</li>
<li>Done, this page will update automatically.</li>
</ol>';
printf(
'<img src="data:image/png;base64,%s" style="max-width:100%%">',
base64_encode($auth->getChallengeImage())
);
}
exit;
}
// Step 3 - You are in!
$bankConn = new SwedbankJson\SwedbankJson($auth);
} catch (Exception $e)
{
exit($e->getMessage());
}
// Example of account details call. See documentation for details.
echo '<h1>Account details</h1><pre>';
print_r($bankConn->accountDetails());
// Sign out. If you want to keep the session to next page load, remove this line.
$bankConn->terminate();