How to use the base64url.substring function in base64url

To help you get started, we’ve selected a few base64url examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fabric8io / openshift-auth-proxy / lib / config.js View on Github external
// read in all the files with secrets, keys, certs
//
var files = {};
switch (config['auth-mode']) {
  case 'oauth2':
    // look for an oauth secret -- crash if not there
    files.oauthSecret = fs.readFileSync(config['oauth-secret'], 'utf8').
	                   replace(/(\n|\r)/gm,''); // newlines can mismatch secret
    try { // ok if missing, we will generate
      files.sessionSecret = fs.readFileSync(config['session-secret'], 'utf8');
    } catch(err) {
      console.error('error reading session secret: %s', JSON.stringify(err));
    } finally { // just ignore if the file is not there
      if (files.sessionSecret == null) {
        console.error('generating session secret (will not work with scaled service)');
        files.sessionSecret = require('base64url')(require('crypto').randomBytes(256)).substring(0, 256);
      }
    };
    // don't break, do both.
  case 'bearer': // and oauth2 as well:
    // ensure we validate connections to master w/ master CA.
    // technically this might not be required, but passport fails
    // silently if it *is* needed and is not present.
    var cas = https.globalAgent.options.ca || [];
    cas.push(fs.readFileSync(config['master-ca'], 'utf8'));
    https.globalAgent.options.ca = cas;
    break;
  case 'mutual_tls':
    try {
      files.mutualTlsCa = fs.readFileSync(config['mutual-tls-ca'], 'utf8');
    } catch(err) {
        throw 'No CA read for mutual TLS. Looked in: ' + config['mutual-tls-ca'];

base64url

For encoding to/from base64urls

MIT
Latest version published 6 years ago

Package Health Score

74 / 100
Full package analysis