public ValidateToken ( System.IdentityModel.Tokens.SecurityToken token ) : ClaimsIdentityCollection | ||
token | System.IdentityModel.Tokens.SecurityToken | The token. |
return | ClaimsIdentityCollection |
static void Main(string[] args) { var handler = new AccessSecurityTokenHandler() { Configuration = new SecurityTokenHandlerConfiguration() }; ConfigureHandler(handler.Configuration); var token = CreateToken(handler); var tokenString = WriteToken(handler, token); Console.WriteLine(tokenString.ToString()); Console.WriteLine("\nFull Length : {0}", tokenString.Length); Console.WriteLine("Compressed Length: {0}\n", Compress(tokenString.ToString()).Length); var readToken = ReadToken(handler, tokenString.ToString()); var identities = handler.ValidateToken(readToken); ClaimsViewer.ShowConsole(new ClaimsPrincipal(identities)); TestHandlerCollection(tokenString); TestMalformedTokens(); TestCompressedToken(token); }
private static void TestMalformedTokens() { var expiredToken = File.ReadAllText("ExpiredToken.xml"); var tamperedToken = File.ReadAllText("TamperedToken.xml"); var handler = new AccessSecurityTokenHandler() { Configuration = new SecurityTokenHandlerConfiguration() }; ConfigureHandler(handler.Configuration); try { using (var reader = expiredToken.AsXmlReader(true)) { Console.WriteLine("\nReading expired token"); var readToken = handler.ReadToken(reader); handler.ValidateToken(readToken); } } catch (Exception ex) { Console.WriteLine(ex); } try { using (var reader = tamperedToken.AsXmlReader(true)) { Console.WriteLine("\nReading tampered token"); var readToken = handler.ReadToken(reader); handler.ValidateToken(readToken); } } catch (Exception ex) { Console.WriteLine(ex); } }