Exemplo n.º 1
0
        public async Task <string> Login(string email, string password)
        {
            if (!KeyUtils._isCreated)
            {
                KeyUtils.CreateKey();
            }
            Console.WriteLine("Verify Email: " + email);
            Console.WriteLine("Verify Password: "******"User Credential password: "******"$")[0]);
            var    pbkdf2 = new Rfc2898DeriveBytes(password, salt, 1000);
            string hash   = String.Concat(String.Concat(Convert.ToBase64String(salt), "$"), Convert.ToBase64String(pbkdf2.GetBytes(20)));

            Console.WriteLine("Verification Hash: " + hash);
            if (hash != null && hash != "" && hash.Equals(userCredential.passwordHash))
            {
                OnboardingUtility onboardingUtility = new OnboardingUtility();
                JsonObject        jwtHeader         = new JsonObject();
                jwtHeader.AppendString("alg", "RS256");
                jwtHeader.AppendString("typ", "JWT");
                JsonObject   claims = new JsonObject();
                Models.Agent agent  = await onboardingUtility.GetAgentDetails(email);

                claims.AppendString("organisationid", "1");
                claims.AppendString("agentid", agent.agentId.ToString());
                claims.AppendString("name", agent.name);
                claims.AppendString("organisationname", "Boeing");
                claims.AppendString("email", email);

                Jwt    jwt   = new Jwt();
                string token = jwt.CreateJwtPk(jwtHeader.Emit(), claims.Emit(), KeyUtils.GetPrivateKey());
                return(token);
            }
            throw new UnauthorizedAccessException();
        }