<commit_before>import nJwt from 'njwt';
import Boom from 'boom';

export function scheme(server, options) {
  return {
    authenticate(request, reply) {
      const jwtResponse = request.query.jwtResponse;

      if (!jwtResponse) {
        const jwt = nJwt.create({
          iss: options.apiKeyId,
          sub: options.applicationHref,
          cb_uri: options.returnUrl,
          state: JSON.stringify(request.url.query)
        }, options.apiKeySecret);

        reply.redirect(`https://api.stormpath.com/sso?jwtRequest=${jwt.compact()}`);
      } else {
        nJwt.verify(jwtResponse, options.apiKeySecret, (err, verifiedJwt) => {
          if (err) {
            reply(Boom.wrap(err));
          } else if ('AUTHENTICATED' !== verifiedJwt.body.status) {
            reply(Boom.badImplementation(`The ID Site result of "${verifiedJwt.body.status}" was not AUTHENTICATED`));
          } else {
            reply.continue({
              credentials: {
                account: verifiedJwt.body.sub,
                next: JSON.parse(verifiedJwt.body.state).next
              }
            });
          }
        });
      }
    }
  };
}

export function register(server, options, next) {
  server.auth.scheme('stormpath', scheme);

  next();
}

register.attributes = {
  pkg: require('../package.json')
};
<commit_msg>fix(joi): re-enabled joi validations of plugin options<commit_after>import * as joi from 'joi';
import hoek from 'hoek';
import nJwt from 'njwt';
import Boom from 'boom';

function validate(options) {
  const validated = joi.validate(options, joi.object({
    applicationHref: joi.string().uri().required(),
    apiKeyId: joi.string().required(),
    apiKeySecret: joi.string().required(),
    returnUrl: joi.string().uri().required()
  }).required());

  hoek.assert(!validated.error, validated.error);

  return validated.value;
}

export function scheme(server, options) {
  const settings = validate(options);

  return {
    authenticate(request, reply) {
      const jwtResponse = request.query.jwtResponse;

      if (!jwtResponse) {
        const jwt = nJwt.create({
          iss: settings.apiKeyId,
          sub: settings.applicationHref,
          cb_uri: settings.returnUrl,
          state: JSON.stringify(request.url.query)
        }, settings.apiKeySecret);

        reply.redirect(`https://api.stormpath.com/sso?jwtRequest=${jwt.compact()}`);
      } else {
        nJwt.verify(jwtResponse, settings.apiKeySecret, (err, verifiedJwt) => {
          if (err) {
            reply(Boom.wrap(err));
          } else if ('AUTHENTICATED' !== verifiedJwt.body.status) {
            reply(Boom.badImplementation(`The ID Site result of "${verifiedJwt.body.status}" was not AUTHENTICATED`));
          } else {
            reply.continue({
              credentials: {
                account: verifiedJwt.body.sub,
                next: JSON.parse(verifiedJwt.body.state).next
              }
            });
          }
        });
      }
    }
  };
}

export function register(server, options, next) {
  server.auth.scheme('stormpath', scheme);

  next();
}

register.attributes = {
  pkg: require('../package.json')
};

{'fraction_non_alphanumeric': 0.13924050632911392, 'fraction_numerical': 0.0, 'mean_word_length': 2.4099244875943904, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1721345', 'n_tokens_mistral': 972, 'n_tokens_neox': 951, 'n_words': 181}