Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Aug 18, 2017
1 parent eac6fa7 commit 2de3c06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
6 changes: 3 additions & 3 deletions lib/actions/authorization/no_redirect_uri_clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* to be the requested redirect_uri and used as if it was explicitly provided;
*/
module.exports = async function noRedirectUriClients(ctx, next) {
const { oidc } = ctx;
const { params, client } = ctx.oidc;

if (oidc.params.redirect_uri === undefined && oidc.client.redirectUris.length === 1) {
oidc.params.redirect_uri = oidc.client.redirectUris[0];
if (params.redirect_uri === undefined && client.redirectUris.length === 1) {
params.redirect_uri = client.redirectUris[0];
}

await next();
Expand Down
26 changes: 9 additions & 17 deletions lib/actions/authorization/process_response_types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { get } = require('lodash');
const { InvalidRequestError } = require('../../helpers/errors');
const instance = require('../../helpers/weak_cache');

module.exports = (provider) => {
Expand Down Expand Up @@ -75,44 +74,37 @@ module.exports = (provider) => {
return { id_token: token };
}

function noneHandler() {
return {};
}

/*
* Resolves each requested response type to a single response object. If one of the hybrid
* response types is used an appropriate _hash is also pushed on to the id_token.
*/
return async function processResponseTypes(ctx) {
const responses = ctx.oidc.params.response_type.split(' ');
const out = Object.assign({}, ...await Promise.all(responses.map((responseType) => {
const res = Object.assign({}, ...await Promise.all(responses.map((responseType) => {
switch (responseType) {
case 'code':
return codeHandler(ctx);
case 'token':
return tokenHandler(ctx);
case 'id_token':
return idTokenHandler(ctx);
case 'none':
return noneHandler(ctx);
/* istanbul ignore next */
default:
throw new InvalidRequestError('not implemented', 501);
return {};
}
})));

if (out.access_token && out.id_token) {
out.id_token.set('at_hash', out.access_token);
if (res.access_token && res.id_token) {
res.id_token.set('at_hash', res.access_token);
}

if (out.code && out.id_token) {
out.id_token.set('c_hash', out.code);
if (res.code && res.id_token) {
res.id_token.set('c_hash', res.code);
}

if (out.id_token) {
out.id_token = await out.id_token.sign(ctx.oidc.client);
if (res.id_token) {
res.id_token = await res.id_token.sign(ctx.oidc.client);
}

return out;
return res;
};
};

0 comments on commit 2de3c06

Please sign in to comment.