Skip to content

Commit

Permalink
docs: move clockSkew and clockTolerance docs to the symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Jun 20, 2024
1 parent c0dc8f8 commit 3b5d2ea
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 94 deletions.
42 changes: 2 additions & 40 deletions docs/interfaces/Client.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,53 +42,15 @@ ___

`Optional` **[clockSkew]**: `number`

Use to adjust the client's assumed current time. Positive and negative finite values
representing seconds are allowed. Default is `0` (Date.now() + 0 seconds is used).

**`Example`**

When the client's local clock is mistakenly 1 hour in the past

```ts
const client: oauth.Client = {
client_id: 'abc4ba37-4ab8-49b5-99d4-9441ba35d428',
// ... other metadata
[oauth.clockSkew]: +(60 * 60),
}
```

**`Example`**

When the client's local clock is mistakenly 1 hour in the future

```ts
const client: oauth.Client = {
client_id: 'abc4ba37-4ab8-49b5-99d4-9441ba35d428',
// ... other metadata
[oauth.clockSkew]: -(60 * 60),
}
```
See [clockSkew](../variables/clockSkew.md).

___

### [clockTolerance]

`Optional` **[clockTolerance]**: `number`

Use to set allowed client's clock tolerance when checking DateTime JWT Claims. Only positive
finite values representing seconds are allowed. Default is `30` (30 seconds).

**`Example`**

Tolerate 30 seconds clock skew when validating JWT claims like exp or nbf.

```ts
const client: oauth.Client = {
client_id: 'abc4ba37-4ab8-49b5-99d4-9441ba35d428',
// ... other metadata
[oauth.clockTolerance]: 30,
}
```
See [clockTolerance](../variables/clockTolerance.md).

___

Expand Down
6 changes: 1 addition & 5 deletions docs/interfaces/ProtectedResourceRequestOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ ___

`Optional` **[clockSkew]**: `number`

Use to adjust the client's assumed current time. Positive and negative finite values
representing seconds are allowed. Default is `0` (Date.now() + 0 seconds is used).

This option only affects the request if the [DPoP](DPoPRequestOptions.md#dpop)
option is also used.
See [clockSkew](../variables/clockSkew.md).

___

Expand Down
4 changes: 2 additions & 2 deletions docs/interfaces/ValidateJWTAccessTokenOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

`Optional` **[clockSkew]**: `number`

Same functionality as in [Client](Client.md)
See [clockSkew](../variables/clockSkew.md).

___

### [clockTolerance]

`Optional` **[clockTolerance]**: `number`

Same functionality as in [Client](Client.md)
See [clockTolerance](../variables/clockTolerance.md).

___

Expand Down
27 changes: 27 additions & 0 deletions docs/variables/clockSkew.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,30 @@
[💗 Help the project](https://github.com/sponsors/panva)

`Const` **clockSkew**: unique `symbol`

Use to adjust the assumed current time. Positive and negative finite values representing seconds
are allowed. Default is `0` (Date.now() + 0 seconds is used).

**`Example`**

When the client's local clock is mistakenly 1 hour in the past

```ts
const client: oauth.Client = {
client_id: 'abc4ba37-4ab8-49b5-99d4-9441ba35d428',
// ... other metadata
[oauth.clockSkew]: +(60 * 60),
}
```

**`Example`**

When the client's local clock is mistakenly 1 hour in the future

```ts
const client: oauth.Client = {
client_id: 'abc4ba37-4ab8-49b5-99d4-9441ba35d428',
// ... other metadata
[oauth.clockSkew]: -(60 * 60),
}
```
15 changes: 15 additions & 0 deletions docs/variables/clockTolerance.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,18 @@
[💗 Help the project](https://github.com/sponsors/panva)

`Const` **clockTolerance**: unique `symbol`

Use to set allowed clock tolerance when checking DateTime JWT Claims. Only positive finite values
representing seconds are allowed. Default is `30` (30 seconds).

**`Example`**

Tolerate 30 seconds clock skew when validating JWT claims like exp or nbf.

```ts
const client: oauth.Client = {
client_id: 'abc4ba37-4ab8-49b5-99d4-9441ba35d428',
// ... other metadata
[oauth.clockTolerance]: 30,
}
```
97 changes: 50 additions & 47 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,52 @@ export interface JWK {
readonly [parameter: string]: JsonValue | undefined
}

/**
* Use to adjust the assumed current time. Positive and negative finite values representing seconds
* are allowed. Default is `0` (Date.now() + 0 seconds is used).
*
* @example
*
* When the client's local clock is mistakenly 1 hour in the past
*
* ```ts
* const client: oauth.Client = {
* client_id: 'abc4ba37-4ab8-49b5-99d4-9441ba35d428',
* // ... other metadata
* [oauth.clockSkew]: +(60 * 60),
* }
* ```
*
* @example
*
* When the client's local clock is mistakenly 1 hour in the future
*
* ```ts
* const client: oauth.Client = {
* client_id: 'abc4ba37-4ab8-49b5-99d4-9441ba35d428',
* // ... other metadata
* [oauth.clockSkew]: -(60 * 60),
* }
* ```
*/
export const clockSkew: unique symbol = Symbol()

/**
* Use to set allowed clock tolerance when checking DateTime JWT Claims. Only positive finite values
* representing seconds are allowed. Default is `30` (30 seconds).
*
* @example
*
* Tolerate 30 seconds clock skew when validating JWT claims like exp or nbf.
*
* ```ts
* const client: oauth.Client = {
* client_id: 'abc4ba37-4ab8-49b5-99d4-9441ba35d428',
* // ... other metadata
* [oauth.clockTolerance]: 30,
* }
* ```
*/
export const clockTolerance: unique symbol = Symbol()

/**
Expand Down Expand Up @@ -798,50 +843,12 @@ export interface Client {
default_max_age?: number

/**
* Use to adjust the client's assumed current time. Positive and negative finite values
* representing seconds are allowed. Default is `0` (Date.now() + 0 seconds is used).
*
* @example
*
* When the client's local clock is mistakenly 1 hour in the past
*
* ```ts
* const client: oauth.Client = {
* client_id: 'abc4ba37-4ab8-49b5-99d4-9441ba35d428',
* // ... other metadata
* [oauth.clockSkew]: +(60 * 60),
* }
* ```
*
* @example
*
* When the client's local clock is mistakenly 1 hour in the future
*
* ```ts
* const client: oauth.Client = {
* client_id: 'abc4ba37-4ab8-49b5-99d4-9441ba35d428',
* // ... other metadata
* [oauth.clockSkew]: -(60 * 60),
* }
* ```
* See {@link clockSkew}.
*/
[clockSkew]?: number

/**
* Use to set allowed client's clock tolerance when checking DateTime JWT Claims. Only positive
* finite values representing seconds are allowed. Default is `30` (30 seconds).
*
* @example
*
* Tolerate 30 seconds clock skew when validating JWT claims like exp or nbf.
*
* ```ts
* const client: oauth.Client = {
* client_id: 'abc4ba37-4ab8-49b5-99d4-9441ba35d428',
* // ... other metadata
* [oauth.clockTolerance]: 30,
* }
* ```
* See {@link clockTolerance}.
*/
[clockTolerance]?: number

Expand Down Expand Up @@ -2075,11 +2082,7 @@ export interface ProtectedResourceRequestOptions
extends Omit<HttpRequestOptions, 'headers'>,
DPoPRequestOptions {
/**
* Use to adjust the client's assumed current time. Positive and negative finite values
* representing seconds are allowed. Default is `0` (Date.now() + 0 seconds is used).
*
* This option only affects the request if the {@link ProtectedResourceRequestOptions.DPoP DPoP}
* option is also used.
* See {@link clockSkew}.
*/
[clockSkew]?: number
}
Expand Down Expand Up @@ -4424,12 +4427,12 @@ export interface ValidateJWTAccessTokenOptions extends HttpRequestOptions, JWKSC
requireDPoP?: boolean

/**
* Same functionality as in {@link Client}
* See {@link clockSkew}.
*/
[clockSkew]?: number

/**
* Same functionality as in {@link Client}
* See {@link clockTolerance}.
*/
[clockTolerance]?: number
}
Expand Down

0 comments on commit 3b5d2ea

Please sign in to comment.