Skip to content

Commit

Permalink
feat: allow overloading prototype for comparing client secrets
Browse files Browse the repository at this point in the history
resolves #631
  • Loading branch information
panva committed Jan 20, 2020
1 parent 2be3eeb commit eec36eb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
5 changes: 5 additions & 0 deletions lib/models/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const request = require('../helpers/request');
const nanoid = require('../helpers/nanoid');
const epochTime = require('../helpers/epoch_time');
const instance = require('../helpers/weak_cache');
const constantEquals = require('../helpers/constant_equals');
const { InvalidClient, InvalidClientMetadata } = require('../helpers/errors');
const getSchema = require('../helpers/client_schema');
const sectorIdentifier = require('../helpers/sector_identifier');
Expand Down Expand Up @@ -513,6 +514,10 @@ module.exports = function getClient(provider) {
|| (this.backchannelLogoutUri && this.backchannelLogoutSessionRequired);
}

compareClientSecret(actual) {
return constantEquals(this.clientSecret, actual, 1000);
}

checkClientSecretExpiration(message, errorOverride) {
if (!this.clientSecretExpiresAt) {
return;
Expand Down
7 changes: 4 additions & 3 deletions lib/shared/token_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const instance = require('../helpers/weak_cache');
const { 'x5t#S256': thumbprint } = require('../helpers/calculate_thumbprint');

const rejectDupes = require('./reject_dupes');
const tokenCredentialAuth = require('./token_credential_auth');
const getJWTAuthMiddleware = require('./token_jwt_auth');

const assertionType = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer';
Expand Down Expand Up @@ -172,9 +171,11 @@ module.exports = function tokenAuth(provider, endpoint, jwtAuthEndpointIdentifie
case 'client_secret_basic':
case 'client_secret_post': {
ctx.oidc.client.checkClientSecretExpiration('could not authenticate the client - its client secret is expired');
const expected = ctx.oidc.client.clientSecret;
const actual = params.client_secret || clientSecret;
tokenCredentialAuth(ctx, actual, expected);
const matches = await ctx.oidc.client.compareClientSecret(actual);
if (!matches) {
throw new InvalidClientAuth('invalid secret provided');
}

break;
}
Expand Down
8 changes: 0 additions & 8 deletions lib/shared/token_credential_auth.js

This file was deleted.

1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ declare class Client {
requestUriAllowed(requestUri: string): boolean;
postLogoutRedirectUriAllowed(postLogoutRedirectUri: string): boolean;
includeSid(): boolean;
compareClientSecret(actual: string): CanBePromise<boolean>;

metadata(): ClientMetadata;

Expand Down

0 comments on commit eec36eb

Please sign in to comment.