Skip to content

Commit

Permalink
remove conginto auth flow
Browse files Browse the repository at this point in the history
zemberdotnet committed Oct 11, 2023

Verified

This commit was signed with the committer’s verified signature.
zemberdotnet Matthew Zember
1 parent 393d4fb commit 2b0c42a
Showing 6 changed files with 3,608 additions and 2,149 deletions.
26 changes: 18 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
const integrationConfig = require('@jupiterone/integration-sdk-dev-tools/config/jest');

module.exports = {
...integrationConfig,
preset: 'ts-jest',
testPathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/node_modules/'],
globals: {
'ts-jest': {
isolatedModules: true,
},
clearMocks: true,
restoreMocks: true,
testMatch: [
'<rootDir>/**/*.test.ts',
'!**/node_modules/*',
'!**/dist/*',
'!**/*.bak/*',
],
collectCoverage: false,
transform: {
'^.+\\.[tj]sx?$': [
'ts-jest',
{
isolatedModules: true,
},
],
},
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/node_modules/'],
};
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@
"dependencies": {
"@jupiterone/jupiterone-alert-rules": "^0.15.2",
"@lifeomic/attempt": "^3.0.0",
"amazon-cognito-identity-js-node": "^0.0.3",
"apollo-cache-inmemory": "^1.5.1",
"apollo-client": "^2.5.1",
"apollo-link": "^1.2.11",
@@ -55,7 +54,7 @@
"js-yaml": "^3.13.1",
"moment": "^2.22.2",
"mustache": "^2.3.0",
"node-fetch": "^2.6.0",
"node-fetch": "^2.6.7",
"p-all": "^2.1.0",
"p-map": "^1.2.0",
"pluralize": "^7.0.0",
@@ -64,7 +63,6 @@
"valid-url": "^1.0.9"
},
"devDependencies": {
"@jupiterone/integration-sdk-dev-tools": "^7.4.1",
"@pollyjs/adapter-node-http": "^2.7.0",
"@pollyjs/core": "^2.6.3",
"@types/bunyan": "^1.8.8",
6 changes: 5 additions & 1 deletion prettier.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
module.exports = require("@jupiterone/integration-sdk-dev-tools/config/prettier");
module.exports = {
proseWrap: 'always',
singleQuote: true,
};

3 changes: 0 additions & 3 deletions src/index.new.test.ts
Original file line number Diff line number Diff line change
@@ -41,9 +41,6 @@ describe('Core Index Tests', () => {
});

describe('Ensure JupiterOneClient Has Correct Props', () => {
test('authenticateUser', () => {
expect(j1).toHaveProperty('authenticateUser');
});
test('queryV1', () => {
expect(j1).toHaveProperty('queryV1');
});
28 changes: 2 additions & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Cognito from 'amazon-cognito-identity-js-node';

import { ApolloClient, ApolloError, QueryOptions } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloLink } from 'apollo-link';
@@ -293,7 +291,7 @@ export class JupiterOneClient {
password: string | undefined;
poolId: string;
clientId: string;
accessToken: string | undefined;
accessToken: string;
useRulesEndpoint: boolean;
apiUrl: string;
queryEndpoint: string;
@@ -337,8 +335,6 @@ export class JupiterOneClient {

async init(): Promise<JupiterOneClient> {
const token = this.accessToken
? this.accessToken
: await this.authenticateUser();
this.headers = {
Authorization: `Bearer ${token}`,
'LifeOmic-Account': this.account,
@@ -362,27 +358,7 @@ export class JupiterOneClient {
return this;
}

async authenticateUser() {
const authenticationDetails = new Cognito.AuthenticationDetails({
Username: this.username,
Password: this.password,
});
const Pool = new Cognito.CognitoUserPool({
UserPoolId: this.poolId,
ClientId: this.clientId,
});
const User = new Cognito.CognitoUser({ Username: this.username, Pool });

const result: any = await new Promise((resolve, reject) => {
User.authenticateUser(authenticationDetails, {
onSuccess: (result: any) => resolve(result),
onFailure: (err: any) => reject(err),
});
});

return result.getAccessToken().getJwtToken();
}


async queryV1(
j1ql: string,
options: QueryOptions | Record<string, unknown> = {},
5,690 changes: 3,582 additions & 2,108 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 2b0c42a

Please sign in to comment.