Skip to content

Commit

Permalink
docs: update docs on useMtlsAlias
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Sep 16, 2024
1 parent bec0d40 commit 006db55
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 50 deletions.
47 changes: 22 additions & 25 deletions docs/variables/useMtlsAlias.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,43 @@ prioritize an endpoint URL present in
(Node.js) Using [nodejs/undici](https://github.com/nodejs/undici) for Mutual-TLS Client
Authentication and Certificate-Bound Access Tokens support.

```js
```ts
import * as undici from 'undici'
import * as oauth from 'oauth4webapi'

// Prerequisites
let as!: oauth.AuthorizationServer
let client!: oauth.Client
let params!: URLSearchParams
let key!: string // PEM-encoded key
let cert!: string // PEM-encoded certificate

const agent = new undici.Agent({ connect: { key, cert } })

const response = await oauth.pushedAuthorizationRequest(as, client, params, {
[oauth.useMtlsAlias]: true,
[oauth.customFetch]: (...args) => {
return undici.fetch(args[0], {
...args[1],
dispatcher: new undici.Agent({
connect: {
key: clientKey,
cert: clientCertificate,
},
}),
})
},
[oauth.customFetch]: (...args) => undici.fetch(args[0], { ...args[1], dispatcher: agent }),
})
```

(Deno) Using Deno.createHttpClient API for Mutual-TLS Client Authentication and Certificate-Bound
Access Tokens support. This is currently (Jan 2023) locked behind the --unstable command line
flag.
Access Tokens support.

```js
```ts
import * as oauth from 'oauth4webapi'

const agent = Deno.createHttpClient({
certChain: clientCertificate,
privateKey: clientKey,
})
// Prerequisites
let as!: oauth.AuthorizationServer
let client!: oauth.Client
let params!: URLSearchParams
let key!: string // PEM-encoded key
let cert!: string // PEM-encoded certificate

const agent = Deno.createHttpClient({ key, cert })

const response = await oauth.pushedAuthorizationRequest(as, client, params, {
[oauth.useMtlsAlias]: true,
[oauth.customFetch]: (...args) => {
return fetch(args[0], {
...args[1],
client: agent,
})
},
[oauth.customFetch]: (...args) => fetch(args[0], { ...args[1], client: agent }),
})
```

Expand Down
47 changes: 22 additions & 25 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,48 +397,45 @@ export const jwksCache: unique symbol = Symbol()
* (Node.js) Using [nodejs/undici](https://github.com/nodejs/undici) for Mutual-TLS Client
* Authentication and Certificate-Bound Access Tokens support.
*
* ```js
* ```ts
* import * as undici from 'undici'
* import * as oauth from 'oauth4webapi'
*
* // Prerequisites
* let as!: oauth.AuthorizationServer
* let client!: oauth.Client
* let params!: URLSearchParams
* let key!: string // PEM-encoded key
* let cert!: string // PEM-encoded certificate
*
* const agent = new undici.Agent({ connect: { key, cert } })
*
* const response = await oauth.pushedAuthorizationRequest(as, client, params, {
* [oauth.useMtlsAlias]: true,
* [oauth.customFetch]: (...args) => {
* return undici.fetch(args[0], {
* ...args[1],
* dispatcher: new undici.Agent({
* connect: {
* key: clientKey,
* cert: clientCertificate,
* },
* }),
* })
* },
* [oauth.customFetch]: (...args) => undici.fetch(args[0], { ...args[1], dispatcher: agent }),
* })
* ```
*
* @example
*
* (Deno) Using Deno.createHttpClient API for Mutual-TLS Client Authentication and Certificate-Bound
* Access Tokens support. This is currently (Jan 2023) locked behind the --unstable command line
* flag.
* Access Tokens support.
*
* ```js
* ```ts
* import * as oauth from 'oauth4webapi'
*
* const agent = Deno.createHttpClient({
* certChain: clientCertificate,
* privateKey: clientKey,
* })
* // Prerequisites
* let as!: oauth.AuthorizationServer
* let client!: oauth.Client
* let params!: URLSearchParams
* let key!: string // PEM-encoded key
* let cert!: string // PEM-encoded certificate
*
* const agent = Deno.createHttpClient({ key, cert })
*
* const response = await oauth.pushedAuthorizationRequest(as, client, params, {
* [oauth.useMtlsAlias]: true,
* [oauth.customFetch]: (...args) => {
* return fetch(args[0], {
* ...args[1],
* client: agent,
* })
* },
* [oauth.customFetch]: (...args) => fetch(args[0], { ...args[1], client: agent }),
* })
* ```
*
Expand Down

0 comments on commit 006db55

Please sign in to comment.