Skip to content

Commit b590d4b

Browse files
authored
Merge pull request #59 from IABTechLab/ccm-UID2-2832-change-domain-name-to-domain-or-app-name
UID2-2832 change domain name to domain or app name
2 parents e4c13ed + b0f972c commit b590d4b

14 files changed

+202
-95
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dotnet test
2222
To run the sample app:
2323

2424
```
25-
dotnet run --project src/SampleApp/SampleApp.csproj https://integ.uidapi.com \
25+
dotnet run --project src/SampleApp/SampleApp.csproj https://operator-integ.uidapi.com \
2626
<your-api-token> <your-secret-key> <advertising-token>
2727
```
2828

src/UID2.Client/BidstreamClient.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ public BidstreamClient(string endpoint, string authKey, string secretKey)
1212
_tokenHelper = new TokenHelper(endpoint, authKey, secretKey);
1313
}
1414

15-
public DecryptionResponse DecryptTokenIntoRawUid(string token, string domainNameFromBidRequest)
15+
public DecryptionResponse DecryptTokenIntoRawUid(string token, string domainOrAppNameFromBidRequest)
1616
{
17-
return DecryptTokenIntoRawUid(token, domainNameFromBidRequest, DateTime.UtcNow);
17+
return DecryptTokenIntoRawUid(token, domainOrAppNameFromBidRequest, DateTime.UtcNow);
1818
}
1919

20-
internal DecryptionResponse DecryptTokenIntoRawUid(string token, string domainNameFromBidRequest, DateTime utcNow)
20+
internal DecryptionResponse DecryptTokenIntoRawUid(string token, string domainOrAppNameFromBidRequest, DateTime utcNow)
2121
{
22-
return _tokenHelper.Decrypt(token, utcNow, domainNameFromBidRequest, ClientType.Bidstream);
22+
return _tokenHelper.Decrypt(token, utcNow, domainOrAppNameFromBidRequest, ClientType.Bidstream);
2323
}
2424

2525

src/UID2.Client/DecryptionStatus.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public enum DecryptionStatus
1616
/// DSPs are still expected to check their records for user opt out, even when this status is not returned
1717
/// </summary>
1818
UserOptedOut,
19-
DomainNameCheckFailed,
19+
DomainOrAppNameCheckFailed,
2020
InvalidTokenLifetime
2121
}
2222
}

src/UID2.Client/IUID2Client.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ public interface IUID2Client
4040
DecryptionResponse Decrypt(string token, DateTime utcNow);
4141
DecryptionResponse Decrypt(string token);
4242
/// <summary>
43-
/// Decrypt advertising token to extract UID2 details and does a domain name check with the provided domainNameFromBidRequest param
43+
/// Decrypt advertising token to extract UID2 details and does a domain or app name check with the provided domainOrAppNameFromBidRequest param
4444
/// for tokens from Client Side Token Generation
4545
/// </summary>
4646
/// <param name="token">The UID2 Token </param>
47-
/// <param name="domainNameFromBidRequest">The domain name from bid request which should match the domain name of the publisher (registered with UID2 admin)
47+
/// <param name="domainOrAppNameFromBidRequest">The domain or app name from bid request which should match the domain or app name of the publisher (registered with UID2 admin)
4848
/// generating this token previously using Client Side Token Generation
4949
/// </param>
5050
/// <returns>Response showing if decryption is successful and the resulting UID if successful.
51-
/// Or it could return error codes/string indicating what went wrong (such as DecryptionStatus.DomainNameCheckFailed)
51+
/// Or it could return error codes/string indicating what went wrong (such as DecryptionStatus.DomainOrAppNameCheckFailed)
5252
/// </returns>
53-
DecryptionResponse Decrypt(string token, string domainNameFromBidRequest);
53+
DecryptionResponse Decrypt(string token, string domainOrAppNameFromBidRequest);
5454

5555
EncryptionDataResponse Encrypt(string rawUid);
5656
[Obsolete("Please use Encrypt(string rawUid) instead.")]

src/UID2.Client/KeyContainer.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ public bool TryGetMasterKey(DateTime now, out Key key)
114114
return TryGetKeysetActiveKey(_masterKeysetId, now, out key);
115115
}
116116

117-
public bool IsDomainNameAllowedForSite(int siteId, string domainName)
117+
public bool IsDomainOrAppNameAllowedForSite(int siteId, string domainOrAppName)
118118
{
119-
if (domainName == null)
119+
if (domainOrAppName == null)
120120
{
121121
return false;
122122
}
123123

124-
return this._siteIdToSite.TryGetValue(siteId, out var site) && site.AllowDomainName(domainName);
124+
return this._siteIdToSite.TryGetValue(siteId, out var site) && site.AllowDomainName(domainOrAppName);
125125
}
126126

127127
private bool TryGetKeysetActiveKey(int keysetId, DateTime now, out Key key)

src/UID2.Client/TokenHelper.cs

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

18-
internal DecryptionResponse Decrypt(string token, DateTime now, string domainNameFromBidRequest, ClientType clientType)
18+
internal DecryptionResponse Decrypt(string token, DateTime now, string domainOrAppNameFromBidRequest, ClientType clientType)
1919
{
2020
var container = Volatile.Read(ref _container);
2121
if (container == null)
@@ -30,7 +30,7 @@ internal DecryptionResponse Decrypt(string token, DateTime now, string domainNam
3030

3131
try
3232
{
33-
return UID2Encryption.Decrypt(token, container, now, domainNameFromBidRequest, container.IdentityScope, clientType);
33+
return UID2Encryption.Decrypt(token, container, now, domainOrAppNameFromBidRequest, container.IdentityScope, clientType);
3434
}
3535
catch (Exception)
3636
{

src/UID2.Client/UID2Client.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ public UID2Client(string endpoint, string authKey, string secretKey, IdentitySco
3434

3535
public DecryptionResponse Decrypt(string token)
3636
{
37-
return Decrypt(token, DateTime.UtcNow, null, ClientType.LegacyWithoutDomainCheck);
37+
return Decrypt(token, DateTime.UtcNow, null, ClientType.LegacyWithoutDomainOrAppNameCheck);
3838
}
3939

4040
public DecryptionResponse Decrypt(string token, DateTime utcNow)
4141
{
42-
return Decrypt(token, utcNow, null, ClientType.LegacyWithoutDomainCheck);
42+
return Decrypt(token, utcNow, null, ClientType.LegacyWithoutDomainOrAppNameCheck);
4343
}
4444

45-
public DecryptionResponse Decrypt(string token, string domainNameFromBidRequest)
45+
public DecryptionResponse Decrypt(string token, string domainOrAppNameFromBidRequest)
4646
{
47-
return Decrypt(token, DateTime.UtcNow, domainNameFromBidRequest, ClientType.LegacyWithDomainCheck);
47+
return Decrypt(token, DateTime.UtcNow, domainOrAppNameFromBidRequest, ClientType.LegacyWithDomainOrAppNameCheck);
4848
}
4949

50-
private DecryptionResponse Decrypt(string token, DateTime now, string domainNameFromBidRequest, ClientType clientType)
50+
private DecryptionResponse Decrypt(string token, DateTime now, string domainOrAppNameFromBidRequest, ClientType clientType)
5151
{
5252
var container = Volatile.Read(ref _container);
5353
if (container == null)
@@ -62,7 +62,7 @@ private DecryptionResponse Decrypt(string token, DateTime now, string domainName
6262

6363
try
6464
{
65-
return UID2Encryption.Decrypt(token, container, now, domainNameFromBidRequest, _identityScope, clientType);
65+
return UID2Encryption.Decrypt(token, container, now, domainOrAppNameFromBidRequest, _identityScope, clientType);
6666
}
6767
catch (Exception)
6868
{

src/UID2.Client/UID2Encryption.cs

+17-17
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ internal enum ClientType
1313
{
1414
Sharing,
1515
Bidstream,
16-
LegacyWithoutDomainCheck,
17-
LegacyWithDomainCheck
16+
LegacyWithoutDomainOrAppNameCheck,
17+
LegacyWithDomainOrAppNameCheck
1818
}
1919

2020
internal static class UID2Encryption
@@ -26,7 +26,7 @@ internal static class UID2Encryption
2626
private static char[] BASE64_URL_SPECIAL_CHARS = { '-', '_' };
2727

2828

29-
internal static DecryptionResponse Decrypt(string token, KeyContainer keys, DateTime now, string domainName, IdentityScope identityScope, ClientType clientType)
29+
internal static DecryptionResponse Decrypt(string token, KeyContainer keys, DateTime now, string domainOrAppName, IdentityScope identityScope, ClientType clientType)
3030
{
3131
if (token.Length < 4)
3232
{
@@ -39,24 +39,24 @@ internal static DecryptionResponse Decrypt(string token, KeyContainer keys, Date
3939

4040
if (data[0] == 2)
4141
{
42-
return DecryptV2(Convert.FromBase64String(token), keys, now, domainName, clientType);
42+
return DecryptV2(Convert.FromBase64String(token), keys, now, domainOrAppName, clientType);
4343
}
4444

4545
if (data[1] == (int)AdvertisingTokenVersion.V3)
4646
{
47-
return DecryptV3(Convert.FromBase64String(token), keys, now, identityScope, 3, domainName, clientType);
47+
return DecryptV3(Convert.FromBase64String(token), keys, now, identityScope, 3, domainOrAppName, clientType);
4848
}
4949

5050
if (data[1] == (int)AdvertisingTokenVersion.V4)
5151
{
5252
//same as V3 but use Base64URL encoding
53-
return DecryptV3(UID2Base64UrlCoder.Decode(token), keys, now, identityScope, 4, domainName, clientType);
53+
return DecryptV3(UID2Base64UrlCoder.Decode(token), keys, now, identityScope, 4, domainOrAppName, clientType);
5454
}
5555

5656
return DecryptionResponse.MakeError(DecryptionStatus.VersionNotSupported);
5757
}
5858

59-
private static DecryptionResponse DecryptV2(byte[] encryptedId, KeyContainer keys, DateTime now, string domainName, ClientType clientType)
59+
private static DecryptionResponse DecryptV2(byte[] encryptedId, KeyContainer keys, DateTime now, string domainOrAppName, ClientType clientType)
6060
{
6161
if (encryptedId.Length != TOKEN_V2_LENGTH)
6262
{
@@ -118,9 +118,9 @@ private static DecryptionResponse DecryptV2(byte[] encryptedId, KeyContainer key
118118
return new DecryptionResponse(DecryptionStatus.UserOptedOut, null, established, siteId, siteKey.SiteId, null, advertisingTokenVersion, privacyBits.IsClientSideGenerated, expiry);
119119
}
120120

121-
if (!IsDomainNameAllowedForSite(clientType, privacyBits, siteId, domainName, keys))
121+
if (!IsDomainOrAppNameAllowedForSite(clientType, privacyBits, siteId, domainOrAppName, keys))
122122
{
123-
return new DecryptionResponse(DecryptionStatus.DomainNameCheckFailed, null, established, siteId, siteKey.SiteId, null, advertisingTokenVersion, privacyBits.IsClientSideGenerated, expiry);
123+
return new DecryptionResponse(DecryptionStatus.DomainOrAppNameCheckFailed, null, established, siteId, siteKey.SiteId, null, advertisingTokenVersion, privacyBits.IsClientSideGenerated, expiry);
124124
}
125125

126126
if (!DoesTokenHaveValidLifetime(clientType, keys, now, expiry, now))
@@ -129,7 +129,7 @@ private static DecryptionResponse DecryptV2(byte[] encryptedId, KeyContainer key
129129
return new DecryptionResponse(DecryptionStatus.Success, idString, established, siteId, siteKey.SiteId, null, advertisingTokenVersion, privacyBits.IsClientSideGenerated, expiry);
130130
}
131131

132-
private static DecryptionResponse DecryptV3(byte[] encryptedId, KeyContainer keys, DateTime now, IdentityScope identityScope, int advertisingTokenVersion, string domainName, ClientType clientType)
132+
private static DecryptionResponse DecryptV3(byte[] encryptedId, KeyContainer keys, DateTime now, IdentityScope identityScope, int advertisingTokenVersion, string domainOrAppName, ClientType clientType)
133133
{
134134
if (encryptedId.Length < TOKEN_V3_MIN_LENGTH)
135135
{
@@ -203,9 +203,9 @@ private static DecryptionResponse DecryptV3(byte[] encryptedId, KeyContainer key
203203
return new DecryptionResponse(DecryptionStatus.UserOptedOut, null, established, siteId, siteKey.SiteId, identityType, advertisingTokenVersion, privacyBits.IsClientSideGenerated, expiry);
204204
}
205205

206-
if (!IsDomainNameAllowedForSite(clientType, privacyBits, siteId, domainName, keys))
206+
if (!IsDomainOrAppNameAllowedForSite(clientType, privacyBits, siteId, domainOrAppName, keys))
207207
{
208-
return new DecryptionResponse(DecryptionStatus.DomainNameCheckFailed, null, established, siteId, siteKey.SiteId, identityType, advertisingTokenVersion, privacyBits.IsClientSideGenerated, expiry);
208+
return new DecryptionResponse(DecryptionStatus.DomainOrAppNameCheckFailed, null, established, siteId, siteKey.SiteId, identityType, advertisingTokenVersion, privacyBits.IsClientSideGenerated, expiry);
209209
}
210210

211211
if (!DoesTokenHaveValidLifetime(clientType, keys, generated, expiry, now))
@@ -242,15 +242,15 @@ private static bool DoesTokenHaveValidLifetimeImpl(DateTime generatedOrNow, Date
242242
return (generatedOrNow - now).TotalSeconds <= allowClockSkewSeconds; //returns false if token generated too far in the future
243243
}
244244

245-
private static bool IsDomainNameAllowedForSite(ClientType clientType, PrivacyBits privacyBits, int siteId, string domainName, KeyContainer keys)
245+
private static bool IsDomainOrAppNameAllowedForSite(ClientType clientType, PrivacyBits privacyBits, int siteId, string domainOrAppName, KeyContainer keys)
246246
{
247247
if (!privacyBits.IsClientSideGenerated)
248248
return true;
249249

250-
if (clientType != ClientType.Bidstream && clientType != ClientType.LegacyWithDomainCheck)
250+
if (clientType != ClientType.Bidstream && clientType != ClientType.LegacyWithDomainOrAppNameCheck)
251251
return true;
252252

253-
return keys.IsDomainNameAllowedForSite(siteId, domainName);
253+
return keys.IsDomainOrAppNameAllowedForSite(siteId, domainOrAppName);
254254
}
255255

256256
internal static EncryptionDataResponse Encrypt(string rawUid, KeyContainer keys, IdentityScope identityScope, DateTime now)
@@ -327,8 +327,8 @@ internal static EncryptionDataResponse EncryptData(EncryptionDataRequest request
327327
{
328328
try
329329
{
330-
// if the enableDomainNameCheck param is enabled , the caller would have to provide siteId as part of the EncryptionDataRequest.
331-
DecryptionResponse decryptedToken = Decrypt(request.AdvertisingToken, keys, now, domainName: null, identityScope, ClientType.LegacyWithoutDomainCheck);
330+
// if the enableDomainOrAppNameCheck param is enabled , the caller would have to provide siteId as part of the EncryptionDataRequest.
331+
DecryptionResponse decryptedToken = Decrypt(request.AdvertisingToken, keys, now, domainOrAppName: null, identityScope, ClientType.LegacyWithoutDomainOrAppNameCheck);
332332
if (!decryptedToken.Success)
333333
{
334334
return EncryptionDataResponse.MakeError(EncryptionStatus.TokenDecryptFailure);

0 commit comments

Comments
 (0)