Skip to content

Commit

Permalink
SDK-566: Replace userId with rememberMeId
Browse files Browse the repository at this point in the history
  • Loading branch information
bucky-boy committed Oct 15, 2018
1 parent bff51cc commit 7654293
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 29 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ so can use it to determine whether a user is new to you. For example:
ActivityDetails activityDetails;
try {
activityDetails = client.getActivityDetails(token);
Optional<YourAppUserClass> user = yourUserSearchMethod(activityDetails.getUserId());
Optional<YourAppUserClass> user = yourUserSearchMethod(activityDetails.getRememberMeId());
if (user.isPresent()) {
String userId = activityDetails.getUserId();
String rememberMeId = activityDetails.getRememberMeId();
String base64Selfie = activityDetails.getBase64Selfie();
Attribute<Image> selfie = profile.getSelfie();
Image selfieValue = selfie.getValue();
Expand All @@ -210,7 +210,7 @@ try {
}
```

Where `yourUserSearchMethod` is a method in your app that finds the user for the given userId.
Where `yourUserSearchMethod` is a method in your app that finds the user for the given rememberMeId.
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.

### Attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ public interface ActivityDetails {
ApplicationProfile getApplicationProfile();

/**
* Return the user ID, which is a unique, stable identifier for a user in the context of an application/user
* Deprecated. Please use getRememberMeId() instead.
*
* @return user ID.
*/
@Deprecated
String getUserId();

/**
* Return the remember-me ID, which is a unique, stable identifier for a user in the context of an application/user
* interaction. You can be use it to identify returning users. Note that it is different for the same user in
* different applications.
*
* @return user ID.
*/
String getUserId();
String getRememberMeId();


/**
* Time and date of the activity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

final class SimpleActivityDetails implements ActivityDetails {

private final String userId;
private final String rememberMeId;
private final ApplicationProfile applicationProfile;
private final HumanProfile userProfile;
private final Date timestamp;
private final String receiptId;
private final String base64Selfie;

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

@Override
@Deprecated
public String getUserId() {
return userId;
return getRememberMeId();
}

@Override
public String getRememberMeId() {
return rememberMeId;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static com.yoti.api.client.spi.remote.util.CryptoUtil.generateSymmetricKey;

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

private static final String SOME_USER_ID_STRING = "aBase64EncodedUserId";
private static final byte[] SOME_USER_ID_BYTES = decode(SOME_USER_ID_STRING);
private static final String SOME_REMEMBER_ME_ID_STRING = toBase64String("aBase64EncodedRememberMeId".getBytes());
private static final byte[] SOME_REMEMBER_ME_ID_BYTES = decode(SOME_REMEMBER_ME_ID_STRING);
private static final String ENCODED_RECEIPT_STRING = "base64EncodedReceipt";
private static final byte[] DECODED_RECEIPT_BYTES = decode(ENCODED_RECEIPT_STRING);

Expand Down Expand Up @@ -128,7 +129,7 @@ public void shouldGetCorrectProfilesFromProfileReader() throws Exception {
Receipt receipt = new Receipt.Builder()
.withWrappedReceiptKey(validReceiptKey)
.withTimestamp(VALID_TIMESTAMP)
.withRememberMeId(SOME_USER_ID_BYTES)
.withRememberMeId(SOME_REMEMBER_ME_ID_BYTES)
.withProfile(PROFILE_CONTENT)
.withOtherPartyProfile(OTHER_PROFILE_CONTENT)
.withReceiptId(DECODED_RECEIPT_BYTES)
Expand All @@ -140,7 +141,8 @@ public void shouldGetCorrectProfilesFromProfileReader() throws Exception {

assertSame(otherProfileMock, getWrappedProfile(result.getUserProfile()));
assertSame(profileMock, getWrappedProfile(result.getApplicationProfile()));
assertEquals(SOME_USER_ID_STRING, result.getUserId());
assertEquals(SOME_REMEMBER_ME_ID_STRING, result.getRememberMeId());
assertEquals(SOME_REMEMBER_ME_ID_STRING, result.getUserId());
assertEquals(ENCODED_RECEIPT_STRING, result.getReceiptId());
assertEquals(DATE, result.getTimestamp());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class SimpleActivityDetailsTest {

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

@Test(expected = IllegalArgumentException.class)
public void shouldFailConstructionForNullUserProfile() {
new SimpleActivityDetails(USER_ID, null, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
new SimpleActivityDetails(REMEMBER_ME_ID, null, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
}

@Test(expected = IllegalArgumentException.class)
public void shouldFailConstructionForNullAppProfile() {
new SimpleActivityDetails(USER_ID, USER_PROFILE, null, TIMESTAMP, RECEIPT_ID);
new SimpleActivityDetails(REMEMBER_ME_ID, USER_PROFILE, null, TIMESTAMP, RECEIPT_ID);
}

@Test(expected = IllegalArgumentException.class)
public void shouldFailConstructionForNullTimestamp() {
new SimpleActivityDetails(USER_ID, USER_PROFILE, APP_PROFILE, null, RECEIPT_ID);
new SimpleActivityDetails(REMEMBER_ME_ID, USER_PROFILE, APP_PROFILE, null, RECEIPT_ID);
}

@Test(expected = IllegalArgumentException.class)
public void shouldFailConstructionForNullReceiptId() {
new SimpleActivityDetails(USER_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, null);
new SimpleActivityDetails(REMEMBER_ME_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, null);
}

@Test(expected = IllegalArgumentException.class)
public void shouldFailConstructionForNullProfile() {
new SimpleActivityDetails(USER_ID, null, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
new SimpleActivityDetails(REMEMBER_ME_ID, null, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
}

@Test
public void shouldReturnUserId() {
SimpleActivityDetails s = new SimpleActivityDetails(USER_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
assertEquals(USER_ID, s.getUserId());
SimpleActivityDetails s = new SimpleActivityDetails(REMEMBER_ME_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
assertEquals(REMEMBER_ME_ID, s.getRememberMeId());
assertEquals(REMEMBER_ME_ID, s.getUserId());
}

@Test
public void shouldReturnUserProfile() {
SimpleActivityDetails s = new SimpleActivityDetails(USER_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
SimpleActivityDetails s = new SimpleActivityDetails(REMEMBER_ME_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
assertEquals(USER_PROFILE_WRAPPER, s.getUserProfile());
}

@Test
public void shouldReturnAppProfile() {
SimpleActivityDetails s = new SimpleActivityDetails(USER_ID, APP_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
SimpleActivityDetails s = new SimpleActivityDetails(REMEMBER_ME_ID, APP_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
assertEquals(APP_PROFILE_WRAPPER, s.getApplicationProfile());
}

@Test
public void shouldReturnReceiptId() {
SimpleActivityDetails s = new SimpleActivityDetails(USER_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
SimpleActivityDetails s = new SimpleActivityDetails(REMEMBER_ME_ID, USER_PROFILE, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
assertEquals(RECEIPT_ID_STRING, s.getReceiptId());
}

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

SimpleActivityDetails result = new SimpleActivityDetails(USER_ID, profile, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
SimpleActivityDetails result = new SimpleActivityDetails(REMEMBER_ME_ID, profile, APP_PROFILE, TIMESTAMP, RECEIPT_ID);

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

SimpleActivityDetails result = new SimpleActivityDetails(USER_ID, profile, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
SimpleActivityDetails result = new SimpleActivityDetails(REMEMBER_ME_ID, profile, APP_PROFILE, TIMESTAMP, RECEIPT_ID);

assertEquals("", result.getBase64Selfie());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public String doLogin(@RequestParam("token") final String token, final Model mod
}

// load activityDetails into ui model
model.addAttribute("userId", activityDetails.getUserId());
model.addAttribute("rememberMeId", activityDetails.getRememberMeId());
model.addAttribute("base64Selfie", activityDetails.getBase64Selfie());

// load humanProfile data into ui model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script src="https://sdk.yoti.com/clients/browser.2.1.0.js"></script>
</head>
<body>
<p th:text="${userId}"/>
<p th:text="${rememberMeId}"/>
<!-- This span will create the Yoti button -->
<span data-th-attr="data-yoti-application-id=${applicationId}">
Use Yoti
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<th>Verifiers</th>
<tr>
<td>User ID:</td>
<td><p th:text="${userId}"/></td>
<td><p th:text="${rememberMeId}"/></td>
</tr>
<tr>
<td>Selfie:</td>
Expand Down

0 comments on commit 7654293

Please sign in to comment.