-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow to modify issued JWT headers and payloads before signing
- Loading branch information
Showing
9 changed files
with
282 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Interface: ModifyAssertionFunction() | ||
|
||
[💗 Help the project](https://github.com/sponsors/panva) | ||
|
||
Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by [becoming a sponsor](https://github.com/sponsors/panva). | ||
|
||
*** | ||
|
||
▸ **ModifyAssertionFunction**(`header`, `payload`): `void` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| ------ | ------ | ------ | | ||
| `header` | [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)\<`string`, `undefined` \| [`JsonValue`](../type-aliases/JsonValue.md)\> | JWS Header to modify right before it is signed. | | ||
| `payload` | [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)\<`string`, `undefined` \| [`JsonValue`](../type-aliases/JsonValue.md)\> | JWT Claims Set to modify right before it is signed. | | ||
|
||
## Returns | ||
|
||
`void` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Variable: modifyAssertion | ||
|
||
[💗 Help the project](https://github.com/sponsors/panva) | ||
|
||
Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by [becoming a sponsor](https://github.com/sponsors/panva). | ||
|
||
*** | ||
|
||
• `const` **modifyAssertion**: unique `symbol` | ||
|
||
Use to mutate JWT header and payload before they are signed. Its intended use is working around | ||
non-conform server behaviours, such as modifying JWT "aud" (audience) claims, or otherwise | ||
changing fixed claims used by this library. | ||
|
||
## Examples | ||
|
||
Changing Private Key JWT client assertion audience issued from an array to a string | ||
|
||
```ts | ||
import * as oauth from 'oauth4webapi' | ||
|
||
// Prerequisites | ||
let as!: oauth.AuthorizationServer | ||
let client!: oauth.Client | ||
let parameters!: URLSearchParams | ||
let clientPrivateKey!: CryptoKey | ||
|
||
const response = await oauth.pushedAuthorizationRequest(as, client, parameters, { | ||
clientPrivateKey: { | ||
key: clientPrivateKey, | ||
[oauth.modifyAssertion](header, payload) { | ||
payload.aud = as.issuer | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
Changing Request Object issued by [issueRequestObject](../functions/issueRequestObject.md) to have an expiration of 5 minutes | ||
|
||
```ts | ||
import * as oauth from 'oauth4webapi' | ||
|
||
// Prerequisites | ||
let as!: oauth.AuthorizationServer | ||
let client!: oauth.Client | ||
let parameters!: URLSearchParams | ||
let jarPrivateKey!: CryptoKey | ||
|
||
const request = await oauth.issueRequestObject(as, client, parameters, { | ||
key: jarPrivateKey, | ||
[oauth.modifyAssertion](header, payload) { | ||
payload.exp = <number>payload.iat + 300 | ||
}, | ||
}) | ||
``` |
Oops, something went wrong.