Example #1
0
        public IActionResult GetAuthorizationToken([FromBody] GetToken_Credentials credentials)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //Authenticating User. Credentials and User info can be found in the configuration file...
                    var authRes = GetAuth.AuthenticateUser(credentials);

                    if (authRes.Key == true) //if authentication was successful, proceed to authorization...
                    {
                        var token = JWT_Auth.GetToken(authRes.Value);
                        return(Ok(token));
                    }
                    else
                    {
                        //User not found, or wrong credentials...
                        return(BadRequest(":( Wrong Credentials, or User doesn't exist. Please check them again."));
                    }
                }
                else
                {
                    //Model state is not valid, something is missing...
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception e)
            {
                return(StatusCode(500, e));
            }
        }
 public KeyValuePair <bool, string> AuthenticateUser(GetToken_Credentials credentials)
 {
     try
     {
         if (credentials.Email == _config["TestProfile_Info:User_Email"] && credentials.Password == _config["TestProfile_Info:User_Password"])
         {
             //Authentication Succesful. User Found, and returning true along with user's Id...
             var userEmail = _config["TestProfile_Info:User_Email"];
             return(new KeyValuePair <bool, string>(true, userEmail));
         }
         else if (credentials.Email == _config["MagkloProfile_Info:User_Email"] && credentials.Password == _config["MagkloProfile_Info:User_Password"])
         {
             //Authentication Succesful. User Found, and returning true along with user's Id...
             var userEmail = _config["MagkloProfile_Info:User_Email"];
             return(new KeyValuePair <bool, string>(true, userEmail));
         }
         else
         {
             //Authentication Faild. User Not Found Or Wrong Credentials were given. Returning false...
             return(new KeyValuePair <bool, string>(false, String.Empty));
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }