Skip to content

Commit f0d3e3a

Browse files
committed
move sharing encryption example to its own file
1 parent 448f3ab commit f0d3e3a

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

examples/sample_client.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,4 @@ def _usage():
2929
print('UID2 =', decrypt_result.uid2)
3030
print('Established =', decrypt_result.established)
3131
print('Site ID =', decrypt_result.site_id)
32-
print('Site Key Site ID =', decrypt_result.site_key_site_id)
33-
34-
# Not required for DSPs, but for those using UID2 sharing functionality this shows how to encrypt a raw UID2 into
35-
# a new advertising token.
36-
# IdentityScope could be UID2 or EUID
37-
new_ad_token = client.encrypt(decrypt_result.uid2, keys)
38-
print('New Ad Token =', new_ad_token)
32+
print('Site Key Site ID =', decrypt_result.site_key_site_id)

examples/sample_sharing.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
3+
from uid2_client import Uid2Client
4+
from uid2_client import decrypt
5+
from uid2_client import encrypt
6+
from uid2_client.identity_scope import IdentityScope
7+
8+
def _usage():
9+
print('Usage: python3 sample_encryption.py <base_url> <auth_key> <secret_key> <raw_uid>', file=sys.stderr)
10+
sys.exit(1)
11+
12+
13+
if len(sys.argv) <= 4:
14+
_usage()
15+
16+
base_url = sys.argv[1]
17+
auth_key = sys.argv[2]
18+
secret_key = sys.argv[3]
19+
raw_uid = sys.argv[4]
20+
21+
client = Uid2Client(base_url, auth_key, secret_key, IdentityScope.UID2)
22+
keys = client.refresh_keys()
23+
24+
new_ad_token = client.encrypt(raw_uid, keys)
25+
print('New Ad Token =', new_ad_token)
26+
decrypt_result = client.decrypt(new_ad_token, keys)
27+
print('Decrypted UID2 =', decrypt_result.uid2)
28+
print('Established =', decrypt_result.established)
29+
print('Site ID =', decrypt_result.site_id)
30+
print('Site Key Site ID =', decrypt_result.site_key_site_id)

0 commit comments

Comments
 (0)