Skip to content

Commit 6447d43

Browse files
authored
Merge pull request #149 from kaidohallik/improve-documentation
Improve documentation
2 parents 35c6655 + 97bd66a commit 6447d43

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

MIGRATION_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ It is recommended to start using device-link authentication flows from Smart-ID
2828
3. Replace showing verification code with showing device link or QR-code. Recommended to use device link for same device and QR-code for cross-device authentication.
2929
- [Create device link or QR-code](README.md#generating-qr-code-or-device-link) from values in session response and display it to the user. QR-code should be recreated after every second.
3030
4. Querying session status can be done in parallel while displaying device content. Check out [session status poller](README.md#example-of-using-session-status-poller-to-query-final-sessions-status). `ee.sk.smartid.SmartIdClient` provides method `getSessionsStatusPoller()` to get version specific session status poller.
31-
5. When session status state is `COMPLETE` polling will be stopped and [response should be checked](README.md#example-of-validating-the-authentication-sessions-response) with `AuthenticationResponseValidator`. It will validate required fields, certificate and signature value in sessions status, and it will also handler errors.
31+
5. When session status state is `COMPLETE` polling will be stopped and [response should be checked](README.md#example-of-validating-the-authentication-sessions-response) with `DeviceLinkAuthenticationResponseValidator` or `NotificationAuthenticationResponseValidator` (depending on the flow). They will validate required fields, certificate and signature value in sessions status, and they will also handle errors.
3232
6. If everything is ok `AuthenticationIdentity` will be returned. AuthenticationIdentity is same as used for V2.
3333

3434
## Migrating signing

README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,16 @@ Anonymous authentication is a new feature in Smart-ID API v3.1. It allows to aut
230230
RP can learn the user's identity only after the user has authenticated themselves.
231231

232232
```java
233-
// For security reasons a new hash value must be created for each new authentication request
234-
String rpChallenge = RpChallengeGenerator.generate();
233+
// For security reasons a new RP challenge must be created for each new authentication request
234+
RpChallenge rpChallenge = RpChallengeGenerator.generate();
235235
// Store generated rpChallenge only on backend side. Do not expose it to the client side.
236236
// Used for validating authentication sessions status OK response
237237

238238
// Set up builder
239239
DeviceLinkAuthenticationSessionRequestBuilder builder = smartIdClient
240240
.createDeviceLinkAuthentication()
241241
// to use anonymous authentication, do not set semantics identifier or document number
242-
.withRpChallenge(rpChallenge)
242+
.withRpChallenge(rpChallenge.toBase64EncodedValue())
243243
.withInteractions(Collections.singletonList(
244244
DeviceLinkInteraction.displayTextAndPin("Logging into <app-name>") // Display text should be concise and specific.
245245
));
@@ -794,15 +794,16 @@ if ("RUNNING".equalsIgnoreCase(sessionStatus.getState())) {
794794
### Validating session status response
795795

796796
It's important to validate the session status response to ensure that the returned signature or authentication result is valid.
797-
For validating authentication session status response, use the `AuthenticationResponseValidator`.
797+
For validating authentication session status response, use `DeviceLinkAuthenticationResponseValidator` for device link flows
798+
and `NotificationAuthenticationResponseValidator` for notification-based flows.
798799
For validating signature session status response, use the `SignatureResponseValidator`.
799800
NB! Integrators must validate signature value against expected signature value.
800801

801802
#### Set up CertificateValidator
802803

803804
CertificateValidator will check if the certificate is not expired and is trusted
804805
by constructing certificate chain with trust anchors and intermediate CA certificates provided in the TrustedCACertStore.
805-
Will be used by AuthenticationResponseValidator and SignatureResponseValidator.
806+
Will be used by DeviceLinkAuthenticationResponseValidator, NotificationAuthenticationResponseValidator, CertificateChoiceResponseValidator and SignatureResponseValidator.
806807

807808
```java
808809
// Set up TrustedCACertStore
@@ -837,11 +838,12 @@ CertificateValidator certificateValidator = new CertificateValidatorImpl(trusted
837838
DeviceLinkAuthenticationResponseValidator depends on CertificateValidator. Checkout [setting up CertificateValidator](#set-up-certificatevalidator)
838839

839840
```java
840-
// Set up AuthenticationResponseValidator with the CertificateValidator
841-
DeviceLinkAuthenticationResponseValidator deviceLinkAuthenticationResponseValidator = new AuthenticationResponseValidator(certificateValidator);
841+
// Set up DeviceLinkAuthenticationResponseValidator with the CertificateValidator
842+
DeviceLinkAuthenticationResponseValidator deviceLinkAuthenticationResponseValidator =
843+
DeviceLinkAuthenticationResponseValidator.defaultSetupWithCertificateValidator(certificateValidator);
842844

843845
// Create authentication request builder
844-
DeviceLinkAuthenticationSessionRequestBuilder authenticationRequestBuilder = smartIdClient.createDeviceLinkAuthentication()...;
846+
DeviceLinkAuthenticationSessionRequestBuilder authenticationRequestBuilder = smartIdClient.createDeviceLinkAuthentication()...;
845847
// Initialize session
846848
DeviceLinkSessionResponse sessionResponse = authenticationRequestBuilder.initAuthenticationSession();
847849
// Get request used for starting the authentication session and use it later to validate sessions status response
@@ -852,9 +854,13 @@ SessionStatusPoller poller = smartIdClient.getSessionStatusPoller();
852854
SessionStatus sessionStatus = poller.fetchFinalSessionStatus(sessionResponse.sessionID());
853855

854856
// validate sessions state is completed
855-
if("COMPLETE".equals(sessionStatus.getState())){
857+
if ("COMPLETE".equals(sessionStatus.getState())) {
858+
// For same-device flows (Web2App/App2App), get userChallengeVerifier from callback URL
859+
String userChallengeVerifier = "<userChallengeVerifier-from-callback-url>";
860+
856861
// validate the session status response with authentication session request and return authentication identity
857-
AuthenticationIdentity authenticationIdentity = deviceLinkAuthenticationResponseValidator.validate(sessionStatus, authenticationSessionRequest, "smart-id-demo");
862+
AuthenticationIdentity authenticationIdentity =
863+
deviceLinkAuthenticationResponseValidator.validate(sessionStatus, authenticationSessionRequest, userChallengeVerifier, "smart-id-demo");
858864
}
859865
```
860866

@@ -863,11 +869,12 @@ if("COMPLETE".equals(sessionStatus.getState())){
863869
NotificationAuthenticationResponseValidator depends on CertificateValidator. Checkout [setting up CertificateValidator](#set-up-certificatevalidator)
864870

865871
```java
866-
// Set up AuthenticationResponseValidator with the CertificateValidator
867-
NotificationAuthenticationResponseValidator notificationAuthenticationResponseValidator = new AuthenticationResponseValidator(certificateValidator);
872+
// Set up NotificationAuthenticationResponseValidator with the CertificateValidator
873+
NotificationAuthenticationResponseValidator notificationAuthenticationResponseValidator =
874+
NotificationAuthenticationResponseValidator.defaultSetupWithCertificateValidator(certificateValidator);
868875

869876
// Create authentication request builder
870-
NotificationAuthenticationSessionRequestBuilder authenticationRequestBuilder = smartIdClient.createDeviceLinkAuthentication()...;
877+
NotificationAuthenticationSessionRequestBuilder authenticationRequestBuilder = smartIdClient.createNotificationAuthentication()...;
871878
// Initialize session
872879
NotificationAuthenticationSessionResponse sessionResponse = authenticationRequestBuilder.initAuthenticationSession();
873880
// Get request used for starting the authentication session and use it later to validate sessions status response
@@ -878,9 +885,10 @@ SessionStatusPoller poller = smartIdClient.getSessionStatusPoller();
878885
SessionStatus sessionStatus = poller.fetchFinalSessionStatus(sessionResponse.sessionID());
879886

880887
// validate sessions state is completed
881-
if("COMPLETE".equals(sessionStatus.getState())){
888+
if ("COMPLETE".equals(sessionStatus.getState())) {
882889
// validate the session status response with authentication session request and return authentication identity
883-
AuthenticationIdentity authenticationIdentity = notificationAuthenticationResponseValidator.validate(sessionStatus, authenticationSessionRequest, "smart-id-demo");
890+
AuthenticationIdentity authenticationIdentity =
891+
notificationAuthenticationResponseValidator.validate(sessionStatus, authenticationSessionRequest, "smart-id-demo");
884892
}
885893
```
886894

0 commit comments

Comments
 (0)