Skip to content

Commit 00050f9

Browse files
committed
ability to extract all token details, even for error cases
1 parent 6ac53b1 commit 00050f9

7 files changed

+198
-78
lines changed

src/SampleApp/Program.cs

+39
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,45 @@ static void ExampleBidStreamClient()
3232
return;
3333
}
3434

35+
var tokenDetails = client.DecryptTokenDetails(_advertisingToken, _domain);
36+
37+
//masterIv = { System.Convert.ToBase64String(tokenDetails.masterIv)}
38+
Console.WriteLine(
39+
$@"
40+
41+
DecryptionStatus = {tokenDetails.decryptionStatus};
42+
43+
identityScope = {tokenDetails.identityScope}
44+
identityType = {tokenDetails.identityType}
45+
tokenVersion = {tokenDetails.tokenVersion}
46+
masterKeyId = {tokenDetails.masterKeyId}
47+
48+
expiry = {tokenDetails.expiry}
49+
generated = {tokenDetails.generated}
50+
operatorSiteId = {tokenDetails.operatorSiteId}
51+
operatorType = {tokenDetails.operatorType}
52+
operatorVersion = {tokenDetails.operatorVersion}
53+
operatorKeyId = {tokenDetails.operatorKeyId}
54+
55+
siteKeyId = {tokenDetails.siteKeyId}
56+
57+
siteId = {tokenDetails.siteId}
58+
publisherId = {tokenDetails.publisherId}
59+
publisherKeyId = {tokenDetails.publisherKeyId}
60+
61+
privacyBits.CSTG = {tokenDetails.privacyBits.IsClientSideGenerated}
62+
privacyBits.OptedOut= {tokenDetails.privacyBits.IsOptedOut}
63+
established = {tokenDetails.established}
64+
refreshed = {tokenDetails.refreshed}
65+
66+
idLength = {tokenDetails.idLength}
67+
idString = {tokenDetails.idString}
68+
69+
");
70+
71+
72+
73+
return;
3574
var result = client.DecryptTokenIntoRawUid(_advertisingToken, _domain);
3675
Console.WriteLine($"DecryptedSuccess={result.Success} Status={result.Status}");
3776
Console.WriteLine($"UID={result.Uid}");

src/UID2.Client/BidstreamClient.cs

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public DecryptionResponse DecryptTokenIntoRawUid(string token, string domainOrAp
1717
return DecryptTokenIntoRawUid(token, domainOrAppNameFromBidRequest, DateTime.UtcNow);
1818
}
1919

20+
public TokenDetails DecryptTokenDetails(string token, string domainOrAppNameFromBidRequest)
21+
{
22+
return _tokenHelper.DecryptTokenDetails(token, DateTime.UtcNow, domainOrAppNameFromBidRequest, ClientType.Bidstream);
23+
}
24+
2025
internal DecryptionResponse DecryptTokenIntoRawUid(string token, string domainOrAppNameFromBidRequest, DateTime utcNow)
2126
{
2227
return _tokenHelper.Decrypt(token, utcNow, domainOrAppNameFromBidRequest, ClientType.Bidstream);

src/UID2.Client/IdentityScope.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace UID2.Client
22
{
3-
internal enum IdentityScope
3+
public enum IdentityScope
44
{
55
UID2 = 0,
66
EUID = 1,

src/UID2.Client/PrivacyBits.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace UID2.Client
44
{
5-
internal class PrivacyBits
5+
public class PrivacyBits
66
{
77
// Bit 0 is legacy and is no longer in use
88
private const int BitClientSideGenerated = 1;

src/UID2.Client/TokenHelper.cs

+20-4
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,45 @@ internal TokenHelper(string endpoint, string authKey, string secretKey)
1515
_uid2ClientHelper = new Uid2ClientHelper(endpoint, authKey, secretKey);
1616
}
1717

18+
internal static DecryptionResponse TokenDetailsToDecryptionResponse(TokenDetails tokenDetails)
19+
{
20+
string uid = tokenDetails.idString; //todo, some errors should blank this out
21+
int siteKeySiteId = 0; //todo
22+
23+
return new DecryptionResponse(tokenDetails.decryptionStatus, uid, tokenDetails.established, tokenDetails.siteId, siteKeySiteId, tokenDetails.identityType, tokenDetails.tokenVersion,
24+
tokenDetails.privacyBits?.IsClientSideGenerated, tokenDetails.expiry);
25+
}
26+
1827
internal DecryptionResponse Decrypt(string token, DateTime now, string domainOrAppNameFromBidRequest, ClientType clientType)
28+
{
29+
var tokenDetails = DecryptTokenDetails(token, now, domainOrAppNameFromBidRequest, clientType);
30+
return TokenDetailsToDecryptionResponse(tokenDetails);
31+
}
32+
33+
internal TokenDetails DecryptTokenDetails(string token, DateTime now, string domainOrAppNameFromBidRequest, ClientType clientType)
1934
{
2035
var container = Volatile.Read(ref _container);
2136
if (container == null)
2237
{
23-
return DecryptionResponse.MakeError(DecryptionStatus.NotInitialized);
38+
return new TokenDetails(DecryptionStatus.NotInitialized);
2439
}
2540

2641
if (!container.IsValid(now))
2742
{
28-
return DecryptionResponse.MakeError(DecryptionStatus.KeysNotSynced);
43+
return new TokenDetails(DecryptionStatus.KeysNotSynced);
2944
}
3045

3146
try
3247
{
33-
return UID2Encryption.Decrypt(token, container, now, domainOrAppNameFromBidRequest, container.IdentityScope, clientType);
48+
return UID2Encryption.DecryptTokenDetails(token, container, now, domainOrAppNameFromBidRequest, container.IdentityScope, clientType);
3449
}
3550
catch (Exception)
3651
{
37-
return DecryptionResponse.MakeError(DecryptionStatus.InvalidPayload);
52+
return new TokenDetails(DecryptionStatus.InvalidPayload);
3853
}
3954
}
4055

56+
4157
internal EncryptionDataResponse Encrypt(string rawUid, DateTime now)
4258
{
4359
var container = Volatile.Read(ref _container);

src/UID2.Client/UID2Client.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ private DecryptionResponse Decrypt(string token, DateTime now, string domainOrAp
6262

6363
try
6464
{
65-
return UID2Encryption.Decrypt(token, container, now, domainOrAppNameFromBidRequest, _identityScope, clientType);
65+
var tokenDetails = UID2Encryption.DecryptTokenDetails(token, container, now, domainOrAppNameFromBidRequest, _identityScope, clientType);
66+
return TokenHelper.TokenDetailsToDecryptionResponse(tokenDetails);
6667
}
6768
catch (Exception)
6869
{

0 commit comments

Comments
 (0)