예제 #1
0
        public JsonResult RemoveAuthorizationToken(string refreshToken, string authHash)
        {
            //Create the response model
            MobileAppTokenErrorModel response = new MobileAppTokenErrorModel()
            {
                Success = false, Message = ""
            };

            /*---------------------------------Token Validation Begin-----------------------------------*/
            #region Validate the Token

            //Get the currentToken
            UnitOfWork     work         = new UnitOfWork();
            external_token currentToken = work.SystemRepository.GetAuthorizationTokenByRefresh(refreshToken);

            //Invalid token
            if (currentToken == null)
            {
                response.Message = GetTokenValidationResultMessage(TokenValidationResult.FailureInvalid);
                return(Json(response));
            }

            //Build the string to be hashed
            string salt         = currentToken.refresh_token;
            string paramString  = "refreshToken=" + refreshToken;
            string stringToHash = salt + "?" + paramString;

            //Invalid hash
            if (!ValidateHash(stringToHash, authHash))
            {
                response.Message = GetTokenValidationResultMessage(TokenValidationResult.FailureHash);
                return(Json(response));
            }
            #endregion
            /*----------------------------------Token Validation End------------------------------------*/

            //Remove the token from the database
            bool removed = work.SystemRepository.RemoveAuthorizationToken(refreshToken);

            //Populate the model's message
            if (removed)
            {
                response.Message = "Token Removed";
            }
            else
            {
                response.Message = "Unknown Error";
            }

            //Return
            return(Json(response));
        }
예제 #2
0
        public JsonResult ExpireAuthorizationToken(string token, string authHash)
        {
            /*---------------------------------Token Validation Begin-----------------------------------*/
            #region Validate the Token

            //Get the current token
            UnitOfWork     work         = new UnitOfWork();
            external_token currentToken = work.SystemRepository.GetAuthorizationToken(token);

            //Invalid token
            if (currentToken == null)
            {
                return(Json(new MobileAppTokenErrorModel()
                {
                    Success = false, Message = GetTokenValidationResultMessage(TokenValidationResult.FailureInvalid)
                }));
            }

            //Build the string to be hashed
            string salt         = currentToken.refresh_token;
            string paramString  = "token=" + token;
            string stringToHash = salt + "?" + paramString;

            //Invalid hash
            if (!ValidateHash(stringToHash, authHash))
            {
                return(Json(new MobileAppTokenErrorModel()
                {
                    Success = false, Message = GetTokenValidationResultMessage(TokenValidationResult.FailureHash)
                }));
            }

            #endregion
            /*----------------------------------Token Validation End------------------------------------*/

            //Expire the token
            bool expired = work.SystemRepository.ExpireAuthorizationToken(token);

            //Build the response
            MobileAppTokenErrorModel response = new MobileAppTokenErrorModel()
            {
                Success = expired, Message = "Unknown Error"
            };
            if (expired)
            {
                response.Message = "Token Expired";
            }

            //Return
            return(Json(response));
        }
        public JsonResult ExpireAuthorizationToken(string token, string authHash)
        {
            /*---------------------------------Token Validation Begin-----------------------------------*/
            #region Validate the Token

            //Get the current token
            UnitOfWork work = new UnitOfWork();
            external_token currentToken = work.SystemRepository.GetAuthorizationToken(token);

            //Invalid token
            if (currentToken == null)
                return Json(new MobileAppTokenErrorModel() { Success = false, Message = GetTokenValidationResultMessage(TokenValidationResult.FailureInvalid) });

            //Build the string to be hashed
            string salt = currentToken.refresh_token;
            string paramString = "token=" + token;
            string stringToHash = salt + "?" + paramString;

            //Invalid hash
            if (!ValidateHash(stringToHash, authHash))
                return Json(new MobileAppTokenErrorModel() { Success = false, Message = GetTokenValidationResultMessage(TokenValidationResult.FailureHash) });

            #endregion
            /*----------------------------------Token Validation End------------------------------------*/

            //Expire the token
            bool expired = work.SystemRepository.ExpireAuthorizationToken(token);

            //Build the response
            MobileAppTokenErrorModel response = new MobileAppTokenErrorModel() { Success = expired, Message = "Unknown Error" };
            if (expired)
                response.Message = "Token Expired";

            //Return
            return Json(response);
        }
        public JsonResult RemoveAuthorizationToken(string refreshToken, string authHash)
        {
            //Create the response model
            MobileAppTokenErrorModel response = new MobileAppTokenErrorModel() { Success = false, Message = "" };

            /*---------------------------------Token Validation Begin-----------------------------------*/
            #region Validate the Token

            //Get the currentToken
            UnitOfWork work = new UnitOfWork();
            external_token currentToken = work.SystemRepository.GetAuthorizationTokenByRefresh(refreshToken);

            //Invalid token
            if (currentToken == null)
            {
                response.Message = GetTokenValidationResultMessage(TokenValidationResult.FailureInvalid);
                return Json(response);
            }

            //Build the string to be hashed
            string salt = currentToken.refresh_token;
            string paramString = "refreshToken=" + refreshToken;
            string stringToHash = salt + "?" + paramString;

            //Invalid hash
            if (!ValidateHash(stringToHash, authHash))
            {
                response.Message = GetTokenValidationResultMessage(TokenValidationResult.FailureHash);
                return Json(response);
            }
            #endregion
            /*----------------------------------Token Validation End------------------------------------*/

            //Remove the token from the database
            bool removed = work.SystemRepository.RemoveAuthorizationToken(refreshToken);

            //Populate the model's message
            if (removed)
                response.Message = "Token Removed";
            else
                response.Message = "Unknown Error";

            //Return
            return Json(response);
        }