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: web-integrations/javascript-sdk/server-side-node/README.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,13 +8,16 @@ For more information on the JavaScript SDK, refer to the [UID2 SDK for JavaScrip
8
8
9
9
This example can be configured for either UID2 or EUID — the behavior is determined by your environment variable configuration. You cannot use both simultaneously.
10
10
11
-
## Key Benefits
11
+
## How This Implementation Works
12
12
13
-
This example demonstrates the advantages of using the JavaScript SDK on the server:
13
+
Unlike the browser where the SDK runs natively in the DOM, this example uses **jsdom** to simulate a browser environment within Node.js:
14
14
15
-
-**Secure credential handling**: Public credentials (server public key and subscription ID) remain on the server and are not exposed to the browser
16
-
-**Simplified implementation**: The SDK handles the full token lifecycle including encryption, decryption, and refresh logic automatically
17
-
-**No manual cryptography**: Unlike traditional server-side integrations, there's no need to manually implement encryption/decryption processes
15
+
1.**Creates a virtual DOM**: Uses jsdom to provide `window`, `document`, and `navigator` objects that the SDK expects
16
+
2.**Polyfills browser APIs**: Adds Node.js equivalents for Web Crypto API (`crypto.subtle`) and text encoding APIs (`TextEncoder`/`TextDecoder`)
17
+
3.**Loads the SDK**: Fetches and executes the browser-based SDK code within the simulated environment
18
+
4.**Runs SDK methods**: Calls `setIdentityFromEmail` just like in a browser, with the same public credentials
19
+
20
+
This demonstrates that the client-side SDK can be compatible with server-side Node.js environments when given the proper browser-like context.
18
21
19
22
## Build and Run the Example Application
20
23
@@ -91,13 +94,10 @@ The following table outlines and annotates the steps you may take to test and ex
91
94
| 3 | Review the displayed identity information. | The server reads the user session and extracts the current identity ([server.js](server.js)). The `advertising_token` on the identity can be used for targeted advertising. Note that the identity contains several timestamps that determine when the advertising token becomes invalid (`identity_expires`) and when the server should attempt to refresh it (`refresh_from`). The `verifyIdentity` function ([server.js](server.js)) uses the SDK to refresh the token as needed.<br/>The user is automatically logged out in the following cases:<br/>- If the identity expires without being refreshed and refresh attempt fails.<br/>- If the refresh token expires.<br/>- If the refresh attempt indicates that the user has opted out. |
92
95
| 4 | To exit the application, click **Log Out**. | This calls the `/logout` endpoint on the server ([server.js](server.js)), which clears the session and presents the user with the login form again.<br/> NOTE: The page displays the **Log Out** button as long as the user is logged in. |
93
96
94
-
## How This Implementation Works
95
-
96
-
Unlike the browser where the SDK runs natively in the DOM, this example uses **jsdom** to simulate a browser environment within Node.js:
97
+
## Key Benefits
97
98
98
-
1.**Creates a virtual DOM**: Uses jsdom to provide `window`, `document`, and `navigator` objects that the SDK expects
99
-
2.**Polyfills browser APIs**: Adds Node.js equivalents for Web Crypto API (`crypto.subtle`) and text encoding APIs (`TextEncoder`/`TextDecoder`)
100
-
3.**Loads the SDK**: Fetches and executes the browser-based SDK code within the simulated environment
101
-
4.**Runs SDK methods**: Calls `setIdentityFromEmail` just like in a browser, with the same public credentials
99
+
This example demonstrates the advantages of using the JavaScript SDK on the server:
102
100
103
-
This demonstrates that the client-side SDK is can be compatible with server-side Node.js environments when given the proper browser-like context.
101
+
-**Secure credential handling**: Public credentials (server public key and subscription ID) remain on the server and are not exposed to the browser
102
+
-**Simplified implementation**: The SDK handles the full token lifecycle including encryption, decryption, and refresh logic automatically
103
+
-**No manual cryptography**: Unlike traditional server-side integrations, there's no need to manually implement encryption/decryption processes
0 commit comments