Skip to content

Commit

Permalink
fix: include DPoP Proof "htm" in requestResource if GET is defaulted to
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Sep 9, 2024
1 parent a917cb6 commit 23f7b49
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/helpers/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = async function request(options, { accessToken, mTLS = false, DP
opts.headers.DPoP = await this.dpopProof(
{
htu: `${url.origin}${url.pathname}`,
htm: options.method,
htm: options.method || 'GET',
nonce: nonces.get(nonceKey),
},
DPoP,
Expand Down
21 changes: 21 additions & 0 deletions test/client/dpop.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,27 @@ describe('DPoP', () => {
const proof = this.httpOpts.headers.DPoP;
const proofJWT = jose.decodeJwt(proof);
expect(proofJWT).to.have.property('ath');
expect(proofJWT).to.have.property('htm', 'POST');
});

it('includes htm when GET is defaulted to', async function () {
const { privateKey } = await jose.generateKeyPair('ES256', { extractable: true });
nock('https://rs.example.com')
.matchHeader('Transfer-Encoding', isUndefined)
.matchHeader('Content-Length', isUndefined)
.get('/resource')
.reply(200, { sub: 'foo' });

await this.client.requestResource('https://rs.example.com/resource', 'foo', {
DPoP: privateKey,
});

expect(this.httpOpts).to.have.nested.property('headers.DPoP');

const proof = this.httpOpts.headers.DPoP;
const proofJWT = jose.decodeJwt(proof);
expect(proofJWT).to.have.property('ath');
expect(proofJWT).to.have.property('htm', 'GET');
});

it('is enabled for grant', async function () {
Expand Down

0 comments on commit 23f7b49

Please sign in to comment.