
EBSI SIOP Auth Library
EBSI Auth library for natural persons and legal entities.
Table of Contents
Installation
npm install @cef-ebsi/siop-auth
or if you use yarn
yarn add @cef-ebsi/siop-auth
Authentication Flow
The current EBSI SIOP Auth implementation follows RFC - DID-OIDC for NP/LE Authentication to EBSI & Relying Party in EBSI V2, which uses two JSON Web Tokens (JWT) signed by both two parties DID keys in a double challenge-response authentication.
Current version supports only ES256K algorithm (the EC secp256k1) and did:ebsi DID method.
Note: This version implemented does have support for custom claims. (i.e. using VerifiableID).
The DID Auth flow has the following steps involving a natural person or legal entity (NP/LE) and a relying party (RP):
- createAuthenticationRequest (RP)
- A NP, i.e. user, with a valid ebsi:did already generated, accesses on an Institution web site, i.e. the RP, and clicks to a
Login button
- RP creates an EbsiDidAuth URI Request calling
EbsiDidAuth.createAuthenticationRequest with this payload:
const didAuthRequestCall: DidAuthRequestCall = {
redirectUri: "https://app.ebsi.xyz/demo/spanish-university",
hexPrivateKey: , "0x33fbb77871a3...3b44a67"
issuer: "did:ebsi:BdFneNpniW3DE639yY6sEga9GhwdZ3jSdfJ1EyURMPx5"
kid: "https://api.test.intebsi.xyz/did-registry/v2/identifiers/did:ebsi:BdFneNpniW3DE639yY6sEga9GhwdZ3jSdfJ1EyURMPx5#keys-1"
};
const { uri } = await EbsiDidAuth.createAuthenticationRequest(didAuthRequestCall);
- RP receives an Open ID URI and nonce as a result:
openid://?response_type=id_token&client_id=http%3A%2F%2Fapp.ebsi.xyz%2Fdemo%2Fspanish-university&scope=openid%20did_authn&state=7b24331f73fd65a37a0ea915&nonce=_fRDy4lli3gTctXx9evaLJowCZkb2xQcrqnlcNrruKk&request=eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QiLCJraWQiOiJodHRwczovL2FwaS50ZXN0LmludGVic2kueHl6L2RpZC1yZWdpc3RyeS92Mi9pZGVudGlmaWVycy9kaWQ6ZWJzaTpCZEZuZU5wbmlXM0RFNjM5eVk2c0VnYTlHaHdkWjNqU2RmSjFFeVVSTVB4NSNrZXlzLTEifQ.eyJpYXQiOjE2MTg5MDQ0MDEsImV4cCI6MTYxODkwNDcwMSwiaXNzIjoiZGlkOmVic2k6QmRGbmVOcG5pVzNERTYzOXlZNnNFZ2E5R2h3ZFozalNkZkoxRXlVUk1QeDUiLCJzY29wZSI6Im9wZW5pZCBkaWRfYXV0aG4iLCJyZXNwb25zZV90eXBlIjoiaWRfdG9rZW4iLCJjbGllbnRfaWQiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvZGVtby9zcGFuaXNoLXVuaXZlcnNpdHkiLCJzdGF0ZSI6IjdiMjQzMzFmNzNmZDY1YTM3YTBlYTkxNSIsIm5vbmNlIjoiX2ZSRHk0bGxpM2dUY3RYeDlldmFMSm93Q1prYjJ4UWNycW5sY05ycnVLayJ9.h2nlz3AeflzTkh_E2oIvjR_h_0OdB1DDW1maB9Zt3bcfzjYe0Yynl8BJbMB206GySJeZ4d53TuBm8kwSJ2HurA
Note: RP needs to store nonce, found inside the Request token to be used on the response validation process.
- RP redirects to the front-end passing DID-Auth URI.
- verifyAuthenticationRequest (NP/LE)
- User parses the received EBSI DID Auth Request URI to obtain
request URL parameter to be used to verify the token and create the Response token:
const params = new URLSearchParams(didAuthUri);
const didAuthRequestJwt = params.get("request");
const didResolver = "https://api.intebsi.xyz/did/v1/identifiers";
const requestPayload: DidAuthRequestPayload = await EbsiDidAuth.verifyAuthenticationRequest(
didAuthRequestJwt as string,
didResolver as string
);
console.log(requestPayload);
- createAuthenticationResponse (NP/LE)
- After a successful validation, user creates an EBSI SIOP Auth Response JWT token calling
EbsiDidAuth.createAuthenticationResponse, reusing the Request nonce and state.
const didAuthResponseCall: DidAuthResponseCall = {
hexPrivatekey: userPrivateKey,
did: "did:ebsi:0x226e2e2223333c2e4c65652e452d412d50611111",
state: requestPayload.state,
nonce: requestPayload.nonce,
redirectUri,
};
const didAuthResponseJwt = await EbsiDidAuth.createAuthenticationResponse(
didAuthResponseCall
);
- User redirects to the RP
redirectUri URI passing the Response token as a parameter:
https://app.ebsi.xyz/demo/spanish-university?response=<Signed JWT Response Object>
- verifyAuthenticationResponse (RP)
- RP verifies the DID Auth Response token calling
EbsiDidAuth.verifyAuthenticationResponse passing the stored nonce:
const response = await EbsiDidAuth.verifyAuthenticationResponse(
idToken,
didResolver,
audience,
requestPayload.nonce
);
console.log(response);
- Response object contains a JSON struct with
signatureValidation set to true and the verified payload:
{
"signatureValidation": true,
"payload": {
"iss": "https://self-issued.me",
"sub": "QS+5mH5GqVxuah94+D9wV97mMKZ6iMzW1op4B4s02Jk=",
"aud": "redirect-uri",
"exp": 1569937756,
"iat": 1569934156,
"nonce": "6a6b57a9d4e1a130b0edbe1ec4ae8823",
"claims": { ...
}
}
}
Usage
Prerequisites
It is assumed that either the user (NP/LE) and the RP have an EBSI-DID and can use their private keys to sign a given payload.
For instance:
const userDid = "did:ebsi:0xcAe6EFa4461262842BB58188579Ef2602c7A44fC";
const enterpriseDid = "did:ebsi:0xDe07DBEe84cCB1F75A09e96b1f995560b7Cdf5aa";
Library Test
To run e2e you need to set these two environment variables either in a .env or passing as a parameter to yarn test:e2e.
You can use the .env.example from the repo and renamed it to .env.
$ yarn test:unit
$ yarn test:e2e
$ yarn test
Licensing
Copyright (c) 2019 European Commission
Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
You may not use this work except in compliance with the Licence.
You may obtain a copy of the Licence at:
Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Licence for the specific language governing permissions and limitations under the Licence.