示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }