bankid
Npm module to simplify integration with the Swedish Bank ID service for user authentication and signing processes.
Installation
npm install --save bankid
Usage
const BankId = require('bankid');
const bankid = new BankId();
const pno = <SOME_PERSONAL_NUMBER>;
bankid.authenticateAndCollect(pno)
.then(res => console.log(res.userInfo))
.catch(err => console.error(err));
As outlined in the relying party guidelines there's three main methods
authenticate(personalNumber)
sign(personalNumber, message)
collect(orderRef)
In addition bankid provides convenience methods to combine auth / sign with periodic collection of the status until the process either failed or succeeded (as shown in the example code above)
authenticateAndCollect(personalNumber)
signAndCollect(personalNumber, message)
All methods return promises, but you can also pass in an ordinary callback as the last argument.
Full example not using the convenience methods:
const BankId = require('bankid');
const bankid = new BankId();
const pno = <SOME_PERSONAL_NUMBER>;
const message = 'some message displayed to the user to sign';
bankid.sign(pno, message).then(res => {
const timer = setInterval(() => {
const done = () => clearInterval(timer);
bankid.collect(res.orderRef)
.then(res => {
console.log(res.progressStatus);
if (res.progressStatus === 'COMPLETE') {
console.log(res.userInfo);
done();
}
})
.catch(err => {
console.log(err.toString());
done();
})
}, 1000);
});
Configuration
By default bankid is instantiated with the following configuration pointing to the Bank ID Test Environment
{
refreshInterval: 1000,
production: false,
pfx: <PATH_TO_TEST_ENV_PFX>,
passphrase: <TEST_ENV_PASSPHRASE>,
ca: <CERTIFICATE>,
}
For production you'll want to pass in your own pfx and passphrase instead:
const bankid = new BankId({
production: true,
pfx: <PATH_TO_YOUR_PFX>,
passphrase: <YOUR_PASSPHRASE>,
});