-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add audiences to security token descriptor (#2575)
* added SecurityTokenDescriptor.Audiences and refactored code to support * refactored Audience vs Audiences logic * adjusted Audiences validation logic to more accurately evaluate for null or empty strings * Redesigned to avoid adding internal members and to support using both Audience and Audiences simultaneously * Fixed json formatting of audiences * Wrote unit tests for JsonWebTokenHandler jws and jwe * fixed bug in JwtSecurityTokenHandler * added test for audiences validation * added missing brackets * refactor WriteObject for readability and change IList case to IEnumerable * Add public method AddAudience for inexpensive deduplication when adding values * moved Audiences injection for JwtSecurityTokenHandler to the claims dictionary * added error msg * added unit tests ensuring same correct behavior for JwtSecurityTokenHandler and JsonWebTokenHandler * restoring existing note * samlv1 unit tests * saml2 unit tests * changed logic to avoid altering the claims object in the securityTokenDescriptor * added a couple more unit tests * private method renamed for accuracy * Added benchmarks to look at the performance of Audiences Vs Audience Members * removing use of 'collection expressions' as they don't work in ADO build * Redesigned Audiences to use IList * removing unneeded string * Add constructor overload to maintain public api * changed serializer back to using IList * removed unneeded using * re-adding enumerable to switch * reverting change to IList in jsonserializerprimitives * added a method to concat Audience and Audiences when writing to json * added duplicate check * changed _audiences private member to List<string> * Changed IEnumerable back to IList * altered logging logic to avoid unneeded alloc * removed Linq where from hotpath * formatting fixes/changes * Added UriKind.Absolute * removed extra space * Removed AddAudiences method * Added API taking multiple Audiences but not single one for completeness * added details on Aud claim priority to method summary * fixed bug and made variable names more clear * set up tests to track expected behavior * changed variables to original names * reverted changes to WriteObject * formatting changes * small changes from PR feedback * syntax fix * changed IsNullOrWhitespace to IsNullOrEmpty * reverted change to test since incepting code change was reverted * removed unnecessary code leftover from old solutions * replaced linq with foreach * added null check as a result of dropping Linq usage * fixing accidental comment edit * removed unnecessary local string * refactored to only create one list when making SamlAudienceRestrictionCondition * reduced list allocation from one to zero or one * removing duplicate methods * removed unneeded using * add note to features section in changelog * Changes per latest PR comments * adjusted logic to use local var since ICollection can't return last item without iterating through the entire collection * fixed which test was first in theory data
- Loading branch information
1 parent
c24bfe6
commit 55cc10e
Showing
19 changed files
with
792 additions
and
52 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
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 |
---|---|---|
|
@@ -16,6 +16,14 @@ public class BenchmarkUtils | |
|
||
public const string Audience = "http://www.contoso.com/protected"; | ||
|
||
public readonly static IList<string> Audiences = new string[] { | ||
"http://www.contoso.com/protected", | ||
"http://www.contoso.com/protected1", | ||
"http://www.contoso.com/protected2", | ||
"http://www.contoso.com/protected3", | ||
"http://www.contoso.com/protected4" | ||
}; | ||
|
||
private static RSA _rsa; | ||
private static SymmetricSecurityKey _symmetricKey; | ||
|
||
|
@@ -60,6 +68,43 @@ public static Dictionary<string, object> Claims | |
} | ||
} | ||
|
||
public static Dictionary<string, object> ClaimsNoAudience | ||
{ | ||
get | ||
{ | ||
DateTime now = DateTime.UtcNow; | ||
return new Dictionary<string, object>() | ||
{ | ||
{ "role", new List<string>() { "role1", "Developer", "Sales"} }, | ||
{ JwtRegisteredClaimNames.Email, "[email protected]" }, | ||
{ JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(now + TimeSpan.FromDays(1)) }, | ||
{ JwtRegisteredClaimNames.Nbf, EpochTime.GetIntDate(now) }, | ||
{ JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(now) }, | ||
{ JwtRegisteredClaimNames.GivenName, "Bob" }, | ||
{ JwtRegisteredClaimNames.Iss, Issuer }, | ||
}; | ||
} | ||
} | ||
|
||
public static Dictionary<string, object> ClaimsMultipleAudiences | ||
{ | ||
get | ||
{ | ||
DateTime now = DateTime.UtcNow; | ||
return new Dictionary<string, object>() | ||
{ | ||
{ "role", new List<string>() { "role1", "Developer", "Sales"} }, | ||
{ JwtRegisteredClaimNames.Email, "[email protected]" }, | ||
{ JwtRegisteredClaimNames.Exp, EpochTime.GetIntDate(now + TimeSpan.FromDays(1)) }, | ||
{ JwtRegisteredClaimNames.Nbf, EpochTime.GetIntDate(now) }, | ||
{ JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(now) }, | ||
{ JwtRegisteredClaimNames.GivenName, "Bob" }, | ||
{ JwtRegisteredClaimNames.Iss, Issuer }, | ||
{ JwtRegisteredClaimNames.Aud, Audiences } | ||
}; | ||
} | ||
} | ||
|
||
public static Dictionary<string, object> ClaimsExtendedExample | ||
{ | ||
get | ||
|
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
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
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
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
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
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
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
Oops, something went wrong.