Skip to content

Commit

Permalink
Allow configured response_type to fuzzy match issuer response_type
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Jan 23, 2020
1 parent 44894ce commit 7deb960
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@ const telemetryHeader = {
}
};

function spacedStringsToAlphabetical(string) {
return string.split(' ').sort().join(' ');
}

async function get(config) {

const issuer = await Issuer.discover(config.issuerBaseURL);

const issuerTokenAlgs = Array.isArray(issuer.id_token_signing_alg_values_supported) ?
const issuerTokenAlgs = Array.isArray(issuer.id_token_signing_alg_values_supported) ?
issuer.id_token_signing_alg_values_supported : [];
if (!issuerTokenAlgs.includes(config.idTokenAlg)) {
throw new Error(
`ID token algorithm "${config.idTokenAlg}" is not supported by the issuer. ` +
`ID token algorithm "${config.idTokenAlg}" is not supported by the issuer. ` +
`Supported ID token algorithms are: "${issuerTokenAlgs.join('", "')}". `
);
}

const configRespType = config.authorizationParams.response_type;
const configRespType = spacedStringsToAlphabetical(config.authorizationParams.response_type);
const issuerRespTypes = Array.isArray(issuer.response_types_supported) ? issuer.response_types_supported : [];
issuerRespTypes.map(spacedStringsToAlphabetical);
if (!issuerRespTypes.includes(configRespType)) {
throw new Error(
`Response type "${configRespType}" is not supported by the issuer. ` +
`Response type "${configRespType}" is not supported by the issuer. ` +
`Supported response types are: "${issuerRespTypes.join('", "')}". `
);
}
Expand All @@ -38,7 +43,7 @@ async function get(config) {
const issuerRespModes = Array.isArray(issuer.response_modes_supported) ? issuer.response_modes_supported : [];
if (configRespMode && ! issuerRespModes.includes(configRespMode)) {
throw new Error(
`Response mode "${configRespMode}" is not supported by the issuer. ` +
`Response mode "${configRespMode}" is not supported by the issuer. ` +
`Supported response modes are "${issuerRespModes.join('", "')}". `
);
}
Expand Down
14 changes: 14 additions & 0 deletions test/config.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ describe('config', function() {
});
});

describe('when authorizationParams response_type fuzzy matches issuer', function() {
const customConfig = Object.assign({}, defaultConfig, {
clientSecret: '__test_client_secret__',
authorizationParams: {
response_type: 'token id_token code'
}
});
const config = getConfig(customConfig);

it('should keep token code', function() {
assert.equal(config.authorizationParams.response_type, 'token id_token code');
});
});

describe('with auth0Logout', function() {
const config = getConfig(Object.assign({}, defaultConfig, {auth0Logout: true}));

Expand Down

0 comments on commit 7deb960

Please sign in to comment.