-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Consolidating statics * clean up * Test Update * Update test/Microsoft.IdentityModel.TestUtils/ReferenceTokens.cs * Update --------- Co-authored-by: trwalke <[email protected]>
- Loading branch information
Showing
2 changed files
with
62 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
using System.Security.Cryptography; | ||
using System.Security.Cryptography.X509Certificates; | ||
using Microsoft.IdentityModel.Tokens; | ||
using Microsoft.IdentityModel.Tokens.Json; | ||
using Microsoft.IdentityModel.Tokens.Saml; | ||
using Microsoft.IdentityModel.Tokens.Saml2; | ||
using Microsoft.IdentityModel.Xml; | ||
|
@@ -398,38 +397,6 @@ public static string AadPayloadString | |
}.ToString(); | ||
} | ||
|
||
public static string PayloadString | ||
{ | ||
get => new JObject() | ||
{ | ||
{ JwtRegisteredClaimNames.Aud, Audience }, | ||
{ JwtRegisteredClaimNames.Azp, Azp }, | ||
{ JwtRegisteredClaimNames.Email, "[email protected]" }, | ||
{ JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() }, | ||
{ JwtRegisteredClaimNames.GivenName, "Bob" }, | ||
{ JwtRegisteredClaimNames.Iss, Issuer }, | ||
{ JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(IssueInstant).ToString() }, | ||
{ JwtRegisteredClaimNames.Jti, Jti }, | ||
{ JwtRegisteredClaimNames.Nbf, EpochTime.GetIntDate(NotBefore).ToString()}, | ||
}.ToString(Formatting.None); | ||
} | ||
|
||
public static string PayloadStringMultipleAudiences | ||
{ | ||
get => new JObject() | ||
{ | ||
{ JwtRegisteredClaimNames.Aud, JArray.FromObject(Audiences) }, | ||
{ JwtRegisteredClaimNames.Azp, Azp }, | ||
{ JwtRegisteredClaimNames.Email, "[email protected]" }, | ||
{ JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() }, | ||
{ JwtRegisteredClaimNames.GivenName, "Bob" }, | ||
{ JwtRegisteredClaimNames.Iss, Issuer }, | ||
{ JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(IssueInstant).ToString() }, | ||
{ JwtRegisteredClaimNames.Jti, Jti }, | ||
{ JwtRegisteredClaimNames.Nbf, EpochTime.GetIntDate(NotBefore).ToString()}, | ||
}.ToString(Formatting.None); | ||
} | ||
|
||
public static List<Claim> PayloadClaims | ||
{ | ||
get => new List<Claim>() | ||
|
@@ -484,34 +451,17 @@ public static List<Claim> PayloadJsonClaims | |
|
||
public static Dictionary<string, object> PayloadJsonDictionary | ||
{ | ||
get => new Dictionary<string, object>() | ||
{ | ||
{ JwtRegisteredClaimNames.Aud, Audience }, | ||
{ JwtRegisteredClaimNames.Iss, Issuer }, | ||
{ "ClaimValueTypes.String", "ClaimValueTypes.String.Value" }, | ||
{ "ClaimValueTypes.Boolean.true", true }, | ||
{ "ClaimValueTypes.Boolean.false", false }, | ||
{ "ClaimValueTypes.Double", 123.4 }, | ||
{ "ClaimValueTypes.DateTime.IS8061", DateTime.TryParse("2019-11-15T14:31:21.6101326Z", out DateTime dateTimeValue1) ? dateTimeValue1.ToUniversalTime() : new DateTime()}, | ||
{ "ClaimValueTypes.DateTime", DateTime.TryParse("2019-11-15", out DateTime dateTimeValue2) ? dateTimeValue2 : new DateTime()}, | ||
{ "ClaimValueTypes.JsonClaimValueTypes.Json1", JObject.Parse(@"{""jsonProperty1"":""jsonvalue1""}") }, | ||
{ "ClaimValueTypes.JsonClaimValueTypes.Json2", JObject.Parse(@"{""jsonProperty2"":""jsonvalue2""}") }, | ||
{ "ClaimValueTypes.JsonClaimValueTypes.JsonNull", "" }, | ||
{ "ClaimValueTypes.JsonClaimValueTypes.JsonArray1", JArray.Parse(@"[1,2,3]") }, | ||
{ "ClaimValueTypes.JsonClaimValueTypes.JsonArray2", JArray.Parse(@"[1,""2"",3]") }, | ||
{ "ClaimValueTypes.JsonClaimValueTypes.Integer1", 1 }, | ||
{ JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() } | ||
}; | ||
get => PayloadJsonClaims.ToDictionary(x => x.Type, x => (object)x.Value); | ||
} | ||
|
||
public static ClaimsIdentity PayloadClaimsIdentity | ||
{ | ||
get => new CaseSensitiveClaimsIdentity(PayloadClaims, "AuthenticationTypes.Federation"); | ||
} | ||
|
||
public static Dictionary<string, object> PayloadDictionary | ||
public static JObject PayloadAsJObject | ||
{ | ||
get => new Dictionary<string, object>() | ||
get => new JObject() | ||
{ | ||
{ JwtRegisteredClaimNames.Aud, Audience }, | ||
{ JwtRegisteredClaimNames.Azp, Azp }, | ||
|
@@ -525,11 +475,21 @@ public static Dictionary<string, object> PayloadDictionary | |
}; | ||
} | ||
|
||
public static Dictionary<string, object> PayloadDictionaryMultipleAudiences | ||
public static string PayloadString | ||
{ | ||
get => PayloadAsJObject.ToString(Formatting.None); | ||
} | ||
|
||
public static Dictionary<string, object> PayloadDictionary | ||
{ | ||
get => PayloadAsJObject.ToObject<Dictionary<string, object>>(); | ||
} | ||
|
||
public static JObject PayloadAsJObjectMultipleAudiences | ||
{ | ||
get => new Dictionary<string, object>() | ||
get => new JObject() | ||
{ | ||
{ JwtRegisteredClaimNames.Aud, JsonSerializerPrimitives.CreateJsonElement(Default.Audiences) }, | ||
{ JwtRegisteredClaimNames.Aud, JArray.FromObject(Audiences) }, | ||
{ JwtRegisteredClaimNames.Azp, Azp }, | ||
{ JwtRegisteredClaimNames.Email, "[email protected]" }, | ||
{ JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() }, | ||
|
@@ -541,6 +501,16 @@ public static Dictionary<string, object> PayloadDictionaryMultipleAudiences | |
}; | ||
} | ||
|
||
public static string PayloadStringMultipleAudiences | ||
{ | ||
get => PayloadAsJObjectMultipleAudiences.ToString(Formatting.None); | ||
} | ||
|
||
public static Dictionary<string, object> PayloadDictionaryMultipleAudiences | ||
{ | ||
get => PayloadAsJObjectMultipleAudiences.ToObject<Dictionary<string, object>>(); | ||
} | ||
|
||
public static Dictionary<string, object> RemoveClaim(this Dictionary<string, object> payloadClaims, string claimName) | ||
{ | ||
payloadClaims.Remove(claimName); | ||
|
@@ -859,20 +829,37 @@ public static List<Claim> SamlClaims | |
|
||
/// <summary> | ||
/// SamlClaims require the ability to split into name / namespace | ||
/// The <see cref="ClaimTypes.Role"/> claims are added as a list | ||
/// </summary> | ||
public static Dictionary<string, object> SamlClaimsDictionary | ||
{ | ||
get => new Dictionary<string, object>() | ||
get | ||
{ | ||
{ ClaimTypes.Country, "USA"}, | ||
{ ClaimTypes.NameIdentifier, "Bob" }, | ||
{ ClaimTypes.Email, "[email protected]" }, | ||
{ ClaimTypes.GivenName, "Bob" }, | ||
{ ClaimTypes.HomePhone, "555.1212" }, | ||
{ ClaimTypes.Role, new List<string>{"Developer", "Sales" } }, | ||
{ ClaimTypes.StreetAddress, "123AnyWhereStreet\r\nSomeTown/r/nUSA" }, | ||
{ ClaimsIdentity.DefaultNameClaimType, "Jean-S�bastien" } | ||
}; | ||
Dictionary<string, object> dictionary = new Dictionary<string, object>(); | ||
|
||
foreach (Claim claim in SamlClaims) | ||
{ | ||
if (dictionary.ContainsKey(claim.Type)) | ||
{ | ||
if (claim.Type == ClaimTypes.Role) | ||
{ | ||
((List<string>)dictionary[claim.Type]).Add(claim.Value); | ||
} | ||
} | ||
else | ||
{ | ||
if (claim.Type == ClaimTypes.Role) | ||
{ | ||
dictionary[claim.Type] = new List<string> { claim.Value }; | ||
} | ||
else | ||
{ | ||
dictionary[claim.Type] = claim.Value; | ||
} | ||
} | ||
} | ||
return dictionary; | ||
} | ||
} | ||
|
||
/// <summary> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -373,39 +373,32 @@ public static string SamlToken_Formated | |
// { "int", 123 }. | ||
public static string JWSWithSingleAdditionalHeaderClaim = "eyJhbGciOiJSUzI1NiIsImtpZCI6Ikpzb25XZWJLZXlSc2FfMjA0OCIsInR5cCI6IkpXVCIsImludCI6MTIzfQ.eyJlbWFpbCI6IkJvYkBjb250b3NvLmNvbSIsImdpdmVuX25hbWUiOiJCb2IiLCJpc3MiOiJodHRwOi8vRGVmYXVsdC5Jc3N1ZXIuY29tIiwiYXVkIjoiaHR0cDovL0RlZmF1bHQuQXVkaWVuY2UuY29tIiwiaWF0IjoiMTQ4OTc3NTYxNyIsIm5iZiI6IjE0ODk3NzU2MTciLCJleHAiOiIyNTM0MDIzMDA3OTkifQ.DhPiCtD9HWTjG5LDCW8YxSaBXffmPosGnnKINuey6ec50Yf72SzBnMDVZ4Cw9S_SyqSRIxVs0x87g0ZUP8fytUxr_D7ksf0cBI9tqh2MgoAZ2lY8T8oflfIBaTLraZHRmjRCMZGdOLmGj__xqM7mmD0Y1grwAkQgMCLlze2qgCXmym_8jAWfSLQcNc-XNUaDZBlbgebic7TZ0INa93QcJvm_ov6t_rg90Y0l4xCxL_VOdXctdbc5D87bEaaAdqThfVMA1325JZdS_CBWVelLf5zZYPldVDxnD9l93Fy0gqWTWJ0QxMP-BDMgXbQQdUDoSC5HrxXU2JRXnF8V_V4G2g"; | ||
|
||
|
||
// This token is unsigned and includes one additional header claim: | ||
// { "int", 123 }. | ||
public static string UnsignedJWSWithSingleAdditionalHeaderClaim = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIiwiaW50IjoxMjN9.eyJlbWFpbCI6IkJvYkBjb250b3NvLmNvbSIsImdpdmVuX25hbWUiOiJCb2IiLCJpc3MiOiJodHRwOi8vRGVmYXVsdC5Jc3N1ZXIuY29tIiwiYXVkIjoiaHR0cDovL0RlZmF1bHQuQXVkaWVuY2UuY29tIiwiaWF0IjoiMTQ4OTc3NTYxNyIsIm5iZiI6IjE0ODk3NzU2MTciLCJleHAiOiIyNTM0MDIzMDA3OTkifQ."; | ||
|
||
// the following values are separate from the one in Default.cs, so we can change the Defaults | ||
// Do not change any of these values either adding new values or order or the tests will break. | ||
public static Dictionary<string, object> PayloadDictionary | ||
public static JObject PayloadAsJObject | ||
{ | ||
get => new Dictionary<string, object>() | ||
get => new JObject() | ||
{ | ||
{ JwtRegisteredClaimNames.Email, "[email protected]" }, | ||
{ JwtRegisteredClaimNames.GivenName, "Bob" }, | ||
{ JwtRegisteredClaimNames.Iss, Issuer }, | ||
{ JwtRegisteredClaimNames.Aud, Audience }, | ||
{ JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(IssueInstant).ToString() }, | ||
{ JwtRegisteredClaimNames.Nbf, EpochTime.GetIntDate(NotBefore).ToString()}, | ||
{ JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() } | ||
{ JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() }, | ||
}; | ||
} | ||
|
||
public static string PayloadString | ||
{ | ||
get => new JObject() | ||
{ | ||
{ JwtRegisteredClaimNames.Email, "[email protected]" }, | ||
{ JwtRegisteredClaimNames.GivenName, "Bob" }, | ||
{ JwtRegisteredClaimNames.Iss, Issuer }, | ||
{ JwtRegisteredClaimNames.Aud, Audience }, | ||
{ JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(IssueInstant).ToString() }, | ||
{ JwtRegisteredClaimNames.Nbf, EpochTime.GetIntDate(NotBefore).ToString()}, | ||
{ JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(Expires).ToString() }, | ||
}.ToString(Formatting.None); | ||
get => PayloadAsJObject.ToString(Formatting.None); | ||
} | ||
|
||
public static Dictionary<string, object> PayloadDictionary | ||
{ | ||
get => PayloadAsJObject.ToObject<Dictionary<string, object>>(); | ||
} | ||
|
||
public static string Audience | ||
|