Exemplo n.º 1
0
        internal static string RefreshToken(string refresh_token)
        {
            var token = Storage.GetToken(refresh_token);

            if (token == null)
            {
                throw new AppException(HttpStatusCode.NotFound, $"refresh_token {refresh_token} not found");
            }
            var email = Jwt.DecodeToken(token.jwt);

            token = new Jwt.Token
            {
                jwt           = Jwt.GenerateToken(email),
                refresh_token = refresh_token
            };
            Storage.PutToken(token);
            return(token.jwt);
        }
Exemplo n.º 2
0
        internal static Jwt.Token Login(string email, string password)
        {
            var user = Storage.GetUser(email);

            if (user == null)
            {
                throw new AppException(HttpStatusCode.NotFound, $"user {email} not found");
            }
            if (password != user.password)
            {
                throw new AppException(HttpStatusCode.Unauthorized, "wrong password");
            }

            var token = new Jwt.Token
            {
                jwt           = Jwt.GenerateToken(email),
                refresh_token = Guid.NewGuid().ToString()
            };

            Storage.PutToken(token);
            return(token);
        }
Exemplo n.º 3
0
 internal static void PutToken(Jwt.Token token)
 {
     tokens[token.refresh_token] = token;
 }