public void JsonDataRoundTrip() { var date = DateTime.UtcNow; var claims = new PasetoInstance { Issuer = "http://auth.example.com", Subject = "2986689", Audience = "audience", Expiration = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Kind).AddMinutes(10), NotBefore = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Kind).AddMinutes(-10), IssuedAt = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Kind), AdditionalClaims = new Dictionary <string, object> { ["roles"] = new[] { "Admin", "User" } }, Footer = new Dictionary <string, object> { ["kid"] = "dpm0" }, }; string token = PasetoUtility.Encrypt(_symmetricKey, claims); var parsedToken = PasetoUtility.Decrypt(_symmetricKey, token, validateTimes: true); Assert.Equal(claims.Issuer, parsedToken.Issuer); Assert.Equal(claims.Subject, parsedToken.Subject); Assert.Equal(claims.Audience, parsedToken.Audience); Assert.Equal(claims.Expiration, parsedToken.Expiration); Assert.Equal(claims.NotBefore, parsedToken.NotBefore); Assert.Equal(claims.IssuedAt, parsedToken.IssuedAt); Assert.Equal(claims.AdditionalClaims, parsedToken.AdditionalClaims); Assert.Equal(claims.Footer, parsedToken.Footer); }
public void FooterCanBeParsed() { string footerText = "Hello friend"; Assert.Equal(footerText, PasetoUtility.ParseFooter(PasetoUtility.EncryptBytes(_symmetricKey, new byte[0], footerText))); var footerJson = new Dictionary <string, object> { ["hello"] = "friend" }; Assert.Equal(footerJson, PasetoUtility.ParseFooterJson(PasetoUtility.Encrypt(_symmetricKey, new PasetoInstance { Footer = footerJson }))); }