How to use the basic-auth.parse function in basic-auth

To help you get started, we’ve selected a few basic-auth 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 chriswiggins / rtsp-streaming-server / src / lib / ClientServer.ts View on Github external
// Ask for authentication
    if (this.hooks.authentication) {
      if (!req.headers.authorization) {
        debug('%s:%s - No authentication information (required), sending 401', req.socket.remoteAddress, req.socket.remotePort);
        res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
        res.statusCode = 401;
        return false;
      } else {
        if (req.headers.session && this.clients[req.headers.session] && this.clients[req.headers.session].authorizationHeader !== req.headers.authorization) {
          debug('%s:%s - session header doesn\'t match the cached value, sending 401', req.socket.remoteAddress, req.socket.remotePort);
          res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
          res.statusCode = 401;
          return false;
        }

        const result = parse(req.headers.authorization);
        if (!result) {
          debug('%s:%s - No authentication information (required), sending 401', req.socket.remoteAddress, req.socket.remotePort);
          res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
          res.statusCode = 401;
          return false;
        }

        const allowed = await this.hooks.authentication(result.name, result.pass, req, res);
        if (!allowed) {
          debug('%s:%s - No authentication information (hook returned false), sending 401', req.socket.remoteAddress, req.socket.remotePort);
          res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
          res.statusCode = 401;
          return false;
        }
      }
    }
github replicatedhq / kots / kotsadm / api / src / controllers / kots / RestoreAPI.ts View on Github external
async putUndeployResult(
    @Req() request: Express.Request,
    @Res() response: Express.Response,
    @HeaderParams("Authorization") auth: string,
    @BodyParams("") body: any,
  ): Promise {
    const credentials: BasicAuth.Credentials = BasicAuth.parse(auth);

    let cluster;
    try {
      cluster = await (request.app.locals.stores.clusterStore as ClusterStore).getFromDeployToken(credentials.pass);
    } catch (err) {
      // TODO error type
      response.status(401);
      return {};
    }

    const status = body.is_error ? UndeployStatus.Failed : UndeployStatus.Completed;
    logger.info(`Restore API set RestoreUndeployStatus = ${status} for app ${body.app_id}`);
    const kotsAppStore = request.app.locals.stores.kotsAppStore as KotsAppStore;
    const app = await kotsAppStore.getApp(body.app_id);
    if (app.restoreInProgressName) {
      // Add a delay until we have logic to wait for all pods to be deleted.
github chriswiggins / rtsp-streaming-server / src / lib / PublishServer.ts View on Github external
async announceRequest (req: RtspRequest, res: RtspResponse) {
    debug('%s:%s - Announce request with headers %o', req.socket.remoteAddress, req.socket.remotePort, req.headers);
    // Ask for authentication
    if (this.hooks.authentication) {
      if (!req.headers.authorization) {
        debug('%s:%s - No authentication information (required), sending 401', req.socket.remoteAddress, req.socket.remotePort);
        res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
        res.statusCode = 401;
        return res.end();
      } else {
        const result = parse(req.headers.authorization);
        if (!result) {
          debug('%s:%s - Invalid authentication information (required), sending 401', req.socket.remoteAddress, req.socket.remotePort);
          res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
          res.statusCode = 401;
          return res.end();
        }

        const allowed = await this.hooks.authentication(result.name, result.pass, req, res);
        if (!allowed) {
          debug('%s:%s - Invalid authentication information (Hook returned false), sending 401', req.socket.remoteAddress, req.socket.remotePort);
          res.setHeader('WWW-Authenticate', 'Basic realm="rtsp"');
          res.statusCode = 401;
          return res.end();
        }

        this.authenticatedHeader = req.headers.authorization;
github replicatedhq / kots / kotsadm / api / src / controllers / kots / DeployAPI.ts View on Github external
async putDeployResult(
    @Req() request: Express.Request,
    @Res() response: Express.Response,
    @HeaderParams("Authorization") auth: string,
    @BodyParams("") body: any,
  ): Promise {
    const credentials: BasicAuth.Credentials = BasicAuth.parse(auth);

    let cluster;
    try {
      cluster = await request.app.locals.stores.clusterStore.getFromDeployToken(credentials.pass);
    } catch (err) {
      // TODO error type
      response.status(401);
      return {};
    }

    const output = {
      dryRun: {
        stderr: body.dryrun_stderr,
        stdout: body.dryrun_stdout,
      },
      apply: {
github replicatedhq / kots / kotsadm / api / src / controllers / kots / AppStatusAPI.ts View on Github external
async putAppStatus(
    @Req() request: Express.Request,
    @Res() response: Express.Response,
    @HeaderParams("Authorization") auth: string,
    @BodyParams("") body: any,
  ): Promise {
    const credentials: BasicAuth.Credentials = BasicAuth.parse(auth);

    try {
      await request.app.locals.stores.clusterStore.getFromDeployToken(credentials.pass);
    } catch (err) {
      // TODO error type
      response.status(401);
      return;
    }

    const kotsAppStatusStore: KotsAppStatusStore = request.app.locals.stores.kotsAppStatusStore;
    await kotsAppStatusStore.setKotsAppStatus(body.app_id, body.resource_states, body.updated_at);
    response.status(204);
  }
}
github replicatedhq / kots / kotsadm / api / src / controllers / kots / DeployAPI.ts View on Github external
async getDesiredState(
    @Req() request: Express.Request,
    @Res() response: Express.Response,
    @HeaderParams("Authorization") auth: string,
  ): Promise {
    const credentials: BasicAuth.Credentials = BasicAuth.parse(auth);

    let cluster;
    try {
      cluster = await request.app.locals.stores.clusterStore.getFromDeployToken(credentials.pass);
    } catch (err) {
      // TODO error type
      response.status(401);
      return {};
    }

    try {
      const apps = await request.app.locals.stores.kotsAppStore.listAppsForCluster(cluster.id);

      const present: any[] = [];
      const missing = {};
      let preflight = [];
github node-red / node-red / test / nodes / core / io / 21-httprequest_spec.js View on Github external
testProxyServer.on('proxyRes', function (proxyRes, req, res, options) {
                if (req.url == getTestURL('/proxyAuthenticate')){
                    var user = auth.parse(req.headers['proxy-authorization']);
                    if (!(user.name == "foouser" && user.pass == "barpassword")){
                        proxyRes.headers['proxy-authenticate'] = 'BASIC realm="test"';
                        proxyRes.statusCode = 407;
                    }
                }
            });
            testProxyServer.listen(testProxyPort);
github adonisjs / adonis-auth / src / Schemes / BasicAuth.js View on Github external
async check () {
    if (this.user) {
      return true
    }

    const authString = this._ctx.request.header('authorization') || this._ctx.request.input('basic')
    const credentials = auth.parse(authString)

    if (!credentials) {
      throw CE.InvalidBasicAuthException.invoke()
    }

    this.user = await this.validate(credentials.name, credentials.pass, true)
    return !!this.user
  }

basic-auth

node.js basic auth parser

MIT
Latest version published 6 years ago

Package Health Score

79 / 100
Full package analysis