Ejemplo n.º 1
0
        public HttpResponseMessage ValidateToken([FromBody] tokenModel currentModel)
        {
            string          username  = null;
            ClaimsPrincipal principal = GetPrincipal(currentModel.token);

            if (principal == null)
            {
                return(null);
            }
            ClaimsIdentity identity = null;

            try
            {
                identity = (ClaimsIdentity)principal.Identity;
            }
            catch (NullReferenceException)
            {
                return(null);
            }
            Claim usernameClaim = identity.FindFirst(ClaimTypes.Name);

            username = usernameClaim.Value;

            return(Request.CreateResponse(HttpStatusCode.OK, username));
        }
Ejemplo n.º 2
0
        public bool ValidateToken(string authorizedToken, string userAgent)
        {
            bool result = false;

            try
            {
                string   key   = Encoding.UTF8.GetString(Convert.FromBase64String(authorizedToken));
                string[] parts = key.Split(new char[] { ':' });
                if (parts.Length == 5)
                {
                    objModel = new tokenModel()
                    {
                        clientToken = parts[0],
                        userid      = parts[1],
                        methodtype  = parts[2],
                        menuID      = parts[3],
                        companyID   = parts[4],
                        ip          = HostService.GetIP()
                    };

                    //compare token
                    string serverToken = generateToken(objModel.userid, objModel.methodtype, objModel.ip, userAgent);
                    if (objModel.clientToken == serverToken)
                    {
                        result = ValidateAuthorization(objModel.userid, objModel.methodtype, objModel.menuID, objModel.companyID);
                    }
                }
            }
            catch (Exception e)
            {
                e.ToString();
            }
            return(result);
        }
Ejemplo n.º 3
0
        public HttpResponseMessage UserLogin([FromBody] tokenModel currentModel)
        {
            string token = "";

            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
            if (NeeoUtility.IsPhoneNumberInInternationalFormat(currentModel.uID))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
            }
            if (!NeeoUtility.ValidatePhoneNumber(NeeoUtility.FormatAsIntlPhoneNumber(currentModel.uID)))
            {
                NeeoUtility.SetServiceResponseHeaders(CustomHttpStatusCode.InvalidNumber);
            }
            if (NeeoActivation.CheckUserAlreadyRegistered(currentModel.uID))
            {
                token = GenerateToken(currentModel.uID);
                return(Request.CreateResponse(HttpStatusCode.OK, token));
            }
            else
            {
                token = "-1";
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, token));
            }
        }