-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathIdentityMapV3Helper.java
More file actions
40 lines (32 loc) · 1.96 KB
/
IdentityMapV3Helper.java
File metadata and controls
40 lines (32 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.uid2.client;
import com.google.gson.Gson;
import java.nio.charset.StandardCharsets;
public class IdentityMapV3Helper {
/**
* @param base64SecretKey your UID2 client secret
*/
public IdentityMapV3Helper(String base64SecretKey) {uid2Helper = new Uid2Helper(base64SecretKey);}
/**
* @param identityMapInput represents the input required for <a href="https://unifiedid.com/docs/endpoints/post-identity-map">/identity/map</a>
* @return an EnvelopeV2 instance to use in the POST body of <a href="https://unifiedid.com/docs/endpoints/post-identity-map">/identity/map</a>
*/
public EnvelopeV2 createEnvelopeForIdentityMapRequest(IdentityMapV3Input identityMapInput) {
byte[] jsonBytes = new Gson().toJson(identityMapInput).getBytes(StandardCharsets.UTF_8);
return uid2Helper.createEnvelopeV2(jsonBytes);
}
/**
* @param responseString the response body returned by a call to <a href="https://unifiedid.com/docs/endpoints/post-identity-map">/identity/map</a>
* @param envelope the EnvelopeV2 instance returned by {@link #createEnvelopeForIdentityMapRequest}
* @param identityMapInput the same instance that was passed to {@link #createEnvelopeForIdentityMapRequest}.
* @return an IdentityMapV3Response instance
*/
public IdentityMapV3Response createIdentityMapResponse(String responseString, EnvelopeV2 envelope, IdentityMapV3Input identityMapInput) {
String decryptedResponseString = uid2Helper.decrypt(responseString, envelope.getNonce());
return new IdentityMapV3Response(decryptedResponseString, identityMapInput);
}
public IdentityMapV3Response createIdentityMapResponse(byte[] response, EnvelopeV2 envelope, IdentityMapV3Input identityMapInput) {
String decryptedResponseString = uid2Helper.decrypt(response, envelope.getNonce());
return new IdentityMapV3Response(decryptedResponseString, identityMapInput);
}
private final Uid2Helper uid2Helper;
}