Beispiel #1
0
        public IActionResult Post(AuthorizationGrantRequestDTO token)
        {
            AuthenticationDTO Authorization = new AuthenticationDTO();

            try
            {
                IAuthenticationService tm = new AuthenticationService(
                    _refreshService,
                    _configuration,
                    _tSLogger,
                    _tokenService,
                    _tokenServiceDbContext,
                    _encryptionService);
                Authorization = tm.Authenticate(token);
            }
            catch (InvalidUserException exUser)
            {
                return(Unauthorized(new UnauthorizedError(exUser.Message)));
            }
            catch (Exception ex)
            {
                return(Unauthorized(new UnauthorizedError(ex.Message)));
            }
            return(Ok(Authorization));
        }
        public AuthenticationDTO Authenticate(AuthorizationGrantRequestDTO authorizationGrantRequestDTO)
        {
            IAuthenticate authenticate;

            switch (authorizationGrantRequestDTO.Grant_Type)
            {
            case AuthorizationGrantType.authorization_code:
                authenticate = new AuthenticateCode(refreshtoken, config, Log, JWTToken, oauth, EncryptSvc);
                break;

            case AuthorizationGrantType.refresh_token:
                authenticate = new AuthenticateRefresh(refreshtoken, config, Log, JWTToken, oauth, EncryptSvc);
                break;

            case AuthorizationGrantType.password:
                authenticate = new AuthenticateUser(refreshtoken, config, Log, JWTToken, oauth, EncryptSvc);
                break;

            default:
                authenticate = new AuthenticateCode(refreshtoken, config, Log, JWTToken, oauth, EncryptSvc);
                break;
            }

            TokenDTO tokenDTO = mapper.Map <TokenDTO>(authorizationGrantRequestDTO);

            return(authenticate.AuthenticateGetToken(tokenDTO));
        }
        public void TestAuthenticateAccessTokenFromRefreshToken()
        {
            ITSLogger      log       = new TSLogger();
            AccessTokenDTO accessDTO = new AccessTokenDTO();
            AuthorizationGrantRequestDTO authorizationGrantRequestDTO = new AuthorizationGrantRequestDTO
            {
                Client_Id     = Guid.Parse("29bfd4b1-81c0-4db3-a615-4422d08f9792"),
                Code          = null,
                Grant_Type    = AuthorizationGrantType.refresh_token,
                UserName      = null,
                Scope         = null,
                Password      = null,
                Redirect_Uri  = null,
                Refresh_Token = HttpUtility.UrlEncode("pgsoAvSXD3xYPV+/pSAe3khYZWOFidHPxpltwNDP4Xw="),
                State         = null
            };
            IAuthenticationService tm = new AuthenticationService(new RefreshToken(), configuration, log, new JWTToken(log, new EncryptionService(), configuration), context, new EncryptionService());

            accessDTO.Authorization = accessDTO.Authorization = tm.Authenticate(authorizationGrantRequestDTO).access_token;
            TokenValidationService tokenValidationService = new TokenValidationService(new RefreshToken(), configuration, log, new JWTToken(log, new EncryptionService(), configuration), context, new EncryptionService());

            Assert.AreEqual(TokenConstants.ValidToken, tokenValidationService.VerifyToken(accessDTO));
        }