private bool TryGetPrincipal(string authHeader, out IPrincipal principal) { ApiToken token = GetToken(authHeader); if (token != null) // && token.AuthenticationTime) { CustomIdentity identity = new CustomIdentity(token.UserId, token.UserName, token.Timezone, token.Language, token.Roles, false); principal = new CustomPrincipal(identity); return(true); } principal = null; return(false); }
private ApiToken GetToken(string authHeader) { if (!string.IsNullOrEmpty(authHeader)) { string tokenText = RSAEncryption.Decrypt(authHeader); ApiToken token; if (ApiToken.TryParse(tokenText, out token)) { return(token); } } return(null); }
public static bool TryParse(string tokenString, out ApiToken token) { string[] parts = tokenString.Split('|'); if (parts.Length >= 6) { token = new ApiToken() { UserId = int.Parse(parts[0]), UserName = parts[1], Timezone = parts[2], Language = parts[3], //Roles = parts[4], AuthenticationTime = DateTime.Parse(parts[5]) }; return(true); } token = null; return(false); }