Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Bank ID version #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The CA certificate for the production environment can be found in the BankID doc
Here is an example of using `.cer` and `.key`, in this example named `prod.cer` and `prod.key`:

```php
$bankId = new BankID('prod', '/path/to/prod.cer', '/path/to/prod_cacert.cer', '/path/to/prod.key', 'key-passphrase');
$bankId = new BankID('prod', '/path/to/prod.cer', '/path/to/prod_cacert.cer', '/path/to/prod.key', 'key-passphrase', '5.1');
```

To use a single file, convert the `p12/pfx`-file to a PEM-encoded file:
Expand All @@ -39,3 +39,20 @@ $bankId = new BankID('prod', '/path/to/prod.pem', '/path/to/prod_cacert.cer', nu
## Security

If you discover any security related issues, please contact [email protected] instead of using the issue tracker.

## Bank ID version

By default when you create a new instace of a BankID you can pass several parameters. One the the parameters is to decide the version to use of the Bank ID API. Default value (at the time of this writing is v5.1).

## Bank ID versions
Ver. Release End of life
==============================
v4 2014-01 2019-03
v4* 2017-03 2020-02 *v4 was released again with updated CA, a new endpoint and required TLS1.1 or TLS1.2
v5 2018-02 2022-04
v5.1 2020-04 - *Support for animated QR, autoStartTokenRquired deprecated. tokenStartRequired introduced.

To read more about the different versions,
https://www.bankid.com/assets/bankid/rp/bankid-relying-party-guidelines-v3.5.pdf
or
https://www.bankid.com/utvecklare/rp-info
2 changes: 1 addition & 1 deletion certs/test.pem
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ B5wLKsEqKYuAiMnF105PkpMzvXquTKlaq5FkQC9beQKBgQC4zeRihfM5V49YRzuo
bOj+5I1FVRgPHTqGMlNkzrzVk561kBSY6JfvPx4w5rylFTrBRM7IwwYNcnll0DVc
6cavNLs7O42rDEro5vAEpWiI6oMSGGtUsgzHTUENDxD36b/ZAGPshV8+J9cAdbgJ
BRCv1g4xLPJrOU6D66R4VUSrGg==
-----END PRIVATE KEY-----
-----END PRIVATE KEY-----
2 changes: 1 addition & 1 deletion certs/test_cacert.cer
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ hq+Nh3JrF0HYQuMgExQ6VX8T56saOEtmlp6LSQi4HvKatCNfWUJGoYeT5SrcJ6sn
By7XLMhQUCOXcBwKbNvX6aP79VA3yeJHZO7XParX7V9BB+jtf4tz/usmAT/+qXtH
CCv9Xf4lv8jgdOnFfXbXuT8I4gz8uq8ElBlpbJntO6p/NY5a08E6C7FWVR+WJ5vZ
OP2HsA==
-----END CERTIFICATE-----
-----END CERTIFICATE-----
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"type": "library",
"license": "MIT",
"require": {
"php": "^7.1",
"guzzlehttp/guzzle": "^6.3 | ^7.0.1",
"ext-json": "*"
"php": "^7.2.5|^8.0",
"ext-json": "*",
"guzzlehttp/promise": "^1.4",
"guzzlehttp/psr7": "^1.7",
"psr/http-client": "^1.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand All @@ -15,4 +17,4 @@
"LJSystem\\BankID\\": "src"
}
}
}
}
9 changes: 5 additions & 4 deletions src/BankID.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class BankID
self::ENVIRONMENT_TEST => 'appapi2.test.bankid.com',
];

const BANKIDAPI_VERSION = 'v5.1';

private $httpClient;

/**
Expand All @@ -26,8 +28,9 @@ class BankID
* @param string $caCertificate
* @param string $key
* @param string $passphrase
* @param string $api_version
*/
public function __construct($environment = self::ENVIRONMENT_TEST, $certificate = null, $caCertificate = null, $key = null, $passphrase = null)
public function __construct($environment = self::ENVIRONMENT_TEST, $certificate = null, $caCertificate = null, $key = null, $passphrase = null, $api_version = self::BANKIDAPI_VERSION.'/')
{
if (is_null($certificate)) {
$certificate = __DIR__.'/../certs/test.pem';
Expand All @@ -42,7 +45,7 @@ public function __construct($environment = self::ENVIRONMENT_TEST, $certificate
}

$httpOptions = [
'base_uri' => 'https://'.self::HOSTS[$environment].'/rp/v5/',
'base_uri' => 'https://'.self::HOSTS[$environment].'/rp/'.self::BANKIDAPI_VERSION,
'cert' => $certificate,
'verify' => $caCertificate,
'headers' => [
Expand Down Expand Up @@ -75,8 +78,6 @@ public function authenticate($personalNumber, $ip)
}

try {


$httpResponse = $this->httpClient->post('auth', [
RequestOptions::JSON => $payload,
]);
Expand Down