Skip to content

Commit

Permalink
avoid querying unsupported models during introspection and revocation
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Jul 10, 2017
1 parent cf8982a commit c6136f1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
6 changes: 3 additions & 3 deletions lib/actions/authorization/check_scope.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const _ = require('lodash');
const { intersection, pull } = require('lodash');
const instance = require('../../helpers/weak_cache');
/*
* Validates that all requested scopes are supported by the provider, that openid is amongst them
Expand All @@ -7,7 +7,7 @@ const instance = require('../../helpers/weak_cache');
* @throws: invalid_request
*/
module.exports = provider => async function checkScope(ctx, next) {
const scopes = _.intersection(ctx.oidc.params.scope.split(' '), instance(provider).configuration('scopes'));
const scopes = intersection(ctx.oidc.params.scope.split(' '), instance(provider).configuration('scopes'));
const responseType = ctx.oidc.params.response_type;
const { prompts } = ctx.oidc;

Expand All @@ -21,7 +21,7 @@ module.exports = provider => async function checkScope(ctx, next) {

if (scopes.includes('offline_access')) {
if (!responseType.includes('code') || !prompts.includes('consent')) {
_.pull(scopes, 'offline_access').join(' ');
pull(scopes, 'offline_access').join(' ');
}
}

Expand Down
23 changes: 15 additions & 8 deletions lib/actions/introspection.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,30 @@ const instance = require('../helpers/weak_cache');

module.exports = function introspectionAction(provider) {
const Claims = mask(instance(provider).configuration());
const { grantTypeHandlers } = instance(provider);

function getAccessToken(token) {
return provider.AccessToken.find(token, {
ignoreExpiration: true,
});
}

function getClientCredentials(token) {
return provider.ClientCredentials.find(token, {
ignoreExpiration: true,
});
async function getClientCredentials(token) {
if (grantTypeHandlers.has('client_credentials')) {
return provider.ClientCredentials.find(token, {
ignoreExpiration: true,
});
}
return undefined;
}

function getRefreshToken(token) {
return provider.RefreshToken.find(token, {
ignoreExpiration: true,
});
async function getRefreshToken(token) {
if (grantTypeHandlers.has('refresh_token')) {
return provider.RefreshToken.find(token, {
ignoreExpiration: true,
});
}
return undefined;
}

function findResult(results) {
Expand Down
9 changes: 7 additions & 2 deletions lib/actions/revocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ const PARAM_LIST = new Set(['token', 'token_type_hint']);

const { InvalidRequestError } = require('../helpers/errors');
const presence = require('../helpers/validate_presence');
const instance = require('../helpers/weak_cache');
const authAndParams = require('../shared/chains/client_auth');

module.exports = function revocationAction(provider) {
const { grantTypeHandlers } = instance(provider);

function getAccessToken(token) {
return provider.AccessToken.find(token);
}

function getClientCredentials(token) {
async function getClientCredentials(token) {
if (!grantTypeHandlers.has('client_credentials')) return undefined;
return provider.ClientCredentials.find(token);
}

function getRefreshToken(token) {
async function getRefreshToken(token) {
if (!grantTypeHandlers.has('refresh_token')) return undefined;
return provider.RefreshToken.find(token);
}

Expand Down
2 changes: 1 addition & 1 deletion test/introspection/introspection.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const config = clone(require('../default.config'));

config.subjectTypes = ['public', 'pairwise'];
config.pairwiseSalt = 'foobar';
config.features = { introspection: true };
config.features = { introspection: true, clientCredentials: true };

module.exports = {
config,
Expand Down
2 changes: 1 addition & 1 deletion test/revocation/revocation.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { clone } = require('lodash');
const config = clone(require('../default.config'));

config.features = { revocation: true };
config.features = { revocation: true, clientCredentials: true };

module.exports = {
config,
Expand Down

0 comments on commit c6136f1

Please sign in to comment.