Beispiel #1
0
        public IDataResult <AccessToken> CreateAccessToken(User user)
        {
            var claims      = _userService.GetClaims(user);
            var accessToken = _tokenHelper.CreateAccessToken(user, claims);

            return(new SuccessDataResult <AccessToken>(accessToken, Message.AccessTokenCreated));
        }
Beispiel #2
0
        public Result <AccessToken> CreateAccestoken(User user)
        {
            var claims      = userDAL.GetOperationClaims(user);
            var accessToken = _tokenHelper.CreateAccessToken(user, claims);

            return(new Result <AccessToken>(true, "basarili", accessToken));
        }
Beispiel #3
0
        public Result <AccessToken> CreateAccestoken(UserDTO user)
        {
            var userch      = userDAL.Get(w => w.Email == user.Email);
            var claims      = userDAL.GetOperationClaims(userch);
            var accessToken = _tokenHelper.CreateAccessToken(userch, claims);

            return(new Result <AccessToken>(true, "basarili", accessToken));
        }
Beispiel #4
0
        /// <summary>
        /// Creates and saves access and refresh token by email and password related user.
        /// </summary>
        /// <param name="email">User email</param>
        /// <param name="password">User password (must be hashed).</param>
        /// <returns><see cref="ObjectResponse{AccessToken}"/> that includes new <see cref="AccessToken"/>
        /// if success, error message otherwise.</returns>
        public async Task <ObjectResponse <AccessToken> > CreateTokenAsync(string email, string password)
        {
            ObjectResponse <User> userResponse = await _userService.FindFirstOrDefault(u => u.Email == email);

            if (userResponse.Success)
            {
                User user = userResponse.Object;
                if (user.PassWord != password)
                {
                    return(new ObjectResponse <AccessToken>(Constants.ErrorMessages.Auth.WrongPassword));
                }

                AccessToken token = _tokenHelper.CreateAccessToken(user);
                user.RefreshToken = token.RefreshToken;
                user.RefreshTokenExpirationDate = DateTime.Now.AddDays(_tokenHelper.GetTokenOptions().RefreshTokenExpiration);
                await _userService.UpdateAsync(user);

                return(new ObjectResponse <AccessToken>(token));
            }

            return(new ObjectResponse <AccessToken>(Constants.ErrorMessages.Auth.WrongEmail));
        }
Beispiel #5
0
        /*public IDataResult<AccessToken> CreateAccessToken(User user)
         * {
         *  /*Console.WriteLine(user.Id);
         *  Console.WriteLine(user.Status);
         *  Console.WriteLine(user.EMail);
         *  Console.WriteLine(user.FirstName);
         *  Console.WriteLine(user.LastName);
         *  Console.WriteLine(user.PasswordHash);
         *  Console.WriteLine(user.PasswordSalt);
         *  Console.WriteLine(user);#1#
         *  var result = _userService.GetUserOperationClaims(user);
         *
         *  var userOperationClaimDtoList = result.Data;
         *
         *  var operationClaimList =
         *      userOperationClaimDtoList.Select(userOperationClaimDto => new OperationClaim
         *      {
         *          Id = userOperationClaimDto.OperationClaimId,
         *          Name = userOperationClaimDto.OperationClaimName
         *      }).ToList();
         *
         *  var accessToken = _tokenHelper.CreateAccessToken(user, operationClaimList);
         *  return new SuccessDataResult<AccessToken>(Messages.AccessTokenCreated, accessToken);
         * }*/

        private AccessToken CreateAccessTokenMine(User user)
        {
            var result = _userService.GetUserOperationClaims(user);
            var userOperationClaimDtoList = result.Data;

            var operationClaimList =
                userOperationClaimDtoList.Select(userOperationClaimDto => new OperationClaim
            {
                Id   = userOperationClaimDto.OperationClaimId,
                Name = userOperationClaimDto.OperationClaimName
            }).ToList();

            var accessToken = _tokenHelper.CreateAccessToken(user, operationClaimList);

            return(accessToken);
        }
        public JsonResponses Get([FromQuery] AppToken appToken)
        {
            JsonResponses  responses = JsonResponses.Failed;
            UcUsersSetting ucUsers   = userSettingSdk.GetUserSettingInfo(appToken.UserNo);

            if (ucUsers == null)
            {
                responses.msg = LoginResultType.ERROR_USER_NOT_EXIST.ToString();
                return(JsonResponses.Failed);
            }
            if (!(ucUsers.AppSecret.Equals(appToken.AppSecret) && ucUsers.AppId.Equals(appToken.AppId)))
            {
                responses.msg = LoginResultType.ERROR_PASSWORD_TOO_MUCH.ToString();
                return(JsonResponses.Failed);
            }
            return(new JsonResponses(tokenHelper.CreateAccessToken(appToken)));
        }
Beispiel #7
0
 public IDataResult <AccessToken> CreateAccessToken(User user)
 {
     return(new SuccessDataResult <AccessToken>(Messages.AccessTokenCreated, _tokenHelper.CreateAccessToken(user)));
 }