Exemplo n.º 1
0
        public ClaimsPrincipal ValidateToken(string securityToken, TokenValidationParameters validationParameters,
                                             out SecurityToken validatedToken)
        {
            var principal = tokenHandler.ValidateToken(securityToken, validationParameters, out validatedToken);

            var getTokenTask = Task.Run(() => userTokenService.GetByToken(securityToken));

            getTokenTask.Wait();

            var dbToken = getTokenTask.Result;

            if (dbToken == null || dbToken.Expiration < DateTime.UtcNow)
            {
                throw new AuthenticationException("Token is invalid or expired");
            }

            return(principal);
        }
Exemplo n.º 2
0
        public ApiResponseModel <List <Data.Entity.Auth> > GetAllByCurrentUser([FromBody] GetAllByCurrentUserRequestModel requestModel)
        {
            var responseModel = new ApiResponseModel <List <Data.Entity.Auth> >();

            try
            {
                // token bilgisinde ilgili user'ın profileid bilgisi elde edilir
                var userProfileId = _userTokenService.GetByToken(requestModel.UserToken).ProfileId;

                responseModel.Data                = _authService.GetAllByProfileId(userProfileId);
                responseModel.ResultStatusCode    = ResultStatusCodeStatic.Success;
                responseModel.ResultStatusMessage = "Success";
            }
            catch (Exception ex)
            {
                responseModel.ResultStatusCode    = ResultStatusCodeStatic.Error;
                responseModel.ResultStatusMessage = ex.Message;
            }
            return(responseModel);
        }
Exemplo n.º 3
0
        public ApiResponseModel <int> Logout([FromBody] LogoutRequestModel requestModel)
        {
            // token'ın geçerliliğinin sonlandırılması işlevidir.
            ApiResponseModel <int> responseModel = new ApiResponseModel <int>();

            // UserToken tablosundaki token'ın geçerliliği sonlandırılacak.
            UserToken userToken = _userTokenService.GetByToken(requestModel.UserToken);

            userToken.IsValid        = false;
            userToken.LogoutDateTime = DateTime.Now;
            int resultUpdateToken = _userTokenService.Update(userToken);

            if (resultUpdateToken <= 0)
            {
                responseModel.ResultStatusCode    = ResultStatusCodeStatic.Error;
                responseModel.ResultStatusMessage = "Failed To Terminate User Token";
                return(responseModel);
            }
            responseModel.Data             = resultUpdateToken;
            responseModel.ResultStatusCode = ResultStatusCodeStatic.Success;
            return(responseModel);
        }