Skip to content

Commit f7e0970

Browse files
committed
SDK-2771: [MB] Introduce support for auth tokens
1 parent 067494d commit f7e0970

41 files changed

Lines changed: 1189 additions & 1521 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

yoti-sdk-api/src/main/java/com/yoti/api/client/DigitalIdentityClient.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,36 @@ public class DigitalIdentityClient {
2323
Security.addProvider(new BouncyCastleProvider());
2424
}
2525

26-
private final String sdkId;
2726
private final KeyPair keyPair;
2827
private final DigitalIdentityService identityService;
2928

30-
DigitalIdentityClient(String sdkId, KeyPairSource keyPair, DigitalIdentityService identityService) {
31-
Validation.notNullOrEmpty(sdkId, "SDK ID");
32-
Validation.notNull(keyPair, "Application Key Pair");
33-
34-
this.sdkId = sdkId;
35-
this.keyPair = loadKeyPair(keyPair);
29+
private DigitalIdentityClient(KeyPair keyPair, DigitalIdentityService identityService) {
30+
this.keyPair = keyPair;
3631
this.identityService = identityService;
3732
}
3833

3934
public ShareSession createShareSession(ShareSessionRequest request) throws DigitalIdentityException {
40-
return identityService.createShareSession(sdkId, keyPair, request);
35+
return identityService.createShareSession(request);
4136
}
4237

4338
public ShareSession fetchShareSession(String sessionId) throws DigitalIdentityException {
44-
return identityService.fetchShareSession(sdkId, keyPair, sessionId);
39+
return identityService.fetchShareSession(sessionId);
4540
}
4641

4742
public ShareSessionQrCode createShareQrCode(String sessionId) throws DigitalIdentityException {
48-
return identityService.createShareQrCode(sdkId, keyPair, sessionId);
43+
return identityService.createShareQrCode(sessionId);
4944
}
5045

5146
public ShareSessionQrCode fetchShareQrCode(String qrCodeId) throws DigitalIdentityException {
52-
return identityService.fetchShareQrCode(sdkId, keyPair, qrCodeId);
47+
return identityService.fetchShareQrCode(qrCodeId);
5348
}
5449

5550
public Receipt fetchShareReceipt(String receiptId) throws DigitalIdentityException {
56-
return identityService.fetchShareReceipt(sdkId, keyPair, receiptId);
51+
return identityService.fetchShareReceipt(keyPair, receiptId);
5752
}
5853

5954
public MatchResult fetchMatch(MatchRequest request) throws DigitalIdentityException {
60-
return identityService.fetchMatch(sdkId, keyPair, request);
61-
}
62-
63-
private KeyPair loadKeyPair(KeyPairSource keyPairSource) throws InitialisationException {
64-
try {
65-
return keyPairSource.getFromStream(new KeyStreamVisitor());
66-
} catch (IOException ex) {
67-
throw new InitialisationException("Cannot load Key Pair", ex);
68-
}
55+
return identityService.fetchMatch(request);
6956
}
7057

7158
public static Builder builder() {
@@ -94,7 +81,19 @@ public Builder withKeyPairSource(KeyPairSource keyPairSource) {
9481
}
9582

9683
public DigitalIdentityClient build() {
97-
return new DigitalIdentityClient(sdkId, keyPairSource, DigitalIdentityService.newInstance());
84+
Validation.notNullOrEmpty(sdkId, "SDK ID");
85+
Validation.notNull(keyPairSource, "Application Key Pair");
86+
87+
KeyPair keyPair = loadKeyPair(keyPairSource);
88+
return new DigitalIdentityClient(keyPair, DigitalIdentityService.newInstance(keyPair, sdkId));
89+
}
90+
91+
private KeyPair loadKeyPair(KeyPairSource keyPairSource) throws InitialisationException {
92+
try {
93+
return keyPairSource.getFromStream(new KeyStreamVisitor());
94+
} catch (IOException ex) {
95+
throw new InitialisationException("Cannot load Key Pair", ex);
96+
}
9897
}
9998

10099
}

yoti-sdk-api/src/main/java/com/yoti/api/client/YotiClient.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ public class YotiClient {
4646
private final DynamicSharingService dynamicSharingService;
4747

4848
YotiClient(String applicationId,
49-
KeyPairSource kpSource,
49+
KeyPair keyPair,
5050
ReceiptFetcher receiptFetcher,
51-
ActivityDetailsFactory activityDetailsFactory,
5251
RemoteAmlService remoteAmlService,
52+
ActivityDetailsFactory activityDetailsFactory,
5353
DynamicSharingService dynamicSharingService) throws InitialisationException {
5454
this.appId = notNull(applicationId, "Application id");
55-
this.keyPair = loadKeyPair(notNull(kpSource, "Key pair source"));
55+
this.keyPair = keyPair;
5656
this.receiptFetcher = notNull(receiptFetcher, "receiptFetcher");
5757
this.remoteAmlService = notNull(remoteAmlService, "amlService");
5858
this.activityDetailsFactory = notNull(activityDetailsFactory, "activityDetailsFactory");
@@ -80,7 +80,7 @@ public static YotiClient.Builder builder() {
8080
* @throws ProfileException aggregate exception signalling issues during the call
8181
*/
8282
public ActivityDetails getActivityDetails(String encryptedYotiToken) throws ProfileException {
83-
Receipt receipt = receiptFetcher.fetch(encryptedYotiToken, keyPair, appId);
83+
Receipt receipt = receiptFetcher.fetch(encryptedYotiToken, keyPair);
8484
return activityDetailsFactory.create(receipt, keyPair.getPrivate());
8585
}
8686

@@ -96,7 +96,7 @@ public ActivityDetails getActivityDetails(String encryptedYotiToken) throws Prof
9696
*/
9797
public AmlResult performAmlCheck(AmlProfile amlProfile) throws AmlException {
9898
LOG.debug("Performing aml check...");
99-
return remoteAmlService.performCheck(keyPair, appId, amlProfile);
99+
return remoteAmlService.performCheck(amlProfile);
100100
}
101101

102102
/**
@@ -113,15 +113,7 @@ public AmlResult performAmlCheck(AmlProfile amlProfile) throws AmlException {
113113
*/
114114
public ShareUrlResult createShareUrl(DynamicScenario dynamicScenario) throws DynamicShareException {
115115
LOG.debug("Request a share url for a dynamicScenario...");
116-
return dynamicSharingService.createShareUrl(appId, keyPair, dynamicScenario);
117-
}
118-
119-
private KeyPair loadKeyPair(KeyPairSource kpSource) throws InitialisationException {
120-
try {
121-
return kpSource.getFromStream(new KeyStreamVisitor());
122-
} catch (IOException e) {
123-
throw new InitialisationException("Cannot load key pair", e);
124-
}
116+
return dynamicSharingService.createShareUrl(appId, dynamicScenario);
125117
}
126118

127119
public static class Builder {
@@ -144,14 +136,15 @@ public Builder withKeyPair(KeyPairSource keyPairSource) {
144136

145137
public YotiClient build() {
146138
checkBuilderState();
139+
KeyPair keyPair = loadKeyPair(notNull(keyPairSource, "Key pair source"));
147140

148141
return new YotiClient(
149142
sdkId,
150-
keyPairSource,
151-
ReceiptFetcher.newInstance(),
143+
keyPair,
144+
ReceiptFetcher.newInstance(keyPair, sdkId),
145+
RemoteAmlService.newInstance(keyPair, sdkId),
152146
ActivityDetailsFactory.newInstance(),
153-
RemoteAmlService.newInstance(),
154-
DynamicSharingService.newInstance()
147+
DynamicSharingService.newInstance(keyPair)
155148
);
156149
}
157150

@@ -164,6 +157,14 @@ private void checkBuilderState() {
164157
}
165158
}
166159

160+
private KeyPair loadKeyPair(KeyPairSource kpSource) throws InitialisationException {
161+
try {
162+
return kpSource.getFromStream(new KeyStreamVisitor());
163+
} catch (IOException e) {
164+
throw new InitialisationException("Cannot load key pair", e);
165+
}
166+
}
167+
167168
}
168169

169170
}

0 commit comments

Comments
 (0)