checks if companion is authorized to access a user's provider account.

@param {object} req
@param {object} res
336830
function authorized (req, res) {
  const { params, uppy } = req
  const providerName = params.providerName

  if (!uppy.providerTokens || !uppy.providerTokens[providerName]) {
    return res.json({ authenticated: false })
  }

  const token = uppy.providerTokens[providerName]
  uppy.provider.list({ token, uppy }, (err, response, body) => {
    const notAuthenticated = Boolean(err)
    if (notAuthenticated) {
      logger.debug(`${providerName} failed authorizarion test err:${err}`, 'provider.auth.check')
    }
    return res.json({ authenticated: !notAuthenticated })
  })
}
769815
function yourselfOnly(req, res, next) {
  // Get the username or sessionId from the URL
  var username = req.params.username;
  var sessionId = req.params.sessionId;

  if (!req.session) {
    res.status(401).send('You must be logged-in to access this resource');
  }
  else if (_.contains(req.session.user.roles, 'admin') ||
    (username && req.session.user.username === username) ||
    (sessionId && req.session.id === sessionId)) {
    next();
  }
  else {
    res.status(401).send('You can only perform this operation on your own account');
  }
}
193567
function ensureAuthenticated(req, res, next) {
  if (req.isAuthenticated()) {
    req.authClient = new googleapis.auth.OAuth2(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET);
    req.authClient.credentials = req.session.googleCredentials;
    return next();
  }
  res.redirect('/');
}
562742
function determineClientScope (req, res, next) {
  var params = req.connectParams
  var subject = req.client
  var scope = params.scope || subject.default_client_scope

  if (params.grant_type === 'client_credentials') {
    Scope.determine(scope, subject, function (err, scope, scopes) {
      if (err) { return next(err) }
      req.scope = scope
      req.scopes = scopes
      next()
    })
  } else {
    next()
  }
}
1009733
function authorizationRequest (req, options) {
  var provider = this.provider
  var endpoints = this.endpoints
  var config = this.client
  var url = URL.parse(endpoints.authorize.url)
  var responseType = 'code'
  var clientId = config.client_id
  var redirectUri = provider.redirect_uri
  var state = options.state

  // required authorization parameters
  url.query = {
    response_type: responseType,
    client_id: clientId,
    redirect_uri: redirectUri
  }

  // merge default and configured scopes
  if (provider.scope || config.scope) {
    var s1 = provider.scope || []
    var s2 = config.scope || []
    var sp = provider.separator || ' '

    url.query.scope = s1.concat(s2).join(sp)
  }

  if (state) {
    url.query.state = state
  }

  // Redirect to the provider. This method is
  // added at runtime by passport and not explicitly
  // defined here.
  this.redirect(URL.format(url))
}
29991
function getBearerToken (req, res, next) {
  // check for access token in the authorization header
  if (req.authorization.scheme && req.authorization.scheme.match(/Bearer/i)) {
    req.bearer = req.authorization.credentials
  }

  // check for access token in the query params
  if (req.query && req.query.access_token) {
    if (req.bearer) {
      return next(new UnauthorizedError({
        error: 'invalid_request',
        error_description: 'Multiple authentication methods',
        statusCode: 400
      }))
    }

    req.bearer = req.query.access_token
  }

  // check for access token in the request body
  if (req.body && req.body.access_token) {
    if (req.bearer) {
      return next(new UnauthorizedError({
        error: 'invalid_request',
        error_description: 'Multiple authentication methods',
        statusCode: 400
      }))
    }

    if (req.headers &&
      req.headers['content-type'] !== 'application/x-www-form-urlencoded') {
      return next(new UnauthorizedError({
        error: 'invalid_request',
        error_description: 'Invalid content-type',
        statusCode: 400
      }))
    }

    req.bearer = req.body.access_token
  }

  next()
}
513455
function (req,res,cfg) {
		if(!ipr.checkip(req,process.rapidcfg.ipallow)){return res.status(401).send({message:"error",error:"access allowed by IP"})}
		var ck = utils.checkadmpwd(req,process.rapidcfg.suser,process.rapidcfg.spwd);
		if (ck.message != "OK"){return res.send({error:ck.error})};
		if (!process.rapidcfg.mdb && req.params["0"] !== 'reload'){
			return res.status(404).send({error:"system not configured"})
		};
		/*console.log(req.params["0"]);
		console.log(req.body);
		console.log(req.query);
		console.log(req.method); */
		var fastr = req.params["0"];	
		if (typeof intc[fastr]=='function'){intc[fastr](req,res,cfg)} else {
			res.status(404).send({error:"service not implemented",service:fastr})}
	}
1165115
function (req, res) {
    User.findOne({ id: req.params.id }).exec(function (err, user) {
      if(err) return res.json({ err: err }, 500);
      else res.json(user);
    });
  }
803650
function appAuth(req, res, next){
  var apiKey = req.get('x-fh-auth-app');
  var envAccessKey = req.get('x-fh-env-access-key');

  log.logger.debug("Authenticating App ", apiKey, envAccessKey, req.params);

  if(!apiKey || !envAccessKey){
    res.status(401);
    return res.end();
  }

  appMiddleware.getMbaasApp({
    domain: req.params.domain,
    environment: req.params.environment,
    guid: req.params.appid,
    accessKey: envAccessKey,
    apiKey: apiKey
  }, function(err, mbaasApp){
    if(!mbaasApp){
      log.logger.debug("App Not Valid For Params ", apiKey, envAccessKey, req.params);
      return res.status(401).json({});
    }

    log.logger.debug("App Valid For Params ", apiKey, envAccessKey, req.params);
    req.appMbaasModel = mbaasApp;
    //Authorised, moving on.
    next();
  });
}
436601
def check_authorization(self, response):
        """"""
        if not hasattr(request, '_authorized'):
            raise Unauthorized
        elif not request._authorized:
            raise Unauthorized
        return response
1112106
def authorized(resp, remote):
    
    if resp and 'error' in resp:
        if resp['error'] == 'bad_verification_code':
            # See https://developer.github.com/v3/oauth/#bad-verification-code
            # which recommends starting auth flow again.
            return redirect(url_for('invenio_oauthclient.login',
                                    remote_app='github'))
        elif resp['error'] in ['incorrect_client_credentials',
                               'redirect_uri_mismatch']:
            raise OAuthResponseError(
                'Application mis-configuration in GitHub', remote, resp
            )

    return authorized_signup_handler(resp, remote)
1370338
function (req, res, next) {
    if (vulpejs.app.security.ignore) {
      exports.auth.checkAfter(req, res, next);
      return;
    }
    if (!req.cookies.appLanguage || req.cookies.appLanguage === 'undefined') {
      res.cookie('appLanguage', 'pt');
    }
    var skip = false;
    for (var i = 0, len = loginSkip.length; i < len; ++i) {
      var skipUri = vulpejs.app.root.context + loginSkip[i];
      if (skipUri === req.originalUrl || (skipUri !== '/' && req.originalUrl.indexOf(skipUri) === 0)) {
        skip = true;
        break;
      }
    }
    if (!req.isAuthenticated()) {
      if (!skip) {
        req.session['redirect-to'] = req.originalUrl;
        res.redirect(vulpejs.app.root.context + '/login');
        return;
      }
      exports.auth.checkAfter(req, res, next);
    } else {
      var roles = req.session['user-roles'];
      if (skip || !roles || roles.length === 0 || !vulpejs.app.security.routes || vulpejs.app.security.routes.length === 0) {
        exports.auth.checkAfter(req, res, next);
        return;
      }
      var hasRouteRoles = function (route) {
        if (route === '') {
          return false;
        }
        var roleExists = !route.roles || route.roles.length === 0;
        if (!roleExists) {
          for (var i = 0, len = roles.length; i < len; ++i) {
            if (route.roles.indexOf(roles[i]) !== -1) {
              roleExists = true;
              break;
            }
          }
        }
        return roleExists;
      };
      var routeWildcard = '';
      var requestedRoute = '';
      var roleExists = false;
      var routeExists = false;
      var routes = vulpejs.app.security.routes.length;
      var uriCheck = function (value) {
        return (value === '/' && req.originalUrl === value) || (value !== '/' && req.originalUrl.indexOf(value) === 0);
      };
      for (var i = 0; i < routes; ++i) {
        var route = vulpejs.app.security.routes[i];
        if (route.uris && Array.isArray(route.uris)) {
          for (var j = 0; j < route.uris.length; ++j) {
            if (uriCheck(route.uris[j])) {
              requestedRoute = route;
              break;
            }
          }
        } else if (route.uri === '/**') {
          routeWildcard = route;
        } else if (uriCheck(route.uri)) {
          requestedRoute = route;
        }
        if (requestedRoute) {
          break;
        }
      }
      if (((requestedRoute === '' && routeWildcard === '') || hasRouteRoles(requestedRoute)) || (routeWildcard !== '' && hasRouteRoles(routeWildcard))) {
        exports.auth.checkAfter(req, res, next);
      } else {
        res.status(403);
        exports.render(res, 'error', {
          ui: {
            controller: 'Error',
          },
          error: {
            status: 403,
            message: 'Forbidden',
          },
        });
      }
    }
  }
255456
async def is_user_authorized(self):
        
        if self._authorized is None:
            try:
                # Any request that requires authorization will work
                await self(functions.updates.GetStateRequest())
                self._authorized = True
            except errors.RPCError:
                self._authorized = False

        return self._authorized
1048412
function(req, user){
      req.session.authenticated = true;
      req.session.user = user;
    }
1365600
function (req, res) {
    User.find().exec(function (err, users) {
      if(err) return res.json({ err: err }, 500);
      else res.json(users);
    });
  }
1355851
protected boolean isAuthorizationRequest(final HttpServletRequest request, final HttpServletResponse response) {
        val requestPath = request.getRequestURI();
        return doesUriMatchPattern(requestPath, OAuth20Constants.AUTHORIZE_URL);
    }
686474
def authorized?(action, subject)
      policy = context.send :policy, subject
      ModuleUtils.try_to policy, normalize(action)
    end