Skip to content

Commit 7654293

Browse files
committed
SDK-566: Replace userId with rememberMeId
1 parent bff51cc commit 7654293

File tree

8 files changed

+47
-29
lines changed

8 files changed

+47
-29
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ so can use it to determine whether a user is new to you. For example:
185185
ActivityDetails activityDetails;
186186
try {
187187
activityDetails = client.getActivityDetails(token);
188-
Optional<YourAppUserClass> user = yourUserSearchMethod(activityDetails.getUserId());
188+
Optional<YourAppUserClass> user = yourUserSearchMethod(activityDetails.getRememberMeId());
189189
if (user.isPresent()) {
190-
String userId = activityDetails.getUserId();
190+
String rememberMeId = activityDetails.getRememberMeId();
191191
String base64Selfie = activityDetails.getBase64Selfie();
192192
Attribute<Image> selfie = profile.getSelfie();
193193
Image selfieValue = selfie.getValue();
@@ -210,7 +210,7 @@ try {
210210
}
211211
```
212212

213-
Where `yourUserSearchMethod` is a method in your app that finds the user for the given userId.
213+
Where `yourUserSearchMethod` is a method in your app that finds the user for the given rememberMeId.
214214
Regardless of whether the user is new to your app, Yoti will always provide the profile. So you don't necessarily need to store it.
215215

216216
### Attributes

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,22 @@ public interface ActivityDetails {
2323
ApplicationProfile getApplicationProfile();
2424

2525
/**
26-
* Return the user ID, which is a unique, stable identifier for a user in the context of an application/user
26+
* Deprecated. Please use getRememberMeId() instead.
27+
*
28+
* @return user ID.
29+
*/
30+
@Deprecated
31+
String getUserId();
32+
33+
/**
34+
* Return the remember-me ID, which is a unique, stable identifier for a user in the context of an application/user
2735
* interaction. You can be use it to identify returning users. Note that it is different for the same user in
2836
* different applications.
2937
*
3038
* @return user ID.
3139
*/
32-
String getUserId();
40+
String getRememberMeId();
41+
3342

3443
/**
3544
* Time and date of the activity.

yoti-sdk-impl/src/main/java/com/yoti/api/client/spi/remote/SimpleActivityDetails.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
final class SimpleActivityDetails implements ActivityDetails {
1313

14-
private final String userId;
14+
private final String rememberMeId;
1515
private final ApplicationProfile applicationProfile;
1616
private final HumanProfile userProfile;
1717
private final Date timestamp;
1818
private final String receiptId;
1919
private final String base64Selfie;
2020

21-
public SimpleActivityDetails(String userId, Profile userProfile, Profile applicationProfile, Date timestamp, byte[] receiptId) {
22-
this.userId = notNull(userId, "User id");
21+
public SimpleActivityDetails(String rememberMeId, Profile userProfile, Profile applicationProfile, Date timestamp, byte[] receiptId) {
22+
this.rememberMeId = notNull(rememberMeId, "Remember Me id");
2323
this.userProfile = HumanProfileAdapter.wrap(notNull(userProfile, "User profile"));
2424
this.applicationProfile = ApplicationProfileAdapter.wrap(notNull(applicationProfile, "Application profile"));
2525
this.timestamp = notNull(timestamp, "Timestamp");
@@ -43,8 +43,14 @@ public ApplicationProfile getApplicationProfile() {
4343
}
4444

4545
@Override
46+
@Deprecated
4647
public String getUserId() {
47-
return userId;
48+
return getRememberMeId();
49+
}
50+
51+
@Override
52+
public String getRememberMeId() {
53+
return rememberMeId;
4854
}
4955

5056
@Override

yoti-sdk-impl/src/test/java/com/yoti/api/client/spi/remote/ActivityDetailsFactoryTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static com.yoti.api.client.spi.remote.util.CryptoUtil.generateSymmetricKey;
66

77
import static org.bouncycastle.util.encoders.Base64.decode;
8+
import static org.bouncycastle.util.encoders.Base64.toBase64String;
89
import static org.hamcrest.core.StringContains.containsString;
910
import static org.junit.Assert.assertEquals;
1011
import static org.junit.Assert.assertSame;
@@ -52,8 +53,8 @@ public class ActivityDetailsFactoryTest {
5253
private static final DateFormat RFC3339_FORMAT = new SimpleDateFormat(RFC3339_PATTERN);
5354
private static final String VALID_TIMESTAMP = RFC3339_FORMAT.format(DATE);
5455

55-
private static final String SOME_USER_ID_STRING = "aBase64EncodedUserId";
56-
private static final byte[] SOME_USER_ID_BYTES = decode(SOME_USER_ID_STRING);
56+
private static final String SOME_REMEMBER_ME_ID_STRING = toBase64String("aBase64EncodedRememberMeId".getBytes());
57+
private static final byte[] SOME_REMEMBER_ME_ID_BYTES = decode(SOME_REMEMBER_ME_ID_STRING);
5758
private static final String ENCODED_RECEIPT_STRING = "base64EncodedReceipt";
5859
private static final byte[] DECODED_RECEIPT_BYTES = decode(ENCODED_RECEIPT_STRING);
5960

@@ -128,7 +129,7 @@ public void shouldGetCorrectProfilesFromProfileReader() throws Exception {
128129
Receipt receipt = new Receipt.Builder()
129130
.withWrappedReceiptKey(validReceiptKey)
130131
.withTimestamp(VALID_TIMESTAMP)
131-
.withRememberMeId(SOME_USER_ID_BYTES)
132+
.withRememberMeId(SOME_REMEMBER_ME_ID_BYTES)
132133
.withProfile(PROFILE_CONTENT)
133134
.withOtherPartyProfile(OTHER_PROFILE_CONTENT)
134135
.withReceiptId(DECODED_RECEIPT_BYTES)
@@ -140,7 +141,8 @@ public void shouldGetCorrectProfilesFromProfileReader() throws Exception {
140141

141142
assertSame(otherProfileMock, getWrappedProfile(result.getUserProfile()));
142143
assertSame(profileMock, getWrappedProfile(result.getApplicationProfile()));
143-
assertEquals(SOME_USER_ID_STRING, result.getUserId());
144+
assertEquals(SOME_REMEMBER_ME_ID_STRING, result.getRememberMeId());
145+
assertEquals(SOME_REMEMBER_ME_ID_STRING, result.getUserId());
144146
assertEquals(ENCODED_RECEIPT_STRING, result.getReceiptId());
145147
assertEquals(DATE, result.getTimestamp());
146148
}

yoti-sdk-impl/src/test/java/com/yoti/api/client/spi/remote/SimpleActivityDetailsTest.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
public class SimpleActivityDetailsTest {
1616

17-
private static final String USER_ID = "YmFkYWRhZGEtZGFkYWJhZGEK";
17+
private static final String REMEMBER_ME_ID = "YmFkYWRhZGEtZGFkYWJhZGEK";
1818
private static final Profile USER_PROFILE = Mockito.mock(Profile.class);
1919
private static final Profile APP_PROFILE = Mockito.mock(Profile.class);
2020
private static final Profile USER_PROFILE_WRAPPER = HumanProfileAdapter.wrap(USER_PROFILE);
@@ -31,50 +31,51 @@ public void shouldFailConstructionForNullRememberMeId() {
3131

3232
@Test(expected = IllegalArgumentException.class)
3333
public void shouldFailConstructionForNullUserProfile() {
34-
new SimpleActivityDetails(USER_ID, null, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
34+
new SimpleActivityDetails(REMEMBER_ME_ID, null, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
3535
}
3636

3737
@Test(expected = IllegalArgumentException.class)
3838
public void shouldFailConstructionForNullAppProfile() {
39-
new SimpleActivityDetails(USER_ID, USER_PROFILE, null, TIMESTAMP, RECEIPT_ID);
39+
new SimpleActivityDetails(REMEMBER_ME_ID, USER_PROFILE, null, TIMESTAMP, RECEIPT_ID);
4040
}
4141

4242
@Test(expected = IllegalArgumentException.class)
4343
public void shouldFailConstructionForNullTimestamp() {
44-
new SimpleActivityDetails(USER_ID, USER_PROFILE, APP_PROFILE, null, RECEIPT_ID);
44+
new SimpleActivityDetails(REMEMBER_ME_ID, USER_PROFILE, APP_PROFILE, null, RECEIPT_ID);
4545
}
4646

4747
@Test(expected = IllegalArgumentException.class)
4848
public void shouldFailConstructionForNullReceiptId() {
49-
new SimpleActivityDetails(USER_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, null);
49+
new SimpleActivityDetails(REMEMBER_ME_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, null);
5050
}
5151

5252
@Test(expected = IllegalArgumentException.class)
5353
public void shouldFailConstructionForNullProfile() {
54-
new SimpleActivityDetails(USER_ID, null, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
54+
new SimpleActivityDetails(REMEMBER_ME_ID, null, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
5555
}
5656

5757
@Test
5858
public void shouldReturnUserId() {
59-
SimpleActivityDetails s = new SimpleActivityDetails(USER_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
60-
assertEquals(USER_ID, s.getUserId());
59+
SimpleActivityDetails s = new SimpleActivityDetails(REMEMBER_ME_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
60+
assertEquals(REMEMBER_ME_ID, s.getRememberMeId());
61+
assertEquals(REMEMBER_ME_ID, s.getUserId());
6162
}
6263

6364
@Test
6465
public void shouldReturnUserProfile() {
65-
SimpleActivityDetails s = new SimpleActivityDetails(USER_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
66+
SimpleActivityDetails s = new SimpleActivityDetails(REMEMBER_ME_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
6667
assertEquals(USER_PROFILE_WRAPPER, s.getUserProfile());
6768
}
6869

6970
@Test
7071
public void shouldReturnAppProfile() {
71-
SimpleActivityDetails s = new SimpleActivityDetails(USER_ID, APP_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
72+
SimpleActivityDetails s = new SimpleActivityDetails(REMEMBER_ME_ID, APP_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
7273
assertEquals(APP_PROFILE_WRAPPER, s.getApplicationProfile());
7374
}
7475

7576
@Test
7677
public void shouldReturnReceiptId() {
77-
SimpleActivityDetails s = new SimpleActivityDetails(USER_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
78+
SimpleActivityDetails s = new SimpleActivityDetails(REMEMBER_ME_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
7879
assertEquals(RECEIPT_ID_STRING, s.getReceiptId());
7980
}
8081

@@ -83,7 +84,7 @@ public void shouldReturnBase64SelfieIfSelfieSet() {
8384
Attribute selfie = new SimpleAttribute("selfie", new JpegAttributeValue(SOME_SELFIE_BYTES));
8485
SimpleProfile profile = new SimpleProfile(Collections.<Attribute<?>>singletonList(selfie));
8586

86-
SimpleActivityDetails result = new SimpleActivityDetails(USER_ID, profile, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
87+
SimpleActivityDetails result = new SimpleActivityDetails(REMEMBER_ME_ID, profile, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
8788

8889
String expected = "data:image/jpeg;base64," + Base64.toBase64String(SOME_SELFIE_BYTES);
8990
assertEquals(expected, result.getBase64Selfie());
@@ -94,7 +95,7 @@ public void shouldReturnBlankBase64SelfieIfSelfieNotSet() {
9495
Attribute familyName = new SimpleAttribute("family_name", "Smith");
9596
SimpleProfile profile = new SimpleProfile(Collections.<Attribute<?>>singletonList(familyName));
9697

97-
SimpleActivityDetails result = new SimpleActivityDetails(USER_ID, profile, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
98+
SimpleActivityDetails result = new SimpleActivityDetails(REMEMBER_ME_ID, profile, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
9899

99100
assertEquals("", result.getBase64Selfie());
100101
}

yoti-sdk-spring-boot-example/src/main/java/com/yoti/api/examples/springboot/YotiLoginController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public String doLogin(@RequestParam("token") final String token, final Model mod
6565
}
6666

6767
// load activityDetails into ui model
68-
model.addAttribute("userId", activityDetails.getUserId());
68+
model.addAttribute("rememberMeId", activityDetails.getRememberMeId());
6969
model.addAttribute("base64Selfie", activityDetails.getBase64Selfie());
7070

7171
// load humanProfile data into ui model

yoti-sdk-spring-boot-example/src/main/resources/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<script src="https://sdk.yoti.com/clients/browser.2.1.0.js"></script>
99
</head>
1010
<body>
11-
<p th:text="${userId}"/>
11+
<p th:text="${rememberMeId}"/>
1212
<!-- This span will create the Yoti button -->
1313
<span data-th-attr="data-yoti-application-id=${applicationId}">
1414
Use Yoti

yoti-sdk-spring-boot-example/src/main/resources/templates/profile.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<th>Verifiers</th>
1515
<tr>
1616
<td>User ID:</td>
17-
<td><p th:text="${userId}"/></td>
17+
<td><p th:text="${rememberMeId}"/></td>
1818
</tr>
1919
<tr>
2020
<td>Selfie:</td>

0 commit comments

Comments
 (0)