Skip to content

Commit

Permalink
refactor: make protectedResourceRequest headers argument optional
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Feb 7, 2024
1 parent da52311 commit bcbc872
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions conformance/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ export const green = (options?: MacroOptions) =>
access_token,
'GET',
new URL(accounts_endpoint),
new Headers(),
null,
undefined,
undefined,
{
...clientAuthOptions('resource'),
DPoP,
Expand Down
4 changes: 2 additions & 2 deletions docs/functions/protectedResourceRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[💗 Help the project](https://github.com/sponsors/panva)

**protectedResourceRequest**(`accessToken`, `method`, `url`, `headers`, `body?`, `options?`): [`Promise`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise )\<[`Response`]( https://developer.mozilla.org/docs/Web/API/Response )\>
**protectedResourceRequest**(`accessToken`, `method`, `url`, `headers?`, `body?`, `options?`): [`Promise`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise )\<[`Response`]( https://developer.mozilla.org/docs/Web/API/Response )\>

Performs a protected resource request at an arbitrary URL.

Expand All @@ -15,7 +15,7 @@ Authorization Header is used to transmit the Access Token value.
| `accessToken` | `string` | The Access Token for the request. |
| `method` | `string` | The HTTP method for the request. |
| `url` | [`URL`]( https://developer.mozilla.org/docs/Web/API/URL ) | Target URL for the request. |
| `headers` | [`Headers`]( https://developer.mozilla.org/docs/Web/API/Headers ) | Headers for the request. |
| `headers?` | [`Headers`]( https://developer.mozilla.org/docs/Web/API/Headers ) | Headers for the request. |
| `body?` | ``null`` \| `string` \| [`ArrayBuffer`]( https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer ) \| `ArrayBufferView` \| [`Blob`]( https://developer.mozilla.org/docs/Web/API/Blob ) \| [`FormData`]( https://developer.mozilla.org/docs/Web/API/FormData ) \| [`URLSearchParams`]( https://developer.mozilla.org/docs/Web/API/URLSearchParams ) \| [`ReadableStream`]( https://developer.mozilla.org/docs/Web/API/ReadableStream )\<`any`\> | Request body compatible with the Fetch API and the request's method. |
| `options?` | [`ProtectedResourceRequestOptions`](../interfaces/ProtectedResourceRequestOptions.md) | - |

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,7 @@ export async function protectedResourceRequest(
accessToken: string,
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | string,
url: URL,
headers: Headers,
headers?: Headers,
body?:
| ReadableStream
| Blob
Expand Down
2 changes: 1 addition & 1 deletion tap/end2end-device-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default (QUnit: QUnit) => {
access_token,
'GET',
new URL('http://localhost:3001/resource'),
new Headers(),
undefined,
undefined,
{
DPoP,
Expand Down
4 changes: 2 additions & 2 deletions tap/modulus_length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default async (QUnit: QUnit) => {
'accessToken',
'GET',
new URL('https://rs.example.com/api'),
new Headers(),
null,
undefined,
undefined,
{ DPoP: { privateKey, publicKey } },
),
(err: Error) => {
Expand Down
6 changes: 3 additions & 3 deletions test/dpop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test('dpop()', async (t) => {
.reply(200, '')

const url = new URL('https://rs.example.com/resource?foo#bar')
const response = await lib.protectedResourceRequest('token', 'GET', url, new Headers(), null, {
const response = await lib.protectedResourceRequest('token', 'GET', url, undefined, undefined, {
DPoP: sign,
})
t.true(response instanceof Response)
Expand All @@ -61,7 +61,7 @@ test('dpop() w/ a nonce', async (t) => {
.reply(401, '', { headers: { 'DPoP-Nonce': 'foo' } })

const url = new URL('https://rs2.example.com/resource?foo#bar')
await lib.protectedResourceRequest('token', 'GET', url, new Headers(), null, {
await lib.protectedResourceRequest('token', 'GET', url, undefined, undefined, {
DPoP: sign,
})

Expand All @@ -80,7 +80,7 @@ test('dpop() w/ a nonce', async (t) => {
})
.reply(200, '')

await lib.protectedResourceRequest('token', 'GET', url, new Headers(), null, {
await lib.protectedResourceRequest('token', 'GET', url, undefined, undefined, {
DPoP: sign,
})
})
2 changes: 1 addition & 1 deletion test/protected_resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ test('protectedResource()', async (t) => {
})
.reply(200, '')
const url = new URL('https://rs.example.com/resource')
const response = await lib.protectedResourceRequest('token', 'GET', url, new Headers(), null)
const response = await lib.protectedResourceRequest('token', 'GET', url)
t.true(response instanceof Response)
})

0 comments on commit bcbc872

Please sign in to comment.