public ServiceToken GetServiceToken(string userName, string domainName, string environmentName, string applicationName) { try { AuthenticationResponse authResponse = AuthenticationService.AuthenticateWithParams(userName, domainName, environmentName, applicationName); if (!authResponse.IsAuthenticated) { throw new UnauthorizedAPIException(authResponse.AuthenticationError.Message); } return(new ServiceToken( authenticationToken: authResponse.AuthenticationToken.ToString(), authenticatedOn: DateTime.Now, authenticationTokenExpiration: authResponse.AuthenticationTokenExpires )); } catch (Exception ex) { throw new UnauthorizedAPIException(ex.Message); } }