Skip to content

Commit

Permalink
Initial integration of new features.pkce structure
Browse files Browse the repository at this point in the history
  • Loading branch information
psmiraglia authored and panva committed Mar 26, 2018
1 parent 4b370bd commit 0061848
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lib/actions/authorization/check_pixy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const { InvalidRequestError } = require('../../helpers/errors');
const instance = require('../../helpers/weak_cache');

const ALLOWED = ['plain', 'S256'];

/*
* (optional[true]) assign default code_challenge_method if a code_challenge is provided
* (optional[true]) check presence of code code_challenge if code_challenge_method is provided
Expand All @@ -14,7 +12,7 @@ module.exports = (provider) => {
const { params } = ctx.oidc;

if (pkce && params.code_challenge_method) {
if (!ALLOWED.includes(params.code_challenge_method)) {
if (!pkce.supportedMethods.includes(params.code_challenge_method)) {
ctx.throw(new InvalidRequestError('not supported value of code_challenge_method'));
}

Expand All @@ -24,7 +22,11 @@ module.exports = (provider) => {
}

if (pkce && !params.code_challenge_method && params.code_challenge) {
params.code_challenge_method = 'plain';
if (pkce.supportedMethods.includes('plain')) {
params.code_challenge_method = 'plain';
} else {
params.code_challenge_method = 'S256';
}
}

const forced = pkce &&
Expand Down
3 changes: 2 additions & 1 deletion lib/actions/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ module.exports = function discoveryAction(provider) {
token_endpoint_auth_signing_alg_values_supported: config.tokenEndpointAuthSigningAlgValues,
userinfo_endpoint: ctx.oidc.urlFor('userinfo'),
userinfo_signing_alg_values_supported: config.userinfoSigningAlgValues,
code_challenge_methods_supported: config.features.pkce ? ['plain', 'S256'] : undefined,
code_challenge_methods_supported: config.features.pkce ?
config.features.pkce.supportedMethods : undefined,
};

if (config.features.introspection) {
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/configuration_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module.exports = class ConfigurationSchema {
});

if (get(this, 'features.oauthNativeApps')) {
set(this, 'features.pkce', { forcedForNative: true });
set(this, 'features.pkce.forcedForNative', true);
}

if (get(this, 'features.requestUri') === true) {
Expand Down
8 changes: 7 additions & 1 deletion lib/helpers/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ const DEFAULTS = {
discovery: true,
requestUri: true,
oauthNativeApps: true,
pkce: true,
pkce: {
forcedForNative: false,
supportedMethods: [
'plain',
'S256',
],
},

backchannelLogout: false,
frontchannelLogout: false,
Expand Down

0 comments on commit 0061848

Please sign in to comment.