You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-45Lines changed: 60 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,28 @@
1
1
# UID2 Java SDK
2
2
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)
4
14
5
15
## Who is this SDK for?
6
16
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).
7
17
8
18
## Requirements
9
19
10
-
* Java 1.8 or later
11
-
20
+
* This SDK requires Java version 1.8 or later.
12
21
13
22
## Installation
14
23
15
24
Add this dependency to your project's POM:
16
25
17
-
18
26
```
19
27
<dependency>
20
28
<groupId>com.uid2</groupId>
@@ -25,92 +33,97 @@ Add this dependency to your project's POM:
25
33
26
34
## Usage for DSPs
27
35
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).
29
37
30
38
## Usage for Publishers
31
39
32
40
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).
35
45
46
+
### Basic Usage
36
47
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.
38
49
39
-
### Basic usage
40
50
1. Create an instance of PublisherUid2Client as an instance variable.
41
51
42
52
`private final PublisherUid2Client publisherUid2Client = new PublisherUid2Client(UID2_BASE_URL, UID2_API_KEY, UID2_SECRET_KEY);`
43
53
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:
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()`
52
63
53
64
#### 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):
55
65
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):
58
67
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.
59
70
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:
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):
64
75
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) }`
66
77
3. Determine if a refresh is needed:
67
78
68
79
`if (identity.isDueForRefresh()) {..}`
69
-
4. If a refresh is needed, call:
80
+
4. If needed, refresh the token and associated values:
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()`.)
74
85
86
+
### Advanced Usage
75
87
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:
79
89
80
90
`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:
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:
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:
If you're using [standard (client and server) integration](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/guides/publisher-client-side.md):
96
107
97
108
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
+
98
110
#### Server-Only Integration
111
+
99
112
If you're using [server-only integration](https://github.com/UnifiedID2/uid2docs/blob/main/api/v2/guides/custom-publisher-integration.md):
100
113
1. Store this identity as a JSON string in the user's session, using: `identity.getJsonString()`
101
114
2. To use the user's UID2 token, use `identity.getAdvertisingToken()`
102
115
103
116
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:
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):
108
121
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) }`
110
123
3. Determine if a refresh is needed:
111
124
112
125
`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:
114
127
1. Headers (depending on your HTTP library, this might look something like):
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).
123
136
124
137
## Usage for UID Sharers
125
138
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).
127
140
128
-
1. Use UID2ClientFactory.create() to create an IUID2Client reference.
141
+
1. Use UID2ClientFactory.create() to create an IUID2Client reference:
129
142
130
143
`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):
0 commit comments