All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.uid2.client.IdentityMapHelper Maven / Gradle / Ivy

package com.uid2.client;

import com.google.gson.Gson;

import java.nio.charset.StandardCharsets;

public class IdentityMapHelper {
    /**
     * @param base64SecretKey your UID2 client secret
     */
    public IdentityMapHelper(String base64SecretKey) {uid2Helper = new Uid2Helper(base64SecretKey);}

    /**
     * @param identityMapInput represents the input required for /identity/map
     * @return an EnvelopeV2 instance to use in the POST body of /identity/map
     */
    public EnvelopeV2 createEnvelopeForIdentityMapRequest(IdentityMapInput 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 /identity/map
     * @param envelope the EnvelopeV2 instance returned by {@link #createEnvelopeForIdentityMapRequest}
     * @param identityMapInput the same instance that was passed to {@link #createEnvelopeForIdentityMapRequest}.
     * @return an IdentityMapResponse instance
     */
    public IdentityMapResponse createIdentityMapResponse(String responseString, EnvelopeV2 envelope, IdentityMapInput identityMapInput) {
        String decryptedResponseString = uid2Helper.decrypt(responseString, envelope.getNonce());
        return new IdentityMapResponse(decryptedResponseString, identityMapInput);
    }

    Uid2Helper uid2Helper;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy