public void Can_parse_svg_datauri() { var dataUri = Svg.GetDataUri(Svg.Icons.Male); var content = StaticContent.CreateFromDataUri(dataUri); Assert.That(content.MimeType, Is.EqualTo("image/svg+xml")); Assert.That(content.Data.FromUtf8().ToString(), Is.EqualTo(Svg.GetImage(Svg.Icons.Male))); }
public static JsonObject CreateJwtPayload( IAuthSession session, string issuer, TimeSpan expireIn, IEnumerable<string> audiences=null, IEnumerable<string> roles=null, IEnumerable<string> permissions =null) { var now = DateTime.UtcNow; var jwtPayload = new JsonObject { {"iss", issuer}, {"sub", session.UserAuthId}, {"iat", now.ToUnixTime().ToString()}, {"exp", now.Add(expireIn).ToUnixTime().ToString()}, }; jwtPayload.SetAudience(audiences?.ToList()); if (!string.IsNullOrEmpty(session.Email)) jwtPayload["email"] = session.Email; if (!string.IsNullOrEmpty(session.FirstName)) jwtPayload["given_name"] = session.FirstName; if (!string.IsNullOrEmpty(session.LastName)) jwtPayload["family_name"] = session.LastName; if (!string.IsNullOrEmpty(session.DisplayName)) jwtPayload["name"] = session.DisplayName; if (!string.IsNullOrEmpty(session.UserName)) jwtPayload["preferred_username"] = session.UserName; else if (!string.IsNullOrEmpty(session.UserAuthName) && !session.UserAuthName.Contains("@")) jwtPayload["preferred_username"] = session.UserAuthName; var profileUrl = session.GetProfileUrl(); if (profileUrl != null && profileUrl != Svg.GetDataUri(Svg.Icons.DefaultProfile)) jwtPayload["picture"] = profileUrl; var combinedRoles = new List<string>(session.Roles.Safe()); var combinedPerms = new List<string>(session.Permissions.Safe()); roles.Each(x => combinedRoles.AddIfNotExists(x)); permissions.Each(x => combinedPerms.AddIfNotExists(x)); if (combinedRoles.Count > 0) jwtPayload["roles"] = combinedRoles.ToJson(); if (combinedPerms.Count > 0) jwtPayload["perms"] = combinedPerms.ToJson(); return jwtPayload; }
public AuthMetadataProvider() { NoProfileImgUrl = Svg.GetDataUri(Svg.Icons.DefaultProfile); }
public static HtmlString SvgDataUri(this IHtmlHelper html, string name, string fillColor) => Svg.GetDataUri(name, fillColor).ToHtmlString();
public static HtmlString SvgDataUri(this IHtmlHelper html, string name) => Svg.GetDataUri(name).ToHtmlString();
public static JsonObject CreateJwtPayload( IAuthSession session, string issuer, TimeSpan expireIn, IEnumerable <string> audiences = null, IEnumerable <string> roles = null, IEnumerable <string> permissions = null) { var now = DateTime.UtcNow; var jwtPayload = new JsonObject { { "iss", issuer }, { "sub", session.UserAuthId }, { "iat", now.ToUnixTime().ToString() }, { "exp", now.Add(expireIn).ToUnixTime().ToString() }, }; jwtPayload.SetAudience(audiences?.ToList()); if (!string.IsNullOrEmpty(session.Email)) { jwtPayload["email"] = session.Email; } if (!string.IsNullOrEmpty(session.FirstName)) { jwtPayload["given_name"] = session.FirstName; } if (!string.IsNullOrEmpty(session.LastName)) { jwtPayload["family_name"] = session.LastName; } if (!string.IsNullOrEmpty(session.DisplayName)) { jwtPayload["name"] = session.DisplayName; } if (!string.IsNullOrEmpty(session.UserName)) { jwtPayload["preferred_username"] = session.UserName; } else if (!string.IsNullOrEmpty(session.UserAuthName) && !session.UserAuthName.Contains("@")) { jwtPayload["preferred_username"] = session.UserAuthName; } var profileUrl = session.GetProfileUrl(); if (profileUrl != null && profileUrl != Svg.GetDataUri(Svg.Icons.DefaultProfile)) { if (profileUrl.Length <= MaxProfileUrlSize) { jwtPayload["picture"] = profileUrl; } else { LogManager.GetLogger(typeof(JwtAuthProvider)).Warn($"User '{session.UserAuthId}' ProfileUrl exceeds max JWT Cookie size, using default profile"); jwtPayload["picture"] = HostContext.GetPlugin <AuthFeature>()?.ProfileImages?.RewriteImageUri(profileUrl); } } var combinedRoles = new List <string>(session.Roles.Safe()); var combinedPerms = new List <string>(session.Permissions.Safe()); roles.Each(x => combinedRoles.AddIfNotExists(x)); permissions.Each(x => combinedPerms.AddIfNotExists(x)); if (combinedRoles.Count > 0) { jwtPayload["roles"] = combinedRoles.ToJson(); } if (combinedPerms.Count > 0) { jwtPayload["perms"] = combinedPerms.ToJson(); } return(jwtPayload); }
public static string GetMetadataDebugTemplate() { return(LoadTemplate("MetadataDebug.html") .Replace("{{serviceStackLogoDataUriLight}}", Svg.Fill(Svg.GetDataUri(Svg.Logos.ServiceStack), Svg.LightColor))); }
public static string GetOperationControlTemplate() { return(LoadTemplate("OperationControl.html") .Replace("{{serviceStackLogoDataUriLight}}", Svg.Fill(Svg.GetDataUri(Svg.Logos.ServiceStack), Svg.LightColor))); }