예제 #1
0
        public AuthenticationDTO AuthenticateGetToken(TokenDTO tokenDTO)
        {
            string          _refreshTokenold = HttpUtility.UrlDecode(tokenDTO.Refresh_Token);
            string          _refreshToken    = refreshtoken.GenerateToken(tokenDTO);
            RefreshTokenDTO refauth          = new RefreshTokenDTO {
                Authorization = _refreshTokenold
            };
            AuthenticationDTO auth = new AuthenticationDTO();

            try
            {
                //  ValidationResult results = refreshvalidation.Validate(refauth);
                Authorize authorize = oauth.Authorize.Where(x => x.Code == refauth.Authorization).FirstOrDefault();
                User      user      = oauth.User.SingleOrDefault(x => x.UserId == authorize.UserId);
                UserDTO   userDTO   = mapper.Map <UserDTO>(user);
                auth.token_type    = config["TokenType"];
                auth.access_token  = JWTToken.GenerateToken(tokenDTO);
                auth.refresh_token = HttpUtility.UrlEncode(_refreshToken);
                authorize.Code     = _refreshToken;
                oauth.SaveChanges();
            }
            catch (Exception ex)
            {
                Log.Log.Error(ex, TokenConstants.InvalidUser);
                throw new InvalidUserException(TokenConstants.InvalidUser);
            }
            return(auth);
        }
예제 #2
0
        public AuthenticationDTO AuthenticateGetToken(TokenDTO tokenDTO)
        {
            AuthenticationDTO auth = new AuthenticationDTO();

            try
            {
                //Authorize authorize = oauth.Authorize.Where(x => x.Code == refauth.Authorization).FirstOrDefault();
                UserLogin userLogin = new UserLogin(refreshtoken, config, Log, JWTToken, oauth, EncryptSvc);
                UserDTO   userDTO   = new UserDTO {
                    UserName = tokenDTO.UserName, password = tokenDTO.Password, Grant_Type = tokenDTO.Grant_Type
                };
                UserDTO userLoginDTO = userLogin.Login(userDTO);
                auth.token_type    = config["TokenType"];
                auth.access_token  = JWTToken.GenerateToken(tokenDTO);
                auth.refresh_token = HttpUtility.UrlEncode(refreshtoken.GenerateToken(tokenDTO));
            }
            catch (Exception ex)
            {
                Log.Log.Error(ex, TokenConstants.InvalidUser);
                throw new InvalidUserException(TokenConstants.InvalidUser);
            }
            return(auth);
        }
        public string Login()
        {
            string token = JWTToken.GenerateToken("140703", "140", "FaisalSiddique", "703", _appSettings.Secret);

            return("Bearer " + token);
        }