Skip to content

Commit 8147323

Browse files
jon8787genwhittTTD
andauthored
draft review with queries marked for JN (#20)
* draft review with queries marked for JN * additional edits * additional review mods * additional edits based on JN input * minor additional edit from JN --------- Co-authored-by: genwhittTTD <gen.whitt@thetradedesk.com>
1 parent c028b85 commit 8147323

File tree

1 file changed

+60
-45
lines changed

1 file changed

+60
-45
lines changed

README.md

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
# UID2 Java SDK
22

3-
The UID 2 Project is subject to Tech Lab IPR’s Policy and is managed by the IAB Tech Lab Addressability Working Group and Privacy & Rearc Commit Group. Please review the governance rules [here](https://github.com/IABTechLab/uid2-core/blob/master/Software%20Development%20and%20Release%20Procedures.md).
3+
The UID 2 Project is subject to the IAB Tech Lab Intellectual Property Rights (IPR) Policy, and is managed by the IAB Tech Lab Addressability Working Group and [Privacy & Rearc Commit Group](https://iabtechlab.com/working-groups/privacy-rearc-commit-group/). Please review the [governance rules](https://github.com/IABTechLab/uid2-core/blob/master/Software%20Development%20and%20Release%20Procedures.md).
4+
5+
This document includes:
6+
* [Who is this SDK for?](#who-is-this-sdk-for)
7+
* [Requirements](#requirements)
8+
* [Installation](#installation)
9+
* [Usage for DSPs](#usage-for-dsps)
10+
* [Usage for Publishers](#usage-for-publishers)
11+
- [Basic Usage](#basic-usage)
12+
- [Advanced Usage](#advanced-usage)
13+
* [## Usage for UID Sharers](#usage-for-uid-sharers)
414

515
## Who is this SDK for?
616
This SDK simplifies integration with UID2 for Publishers, DSPs, and UID Sharers, as described in the [UID2 Integration Guides](https://github.com/IABTechLab/uid2docs/blob/main/api/v2/guides/summary-guides.md).
717

818
## Requirements
919

10-
* Java 1.8 or later
11-
20+
* This SDK requires Java version 1.8 or later.
1221

1322
## Installation
1423

1524
Add this dependency to your project's POM:
1625

17-
1826
```
1927
<dependency>
2028
<groupId>com.uid2</groupId>
@@ -25,92 +33,97 @@ Add this dependency to your project's POM:
2533

2634
## Usage for DSPs
2735

28-
See com.uid2.client.test.IntegrationExamples for example usage for DSPs.
36+
For an example of usage for DSPs, see [com.uid2.client.test.IntegrationExamples](https://github.com/IABTechLab/uid2-client-java/blob/master/src/test/java/com/uid2/client/test/IntegrationExamples.java).
2937

3038
## Usage for Publishers
3139

3240
As a publisher, there are two ways to use this SDK:
33-
1. **Basic usage** is for those publishers that are happy to use this SDK's HTTP implementation (synchronous [OkHttp](https://square.github.io/okhttp/)).
34-
2. **Advanced usage** is for those publishers that prefer to use their own HTTP library.
41+
1. [**Basic Usage**](#basic-usage) is for publishers who are happy to use this SDK's HTTP implementation (synchronous [OkHttp](https://square.github.io/okhttp/)).
42+
2. [**Advanced Usage**](#advanced-usage) is for publishers who prefer to use their own HTTP library.
43+
44+
For an example application that demonstrates both Basic and Advanced usage, see [uid2-examples](https://github.com/UnifiedID2/uid2-examples/tree/main/publisher/uid2-java-test-site).
3545

46+
### Basic Usage
3647

37-
An example application which demonstrates both Basic and Advanced usage is at [uid2-examples](https://github.com/UnifiedID2/uid2-examples/tree/main/publisher/uid2-java-test-site).
48+
If you're using the SDK's HTTP implementation, follow these steps.
3849

39-
### Basic usage
4050
1. Create an instance of PublisherUid2Client as an instance variable.
4151

4252
`private final PublisherUid2Client publisherUid2Client = new PublisherUid2Client(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY);`
4353

44-
2. When a user authenticates and authorizes the creation of a UID2:
54+
2. When the user has authenticated, and has authorized the creation of a UID2, call a function that takes the user's email address or phone number as input and generates an `IdentityTokens` object. The following example uses an email address:
4555

4656
`IdentityTokens identity = publisherUid2Client.generateToken(TokenGenerateInput.fromEmail(emailAddress));`
4757

48-
4958
#### Standard Integration
50-
If you're using [standard (client and server) integration](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/guides/publisher-client-side.md):
51-
1. Send this identity as a JSON string back to the client (to use in the [identity field](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/sdks/client-side-identity.md#initopts-object-void)) using: `identity.getJsonString()`
59+
60+
If you're using [standard (client and server) integration](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/guides/publisher-client-side.md), follow this step:
61+
62+
* Send this identity as a JSON string back to the client (to use in the [identity field](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/sdks/client-side-identity.md#initopts-object-void)) using: `identity.getJsonString()`
5263

5364
#### Server-Only Integration
54-
If you're using [server-only integration](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/guides/custom-publisher-integration.md):
5565

56-
1. Store this identity as a JSON string in the user's session, using: `identity.getJsonString()`
57-
2. To use the user's UID2 token, use `identity.getAdvertisingToken()`
66+
If you're using [server-only integration](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/guides/custom-publisher-integration.md):
5867

68+
1. Store this identity as a JSON string in the user's session, using the `identity.getJsonString()` function.
69+
2. To use the user's UID2 token, use the `identity.getAdvertisingToken()` function.
5970
3. When the user accesses another page, or on a timer, determine whether a refresh is needed:
60-
1. Retrieve the identity JSON string from the user's session, then call:
71+
1. Retrieve the identity JSON string from the user's session, and then call the following function that takes the identity information as input and generates an `IdentityTokens` object:
6172

6273
`IdentityTokens identity = IdentityTokens.fromJsonString(identityJsonString);`
63-
2. Determine if the identity is refreshable (ie, the refresh token hasn't expired):
74+
2. Determine if the identity can be refreshed (that is, the refresh token hasn't expired):
6475

65-
` if (identity == null || !identity.isRefreshable()) { we must no longer use this identity (eg, remove this identity from the user's session) }`
76+
` if (identity == null || !identity.isRefreshable()) { we must no longer use this identity (for example, remove this identity from the user's session) }`
6677
3. Determine if a refresh is needed:
6778

6879
`if (identity.isDueForRefresh()) {..}`
69-
4. If a refresh is needed, call:
80+
4. If needed, refresh the token and associated values:
7081

7182
`TokenRefreshResponse tokenRefreshResponse = publisherUid2Client.refreshToken(identity);`
7283

73-
5. You should then store `tokenRefreshResponse.getIdentityJsonString()` in the user's session. If the user has opted out, this method will return null, indicating that the user's identity should be removed from their session. (Optout can be confirmed via `tokenRefreshResponse.isOptout()`.)
84+
5. You should then store `tokenRefreshResponse.getIdentityJsonString()` in the user's session. If the user has opted out, this method returns null, indicating that the user's identity should be removed from their session. (Optout can be confirmed via `tokenRefreshResponse.isOptout()`.)
7485

86+
### Advanced Usage
7587

76-
### Advanced usage
77-
78-
1. Create an instance of PublisherUid2Helper as an instance variable.
88+
1. Create an instance of PublisherUid2Helper as an instance variable:
7989

8090
`private final PublisherUid2Helper publisherUid2Helper = new PublisherUid2Helper(UID2_SECRET_KEY);`
81-
2. When a user authenticates and authorizes the creation of a UID2:
91+
2. When the user has authenticated, and has authorized the creation of a UID2, call a function that takes the user's email address or phone number as input and creates a secure request data envelope. See [Encrypting requests](https://github.com/IABTechLab/uid2docs/blob/main/api/v2/getting-started/gs-encryption-decryption.md#encrypting-requests). The following example uses an email address:
8292

8393
`EnvelopeV2 envelope = publisherUid2Helper.createEnvelopeForTokenGenerateRequest(TokenGenerateInput.fromEmail(emailAddress));`
84-
3. Using an HTTP client library of your choice, post this envelope to the [/v2/token/generate](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/endpoints/post-token-generate.md) endpoint, with:
85-
1. Headers (depending on your HTTP library, this might look something like):
94+
3. Using an HTTP client library of your choice, post this envelope to the [/v2/token/generate](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/endpoints/post-token-generate.md) endpoint, including headers and body:
95+
1. Headers: Depending on your HTTP library, this might look something like the following:
8696

8797
`.putHeader("Authorization", "Bearer " + UID2_API_KEY)`
8898
`.putHeader("X-UID2-Client-Version", PublisherUid2Helper.getVersionHeader())`
8999
2. Body: `envelope.getEnvelope()`
90-
4. If the HTTP response status code is _not_ 200, see [Response Status Codes](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/endpoints/post-token-generate.md#response-status-codes) to determine next steps. Otherwise:
100+
4. If the HTTP response status code is _not_ 200, see [Response Status Codes](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/endpoints/post-token-generate.md#response-status-codes) to determine next steps. Otherwise, convert the UID2 identity response content into an `IdentityTokens` object:
91101

92102
`IdentityTokens identity = publisherUid2Helper.createIdentityfromTokenGenerateResponse({response body}, envelope);`
93103

94104
#### Standard Integration
105+
95106
If you're using [standard (client and server) integration](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/guides/publisher-client-side.md):
96107

97108
1. Send this identity as a JSON string back to the client (to use in the [identity field](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/sdks/client-side-identity.md#initopts-object-void)) using: `identity.getJsonString()`
109+
98110
#### Server-Only Integration
111+
99112
If you're using [server-only integration](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/guides/custom-publisher-integration.md):
100113
1. Store this identity as a JSON string in the user's session, using: `identity.getJsonString()`
101114
2. To use the user's UID2 token, use `identity.getAdvertisingToken()`
102115

103116
3. When the user accesses another page, or on a timer, determine whether a refresh is needed:
104-
1. Retrieve the identity JSON string from the user's session, then call:
117+
1. Retrieve the identity JSON string from the user's session, and then call the following function that generates an `IdentityTokens` object:
105118

106119
`IdentityTokens identity = IdentityTokens.fromJsonString(identityJsonString);`
107-
2. Determine if the identity is refreshable (ie, the refresh token hasn't expired):
120+
2. Determine if the identity can be refreshed (that is, the refresh token hasn't expired):
108121

109-
` if (identity == null || !identity.isRefreshable()) { we must no longer use this identity (eg, remove this identity from the user's session) }`
122+
` if (identity == null || !identity.isRefreshable()) { we must no longer use this identity (for example, remove this identity from the user's session) }`
110123
3. Determine if a refresh is needed:
111124

112125
`if (identity.isDueForRefresh()) {..}`
113-
4. If a refresh is needed, post to the [/v2/token/refresh](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/endpoints/post-token-refresh.md) endpoint, with:
126+
4. If a refresh is needed, call the [POST token/refresh](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/endpoints/post-token-refresh.md) endpoint, with:
114127
1. Headers (depending on your HTTP library, this might look something like):
115128

116129
`.putHeader("Authorization", "Bearer " + UID2_API_KEY)`
@@ -119,27 +132,29 @@ If you're using [server-only integration](https://github.com/UnifiedID2/uid2docs
119132
5. If the refresh HTTP response status code is 200:
120133

121134
`TokenRefreshResponse tokenRefreshResponse = PublisherUid2Helper.createTokenRefreshResponse({response body}, identity);`
122-
6. You should then store `tokenRefreshResponse.getIdentityJsonString()` in the user's session. If the user has opted out, this method will return null, indicating that the user's identity should be removed from their session. (Optout can be confirmed via `tokenRefreshResponse.isOptout()`.)
135+
6. You should then store `tokenRefreshResponse.getIdentityJsonString()` in the user's session. If the user has opted out, this method returns null, indicating that the user's identity should be removed from their session (you can confirm user opt-out with the `tokenRefreshResponse.isOptout()` function).
123136

124137
## Usage for UID Sharers
125138

126-
A UID Sharer is a participant that wants to share UID2s or EUIDs with another participant. Raw UIDs must be encrypted into UID tokens before sending them to another participant. See com.uid2.client.test.IntegrationExamples (runSharingExample method) for an example usage.
139+
A UID2 Sharer is a participant that wants to share UID2s or EUIDs with another participant. Raw UIDs must be encrypted into UID tokens before sending them to another participant. For an example of usage, see [com.uid2.client.test.IntegrationExamples](https://github.com/IABTechLab/uid2-client-java/blob/master/src/test/java/com/uid2/client/test/IntegrationExamples.java) (runSharingExample method).
127140

128-
1. Use UID2ClientFactory.create() to create an IUID2Client reference.
141+
1. Use UID2ClientFactory.create() to create an IUID2Client reference:
129142

130143
`private final IUID2Client client = UID2ClientFactory.create(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY);`
131-
2. Call IUID2Client.refresh: once at startup, and then periodically (eg every hour):
144+
2. Call IUID2Client.refresh once at startup, and then periodically (for example, every hour):
145+
132146
`client.refresh();`
133-
3. Senders call:
134-
1. `EncryptionDataResponse encrypted = client.encrypt(rawUid);`
135-
2. If encryption succeeded, send the UID token to the receiver:
136-
147+
3. Senders:
148+
1. Call the following:
149+
150+
`EncryptionDataResponse encrypted = client.encrypt(rawUid);`
151+
2. If encryption succeeded, send the UID token to the receiver:
152+
137153
`if (encrypted.isSuccess()) {` send `encrypted.getEncryptedData()` to receiver`} else {`check `encrypted.getStatus()` for the failure reason}
138-
4. Receivers call:
139-
1. `DecryptionResponse decrypted = client.decrypt(uidToken);`
154+
4. Receivers:
155+
1. Call the following:
156+
157+
`DecryptionResponse decrypted = client.decrypt(uidToken);`
140158
2. If decryption succeeded, use the raw UID:
141159

142160
`if (decrypted.isSuccess()) {`use `decrypted.getUid() } else {`check `decrypted.getStatus()` for the failure reason `}`
143-
144-
145-

0 commit comments

Comments
 (0)