Skip to content

Commit

Permalink
feat: include nbf in FAPIClient Request Objects
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Mar 10, 2021
1 parent a4c926a commit 0be56ba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
9 changes: 7 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@ Returns the `<Client>` class tied to this issuer.
#### `issuer.FAPIClient`

Returns the `<FAPIClient>` class tied to this issuer. `<FAPIClient>` inherits from `<Client>` and
adds necessary FAPI related checks. `s_hash` presence in authorization endpoint response ID Tokens
as well as authorization endpoint `iat` not being too far in the past (fixed to be 1 hour).
adds necessary FAPI behaviours:

- Returns: `<FAPIClient>`

The behaviours are:
- `s_hash` presence and value checks in authorization endpoint response ID Tokens
- authorization endpoint response ID Tokens `iat` must not be too far in the past (fixed to be
1 hour)
- Request Objects include `nbf` (with the same value as `iat`)

---

#### `issuer.metadata`
Expand Down
7 changes: 5 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1487,14 +1487,17 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base
let signed;
let key;

const fapi = this.constructor.name === 'FAPIClient';
const unix = now();
const header = { alg: signingAlgorithm, typ: 'oauth-authz-req+jwt' };
const payload = JSON.stringify(defaults({}, requestObject, {
iss: this.client_id,
aud: this.issuer.issuer,
client_id: this.client_id,
jti: random(),
iat: now(),
exp: now() + 300,
iat: unix,
exp: unix + 300,
...(fapi ? { nbf: unix } : undefined),
}));

if (signingAlgorithm === 'none') {
Expand Down
14 changes: 14 additions & 0 deletions test/client/client_instance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3891,6 +3891,20 @@ describe('Client', () => {
expect(err.message).to.eql('requestObject must be a plain object');
});
});

describe('FAPIClient', function () {
it('includes nbf by default', function () {
const client = new this.issuer.FAPIClient({ client_id: 'identifier', request_object_signing_alg: 'PS256' }, this.keystore.toJWKS(true));
return client.requestObject({})
.then((signed) => {
const { iat, exp, nbf } = JSON.parse(base64url.decode(signed.split('.')[1]));

expect(iat).to.be.ok;
expect(exp).to.eql(iat + 300);
expect(nbf).to.eql(iat);
});
});
});
});

describe('#requestObject (encryption when multiple keys match)', function () {
Expand Down

0 comments on commit 0be56ba

Please sign in to comment.