forked from IABTechLab/uid2-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_client.py
More file actions
38 lines (29 loc) · 1.21 KB
/
sample_client.py
File metadata and controls
38 lines (29 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sys
from uid2_client import Uid2Client
from uid2_client import decrypt
from uid2_client import encrypt
from uid2_client.identity_scope import IdentityScope
# this sample client decrypts an advertising token into a raw UID2
# and then encrypts it into a new advertising token
# to demonstrate decryption (for DSPs and sharers) and encryption (sharers only).
def _usage():
print('Usage: python3 sample_client.py <base_url> <auth_key> <secret_key> <ad_token>', file=sys.stderr)
sys.exit(1)
if len(sys.argv) <= 4:
_usage()
base_url = sys.argv[1]
auth_key = sys.argv[2]
secret_key = sys.argv[3]
ad_token = sys.argv[4]
client = Uid2Client(base_url, auth_key, secret_key)
keys = client.refresh_keys()
decrypt_result = decrypt(ad_token, keys)
print('UID2 =', decrypt_result.uid2)
print('Established =', decrypt_result.established)
print('Site ID =', decrypt_result.site_id)
print('Site Key Site ID =', decrypt_result.site_key_site_id)
# Not required for DSPs, but for those using UID2 sharing functionality this shows how to encrypt a raw UID2 into
# a new advertising token.
# IdentityScope could be UID2 or EUID
new_ad_token = encrypt(decrypt_result.uid2, IdentityScope.UID2, keys)
print('New Ad Token =', new_ad_token)