diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index c86e570d..656e7171 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -1,22 +1,24 @@ name: Commitlint -on: [push, pull_request] +on: [pull_request] jobs: lint-commits: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 # Ensures commit history is fetched - name: Use Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: - node-version: '14' # Specify a Node.js version + node-version: '18' # Specify a Node.js version - name: Install dependencies run: npm install + env: + GH_NPM_TOKEN: ${{ secrets.GH_NPM_TOKEN }} - name: Lint last commit - run: npx commitlint --from=${{ github.event.pull_request.base.sha }} --to=${{ github.head_ref }} --verbose + run: npx commitlint --from=${{ github.event.pull_request.base.sha }} --to=${{ github.event.pull_request.head.sha }} --verbose diff --git a/.vscode/settings.json b/.vscode/settings.json index da2cb458..86078d8f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "conventionalCommits.scopes": [ - "repo" + "repo", + "oauth" ] } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index e1c4a251..31b01177 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27363,10 +27363,12 @@ "version": "8.3.0", "license": "Apache 2.0", "dependencies": { - "@types/debug": "^4.1.12", "debug": "^4.3.4", - "got": "^11.8.5", + "isomorphic-fetch": "^3.0.0", "neon-env": "^0.1.1" + }, + "devDependencies": { + "@types/debug": "^4.1.12" } }, "packages/oauth/node_modules/neon-env": { diff --git a/packages/oauth/package.json b/packages/oauth/package.json index 65949b02..5cc74cd0 100644 --- a/packages/oauth/package.json +++ b/packages/oauth/package.json @@ -25,9 +25,11 @@ }, "homepage": "https://github.com/camunda-community-hub/camunda-saas-oauth-nodejs#readme", "dependencies": { - "@types/debug": "^4.1.12", "debug": "^4.3.4", - "got": "^11.8.5", + "isomorphic-fetch": "^3.0.0", "neon-env": "^0.1.1" + }, + "devDependencies": { + "@types/debug": "^4.1.12" } } diff --git a/packages/oauth/src/__test__/OAuthImpl.spec.ts b/packages/oauth/src/__test__/OAuthImpl.spec.ts index 22caba82..b923b7cd 100644 --- a/packages/oauth/src/__test__/OAuthImpl.spec.ts +++ b/packages/oauth/src/__test__/OAuthImpl.spec.ts @@ -1,6 +1,7 @@ import http from 'http' import { OAuthProviderImpl } from '../lib/OAuthProviderImpl' +jest.setTimeout(10000) // Added test for https://github.com/camunda-community-hub/camunda-saas-oauth-nodejs/issues/8 // "Can not renew expired token" // Updated test for https://github.com/camunda-community-hub/camunda-8-js-sdk/issues/3 @@ -47,7 +48,6 @@ test('In-memory cache is populated and evicted after timeout', done => { await delay(1600) const token3 = await o.getToken('CONSOLE') expect(token3).toBe('1') - server.close() - done() + server.close(() => done()) }) }) diff --git a/packages/oauth/src/lib/OAuthProviderImpl.ts b/packages/oauth/src/lib/OAuthProviderImpl.ts index 3d61c302..5fcdb5c7 100644 --- a/packages/oauth/src/lib/OAuthProviderImpl.ts +++ b/packages/oauth/src/lib/OAuthProviderImpl.ts @@ -1,5 +1,5 @@ import * as fs from 'fs'; -import got from 'got'; +import 'isomorphic-fetch' import { Token, OAuthProviderConfig } from '../index'; import * as os from 'os' import { debug } from 'debug' @@ -102,33 +102,34 @@ export class OAuthProviderImpl { } private makeDebouncedTokenRequest(audience: TokenGrantAudiences) { - const form = { - audience: this.getAudience(audience), - client_id: this.clientId, - client_secret: this.clientSecret, - grant_type: 'client_credentials', - }; - - return got - .post(this.authServerUrl, { - form, + // const form = { + // audience: this.getAudience(audience), + // client_id: this.clientId, + // client_secret: this.clientSecret, + // grant_type: 'client_credentials', + // }; + + const body = `audience=${this.getAudience(audience)}&client_id=${this.clientId}&client_secret=${this.clientSecret}&grant_type=client_credentials` + return fetch(this.authServerUrl, { + method: 'POST', + body, headers: { 'content-type': 'application/x-www-form-urlencoded', 'user-agent': this.userAgentString, }, }) - .then(res => this.safeJSONParse(res.body) - .then(t => { - const token = {...t, audience} - if (this.useFileCache) { - this.sendToFileCache({ audience, token }); - } - this.sendToMemoryCache({ audience, token }) - trace(`Got token from endpoint: \n${token.access_token}`) - trace(`Token expires in ${token.expires_in} seconds`) - return token.access_token; - }) - ); + .then(res => res.json()) + // .then(res => this.safeJSONParse(res) + .then((t: any) => { + const token = {...t, audience} + if (this.useFileCache) { + this.sendToFileCache({ audience, token }); + } + this.sendToMemoryCache({ audience, token }) + trace(`Got token from endpoint: \n${token.access_token}`) + trace(`Token expires in ${token.expires_in} seconds`) + return token.access_token; + }) } private sendToMemoryCache({ audience, token }: { audience: TokenGrantAudiences; token: Token; }) { @@ -138,15 +139,18 @@ export class OAuthProviderImpl { this.tokenCache[key] = token; } - private safeJSONParse(thing: any): Promise { - return new Promise((resolve, reject) => { - try { - resolve(JSON.parse(thing)); - } catch (e) { - reject(e); - } - }); - } + // private safeJSONParse(thing: any): Promise { + // // tslint:disable-next-line: no-console + // console.log(thing); // @DEBUG + + // return new Promise((resolve, reject) => { + // try { + // resolve(JSON.parse(thing)); + // } catch (e) { + // reject(e); + // } + // }); + // } private retrieveFromFileCache(clientId: string, audience: TokenGrantAudiences) { let token: Token;