Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add global requestTimeoutInSeconds setting to OidcClientSettings #1430

Merged
merged 10 commits into from
Jun 21, 2024

Conversation

dbfr3qs
Copy link
Contributor

@dbfr3qs dbfr3qs commented Mar 6, 2024

Closes #1414

This adds a requestTimeoutInSeconds setting. When this is defined, it applies a retry timeout to all fetch requests made to the authorization server (e.g. /token, /userinfo, /.well-known/openid-configuration) except for requests made with silentRequestTimeoutInSeconds (if it is defined).

So the logic goes

  1. requestTimeoutInSeconds is set -> all requests have the same timeout
  2. silentRequestTimeoutInSeconds is set -> only silent request have a specific timeout
  3. both are set -> all requests have the same timeout except silent requests are set to silentRequestTimeoutInSeconds

Checklist

  • This PR makes changes to the public API
  • I have included links for closing relevant issue numbers

src/OidcClientSettings.ts Outdated Show resolved Hide resolved
@pamapa
Copy link
Member

pamapa commented Mar 8, 2024

@Badisi Can you have a look at this?

Copy link

codecov bot commented Mar 8, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 80.49%. Comparing base (f0ad76e) to head (e4fe7c6).
Report is 11 commits behind head on main.

❗ Current head e4fe7c6 differs from pull request most recent head 2e19329. Consider uploading reports for the commit 2e19329 to get more accurate results

Files Patch % Lines
src/UserManager.ts 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1430      +/-   ##
==========================================
- Coverage   80.53%   80.49%   -0.04%     
==========================================
  Files          45       45              
  Lines        1731     1733       +2     
  Branches      344      345       +1     
==========================================
+ Hits         1394     1395       +1     
  Misses        299      299              
- Partials       38       39       +1     
Flag Coverage Δ
unittests 80.49% <87.50%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/UserManager.ts Outdated Show resolved Hide resolved
@Badisi
Copy link
Contributor

Badisi commented Mar 8, 2024

@dbfr3qs, thanks for the PR !

Note that when this is configured, it overrides the silentRequestTimeoutInSeconds used when retrieving refresh tokens

I would go with the opposite: silentRequestTimeoutInSeconds should override requestTimeoutInSeconds if it is also set. Otherwise I wouldn't be able to define a global timeout + a different one for silent request.

Either:

  1. requestTimeoutInSeconds is set -> all requests have the same timeout
  2. silentRequestTimeoutInSeconds is set -> only silent request have a specific timeout
  3. both are set -> all requests have the same timeout except silent request that have a different one

@Badisi
Copy link
Contributor

Badisi commented Mar 8, 2024

@Badisi Can you have a look at this?

I'm abroad right now, will be able to look into this in 2 weeks

@dbfr3qs
Copy link
Contributor Author

dbfr3qs commented Mar 10, 2024

@pamapa @Badisi Thankyou both for your excellent feedback. I've made the suggested changes to try and satisfy the rules described above, such that the silentRequestTimeoutInSeconds setting is not overridden by requestTimeoutInSeconds unless it is not defined:

Either:

  1. requestTimeoutInSeconds is set -> all requests have the same timeout
  2. silentRequestTimeoutInSeconds is set -> only silent request have a specific timeout
  3. both are set -> all requests have the same timeout except silent request that have a different one

However, there's a default setting for the silentRequestTimeoutInSeconds setting so the logic will likely not work unless silentRequestTimeoutInSeconds is intentionally set to undefined. Thoughts?

@pamapa
Copy link
Member

pamapa commented Mar 13, 2024

I would go with the opposite: silentRequestTimeoutInSeconds should override requestTimeoutInSeconds if it is also set. Otherwise I wouldn't be able to define a global timeout + a different one for silent request.

Makes sense! We can handle this also within UserManagerSettingsStore...

@dbfr3qs
Copy link
Contributor Author

dbfr3qs commented Apr 8, 2024

@pamapa @Badisi Thankyou both for your excellent feedback. I've made the suggested changes to try and satisfy the rules described above, such that the silentRequestTimeoutInSeconds setting is not overridden by requestTimeoutInSeconds unless it is not defined:

Either:

  1. requestTimeoutInSeconds is set -> all requests have the same timeout
  2. silentRequestTimeoutInSeconds is set -> only silent request have a specific timeout
  3. both are set -> all requests have the same timeout except silent request that have a different one

However, there's a default setting for the silentRequestTimeoutInSeconds setting so the logic will likely not work unless silentRequestTimeoutInSeconds is intentionally set to undefined. Thoughts?

Any thoughts on this @Badisi @pamapa ?

@pamapa
Copy link
Member

pamapa commented Apr 9, 2024

However, there's a default setting for the silentRequestTimeoutInSeconds setting so the logic will likely not work unless silentRequestTimeoutInSeconds is intentionally set to undefined. Thoughts?

True, silentRequestTimeoutInSeconds is set by default to 10s. In order to not break the existing behavior we can not leave it undefined.

Probably something like this within UserManagerSettingsStore should work:

 this.requestTimeoutInSeconds = requestTimeoutInSeconds;
 this.silentRequestTimeoutInSeconds = silentRequestTimeoutInSeconds ? silentRequestTimeoutInSeconds
   : requestTimeoutInSeconds ? requestTimeoutInSeconds
   : DefaultSilentRequestTimeoutInSeconds;

@dbfr3qs
Copy link
Contributor Author

dbfr3qs commented May 1, 2024

Let me know if this does the trick @pamapa @Badisi 🙏

@pamapa
Copy link
Member

pamapa commented May 6, 2024

Looks good to me. @Badisi What do you think?

@pamapa pamapa added this to the 3.1.0 milestone May 6, 2024
@pamapa pamapa merged commit 4f55109 into authts:main Jun 21, 2024
2 checks passed
@pamapa
Copy link
Member

pamapa commented Jun 21, 2024

Thanks for contributing and being patient!

alexandresoro pushed a commit to alexandresoro/ouca that referenced this pull request Oct 6, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [oidc-client-ts](https://github.com/authts/oidc-client-ts) | dependencies | minor | [`3.0.1` -> `3.1.0`](https://renovatebot.com/diffs/npm/oidc-client-ts/3.0.1/3.1.0) |

---

### Release Notes

<details>
<summary>authts/oidc-client-ts (oidc-client-ts)</summary>

### [`v3.1.0`](https://github.com/authts/oidc-client-ts/releases/tag/v3.1.0)

[Compare Source](authts/oidc-client-ts@v3.0.1...v3.1.0)

oidc-client-ts v3.1.0 is a minor release.

No longer using `crypto-js` package, but built-in browser [crypto.subtle](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/subtle) module. Crypto.subtle is available only in [secure contexts](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts) (HTTPS). Also have a look into the [migration](https://github.com/authts/oidc-client-ts/blob/main/docs/migration.md) info.

#### Changelog:

-   Fixes:
    -   [#&#8203;1666](authts/oidc-client-ts#1666): fix link in docs to issue
    -   [#&#8203;1600](authts/oidc-client-ts#1600): updated docs about logger
    -   [#&#8203;1589](authts/oidc-client-ts#1589): fix compiler error for target=ES2022
    -   [#&#8203;1539](authts/oidc-client-ts#1539): fix small typo in `signinCallback` doc in UserManager.ts
    -   [#&#8203;1504](authts/oidc-client-ts#1504): typo in sample app config
    -   [#&#8203;1490](authts/oidc-client-ts#1490): fix the return type of `signinCallback`
    -   [#&#8203;1443](authts/oidc-client-ts#1443): fixes typos in docs
-   Features:
    -   [#&#8203;1672](authts/oidc-client-ts#1672): make `signoutCallback` return signout response if request_type is so:r
    -   [#&#8203;1626](authts/oidc-client-ts#1626): add `popupSignal` property to `signinPopup` and `signoutPop`
    -   [#&#8203;1580](authts/oidc-client-ts#1580): add dpop docs
    -   [#&#8203;1569](authts/oidc-client-ts#1569): add dpop nonce support
    -   [#&#8203;1457](authts/oidc-client-ts#1457): add extra headers
    -   [#&#8203;1461](authts/oidc-client-ts#1461): add demonstrating proof of possession
    -   [#&#8203;1430](authts/oidc-client-ts#1430): add global `requestTimeoutInSeconds` setting
    -   [#&#8203;1405](authts/oidc-client-ts#1405): allow using default scopes from authorization server

thanks to [@&#8203;klues](https://github.com/klues), [@&#8203;smujmaiku](https://github.com/smujmaiku), [@&#8203;mftruso](https://github.com/mftruso), [@&#8203;peetck](https://github.com/peetck), [@&#8203;dbfr3qs](https://github.com/dbfr3qs), [@&#8203;mottykohn](https://github.com/mottykohn), [@&#8203;noshiro-pf](https://github.com/noshiro-pf), [@&#8203;dbfr3qs](https://github.com/dbfr3qs), [@&#8203;grjan7](https://github.com/grjan7) and [@&#8203;natergj](https://github.com/natergj)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4xMDkuMCIsInVwZGF0ZWRJblZlciI6IjM4LjEwOS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiXX0=-->

Reviewed-on: https://git.tristess.app/alexandresoro/ouca/pulls/191
Reviewed-by: Alexandre Soro <code@soro.dev>
Co-authored-by: renovate <renovate@git.tristess.app>
Co-committed-by: renovate <renovate@git.tristess.app>
alexandresoro pushed a commit to alexandresoro/ouca that referenced this pull request Oct 7, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [oidc-client-ts](https://github.com/authts/oidc-client-ts) | dependencies | minor | [`3.0.1` -> `3.1.0`](https://renovatebot.com/diffs/npm/oidc-client-ts/3.0.1/3.1.0) |

---

### Release Notes

<details>
<summary>authts/oidc-client-ts (oidc-client-ts)</summary>

### [`v3.1.0`](https://github.com/authts/oidc-client-ts/releases/tag/v3.1.0)

[Compare Source](authts/oidc-client-ts@v3.0.1...v3.1.0)

oidc-client-ts v3.1.0 is a minor release.

No longer using `crypto-js` package, but built-in browser [crypto.subtle](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/subtle) module. Crypto.subtle is available only in [secure contexts](https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts) (HTTPS). Also have a look into the [migration](https://github.com/authts/oidc-client-ts/blob/main/docs/migration.md) info.

#### Changelog:

-   Fixes:
    -   [#&#8203;1666](authts/oidc-client-ts#1666): fix link in docs to issue
    -   [#&#8203;1600](authts/oidc-client-ts#1600): updated docs about logger
    -   [#&#8203;1589](authts/oidc-client-ts#1589): fix compiler error for target=ES2022
    -   [#&#8203;1539](authts/oidc-client-ts#1539): fix small typo in `signinCallback` doc in UserManager.ts
    -   [#&#8203;1504](authts/oidc-client-ts#1504): typo in sample app config
    -   [#&#8203;1490](authts/oidc-client-ts#1490): fix the return type of `signinCallback`
    -   [#&#8203;1443](authts/oidc-client-ts#1443): fixes typos in docs
-   Features:
    -   [#&#8203;1672](authts/oidc-client-ts#1672): make `signoutCallback` return signout response if request_type is so:r
    -   [#&#8203;1626](authts/oidc-client-ts#1626): add `popupSignal` property to `signinPopup` and `signoutPop`
    -   [#&#8203;1580](authts/oidc-client-ts#1580): add dpop docs
    -   [#&#8203;1569](authts/oidc-client-ts#1569): add dpop nonce support
    -   [#&#8203;1457](authts/oidc-client-ts#1457): add extra headers
    -   [#&#8203;1461](authts/oidc-client-ts#1461): add demonstrating proof of possession
    -   [#&#8203;1430](authts/oidc-client-ts#1430): add global `requestTimeoutInSeconds` setting
    -   [#&#8203;1405](authts/oidc-client-ts#1405): allow using default scopes from authorization server

thanks to [@&#8203;klues](https://github.com/klues), [@&#8203;smujmaiku](https://github.com/smujmaiku), [@&#8203;mftruso](https://github.com/mftruso), [@&#8203;peetck](https://github.com/peetck), [@&#8203;dbfr3qs](https://github.com/dbfr3qs), [@&#8203;mottykohn](https://github.com/mottykohn), [@&#8203;noshiro-pf](https://github.com/noshiro-pf), [@&#8203;dbfr3qs](https://github.com/dbfr3qs), [@&#8203;grjan7](https://github.com/grjan7) and [@&#8203;natergj](https://github.com/natergj)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4xMTAuMiIsInVwZGF0ZWRJblZlciI6IjM4LjExMC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiXX0=-->

Reviewed-on: https://git.tristess.app/alexandresoro/ouca/pulls/196
Reviewed-by: Alexandre Soro <code@soro.dev>
Co-authored-by: renovate <renovate@git.tristess.app>
Co-committed-by: renovate <renovate@git.tristess.app>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support to define JsonService timeout
3 participants