Skip to content

Commit

Permalink
Increase timeout for openid client to 10s (3.5s before) (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 authored Sep 27, 2024
1 parent 926a36b commit da8e39c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 59 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ See [`src/example.ts`](./src/example.ts).
* Add Tests

## Changelog:

### __WORK IN PROGRESS__
* (Apollon77) Increase timeout for openid client to 10s (3.5s before)

### 2.4.0 (2024-07-17)
* (Apollon77) Allows to ignore the check if a state is writable on setData

Expand Down
123 changes: 71 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
},
"dependencies": {
"ip": "^2.0.1",
"openid-client": "^5.6.5"
"openid-client": "^5.7.0"
},
"devDependencies": {
"@alcalzone/release-script": "^3.8.0",
"@types/ip": "^1.1.3",
"@types/node": "^20.14.9",
"@types/node": "^22.7.4",
"pkg": "^5.8.1",
"typescript": "~5.5.4"
"typescript": "~5.6.2"
},
"repository": {
"type": "git",
Expand Down
12 changes: 8 additions & 4 deletions src/onecta/oidc-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IncomingMessage } from 'node:http';
import { readFile, writeFile } from 'node:fs/promises';
import { EventEmitter } from 'node:events';
import { randomBytes } from 'node:crypto';
import { BaseClient, TokenSet } from 'openid-client';
import { BaseClient, TokenSet, custom } from 'openid-client';
import {
OnectaOIDCScope,
OnectaAPIBaseUrl,
Expand All @@ -22,8 +22,12 @@ type RequestParameters = Parameters<typeof BaseClient.prototype.requestResource>

const ONE_DAY_S = 24 * 60 * 60;

custom.setHttpOptionsDefaults({
timeout: 10_000, // Default 3.5s is too less sometimes as it seems
});

export class OnectaClient {

#config: OnectaClientConfig;
#client: BaseClient;
#tokenSet: TokenSet | null;
Expand Down Expand Up @@ -51,7 +55,7 @@ export class OnectaClient {
if (!receiver || !redirectUri) {
throw new Error('Config params "customOidcCodeReceiver" and "oidcCallbackServerBaseUrl" are both required when using a custom OIDC authorization grant receiver');
}
const reqState = randomBytes(32).toString('hex');
const reqState = randomBytes(32).toString('hex');
const authUrl = this.#client.authorizationUrl({
scope: OnectaOIDCScope.basic,
state: reqState,
Expand All @@ -75,7 +79,7 @@ export class OnectaClient {

async #authorize(): Promise<TokenSet> {
const config = this.#config;
const { authCode, redirectUri } = config.customOidcCodeReceiver
const { authCode, redirectUri } = config.customOidcCodeReceiver
? await this.#getAuthCodeWithCustomReceiver() : await this.#getAuthCodeWithServer();
return await this.#client.grant({
grant_type: 'authorization_code',
Expand Down

0 comments on commit da8e39c

Please sign in to comment.