How to use the utility.randomString function in utility

To help you get started, we’ve selected a few utility 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 koajs / koa-github / index.js View on Github external
return function *githubAuth(next) {
    if (!this.session) {
      return this.throw('github auth need session', 500);
    }

    // first step: redirect to github
    if (this.path === options.signinPath) {
      var state = utility.randomString();
      var redirectUrl = 'https://github.com/login/oauth/authorize?';
      redirectUrl = util.format('%sclient_id=%s&redirect_uri=%s&scope=%s&state=%s',
        redirectUrl, options.clientID, options.callbackURL, options.scope, state);

      this.session._githubstate = state;

      //try to get the redirect url and set it to session
      try {
        var redirect = decodeURIComponent(urlParse(this.url, true).query[options.redirect] || '');
        if (redirect[0] === '/') {
          this.session._githubredirect = redirect;
          debug('get github callback redirect uri: %s', redirect);
        }
      } catch (err) {
        debug('decode redirect uri error');
      }
github cnpm / mirrors / controllers / dist.js View on Github external
function* downloadAsReadStream(key) {
  var options = { timeout: ms('10m') };
  if (nfs.createDownloadStream) {
    return yield nfs.createDownloadStream(key, options);
  }

  var tmpPath = path.join(config.uploadDir,
    utility.randomString() + key.replace(/\//g, '-'));
  function cleanup() {
    debug('cleanup %s', tmpPath);
    fs.unlink(tmpPath, utility.noop);
  }
  debug('downloadAsReadStream() %s to %s', key, tmpPath);
  try {
    yield nfs.download(key, tmpPath, options);
  } catch (err) {
    debug('downloadAsReadStream() %s to %s error: %s', key, tmpPath, err.stack);
    cleanup();
    throw err;
  }
  var tarball = fs.createReadStream(tmpPath);
  tarball.once('error', cleanup);
  tarball.once('end', cleanup);
  return tarball;
github cnpm / cnpmjs.org / controllers / utils.js View on Github external
exports.downloadAsReadStream = function* (key) {
  var options = { timeout: DOWNLOAD_TIMEOUT };
  if (nfs.createDownloadStream) {
    return yield nfs.createDownloadStream(key, options);
  }

  var tmpPath = path.join(config.uploadDir,
    utility.randomString() + key.replace(/\//g, '-'));
  var tarball;
  function cleanup() {
    debug('cleanup %s', tmpPath);
    rimraf(tmpPath, utility.noop);
    if (tarball) {
      tarball.destroy();
    }
  }
  debug('downloadAsReadStream() %s to %s', key, tmpPath);
  try {
    yield nfs.download(key, tmpPath, options);
  } catch (err) {
    debug('downloadAsReadStream() %s to %s error: %s', key, tmpPath, err.stack);
    cleanup();
    throw err;
  }
github apebook / apebook / router / github.js View on Github external
app.get('/github/sign',function *(){
        var state = utility.randomString();
        var query = this.request.query;
        var url = query.back;
        var redirectUrl = 'https://github.com/login/oauth/authorize?';
        redirectUrl = util.format('%sclient_id=%s&redirect_uri=%s&scope=%s&state=%s',url, options.clientID, options.callbackURL, options.scope, state);

        this.session._githubredirect = redirect;

        this.redirect(redirectUrl);
    })
};
github autoai-org / AID / components / discovery / src / service / github.ts View on Github external
public async finishAuth(code: string, redirectUrl: string) {
        const tokenUrl = 'https://github.com/login/oauth/access_token'
        return await Axios.post(tokenUrl, {
            client_id: this.id,
            client_secret: this.secret,
            code: code,
            redirectUrl: redirectUrl,
            grant_type: 'authorization_code',
            state: utility.randomString()
        }, {
            headers: {
                'Content-Type': 'application/json'
            }
        })
    }
}
github autoai-org / AID / components / discovery / src / service / github.ts View on Github external
public auth(redirectUrl: string, scope: string) {
        const state = utility.randomString()
        let formattedRedirectUrl = `https://github.com/login/oauth/authorize?client_id=${this.id}&redirect_uri=${redirectUrl}&scope=${scope}&state=${state}`
        return formattedRedirectUrl
    }
    public async finishAuth(code: string, redirectUrl: string) {