本文整理汇总了C#中IAuthSession.GetProfileUrl方法的典型用法代码示例。如果您正苦于以下问题:C# IAuthSession.GetProfileUrl方法的具体用法?C# IAuthSession.GetProfileUrl怎么用?C# IAuthSession.GetProfileUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAuthSession
的用法示例。
在下文中一共展示了IAuthSession.GetProfileUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateJwtPayload
public static JsonObject CreateJwtPayload(
IAuthSession session, string issuer, TimeSpan expireIn,
string audience=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()},
};
if (audience != null)
jwtPayload["aud"] = audience;
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 != AuthMetadataProvider.DefaultNoProfileImgUrl)
jwtPayload["picture"] = profileUrl;
var combinedRoles = new List<string>(session.Roles.Safe());
var combinedPerms = new List<string>(session.Permissions.Safe());
if (roles != null)
combinedRoles.AddRange(roles);
if (permissions != null)
combinedPerms.AddRange(permissions);
if (combinedRoles.Count > 0)
jwtPayload["roles"] = combinedRoles.ToJson();
if (combinedPerms.Count > 0)
jwtPayload["perms"] = combinedPerms.ToJson();
return jwtPayload;
}