Authenticated requests
976092
def get(request_uri, params={})
      sp = signed_params("GET", request_uri, params)
      http_client.get(request_uri, sp)
    end
1006387
def _authenticate(self, request):
        

        def ensure_user_obj():
            """ Make sure that request object has user property.

            If `request.user` is not present or is `None`, it is
            created and initialized with `AnonymousUser`.
            """

            try:
                if request.user:
                    return
            except AttributeError:
                pass

            request.user = AnonymousUser()

        def anonymous_access(exc_obj):
            """ Determine what to do with unauthenticated requests.

            If the request has already been authenticated, does
            nothing.

            :param exc_obj: exception object to be thrown if anonymous
            access is not permitted.
            """

            if request.user and request.user.is_authenticated():
                # request is already authenticated
                pass
            elif self.allow_anonymous:
                request.user = AnonymousUser()
            else:
                raise exc_obj

        # first, make sure that the request carries `user` attribute
        ensure_user_obj()
        if self.authentication:
            # authentication handler is configured
            try:
                self.authentication.authenticate(request)
            except errors.Unauthorized, exc:
                # http request doesn't carry any authentication information
                anonymous_access(exc)
        else:
            # no authentication configured
            anonymous_access(errors.Forbidden())
84314
def authenticate_user(self, request, user):
        
        return user.check_password(request.data.get('password')) or \
               self.check_user_token(request, user)
1170777
def build_url_request(self):
        
        params = {}
        headers = {}
        self._authenticator(params, headers)
        self._grant(params)
        return Request(self._endpoint, urlencode(params), headers)
463049
def authenticated(function):
    """"""
    def wrapped(*args):
        """Wrap function."""
        try:
            return function(*args)
        except USPSError:
            _LOGGER.info("attempted to access page before login")
            _login(args[0])
            return function(*args)
    return wrapped
829060
def authenticate(self, username=None, password=None):
        
        data = api_client.authenticate(username, password)
        if not data:
            return

        return User(
            data.get('pk'), data.get('token'), data.get('user_data')
        )
325812
def authenticated(function):
    """"""
    def wrapped(*args):
        """Wrap function."""
        try:
            return function(*args)
        except FedexError:
            _login(*args)
            return function(*args)
    return wrapped
614001
def request(self,
                method,
                path,
                data=None,
                stream=False,
                headers=None,
                username=None,
                password=None,
                schema=None,
                **kwargs):
        
        if headers is None:
            headers = {}
        if 'Content-Length' not in headers:
            length = super_len(data)
            if length is not None:
                headers['Content-Length'] = length

        # Authentication credentials
        if username is not None:
            if 'Authorization' not in headers and username is not None:
                credentials = username + ':'
                if password is not None:
                    credentials += password
                headers['Authorization'] = 'Basic %s' % b64encode(credentials.encode('utf-8')).decode('utf-8')
            # For backwards compatibility with Crate <= 2.2
            if 'X-User' not in headers:
                headers['X-User'] = username

        if schema is not None:
            headers['Default-Schema'] = schema
        headers['Accept'] = 'application/json'
        headers['Content-Type'] = 'application/json'
        kwargs['assert_same_host'] = False
        kwargs['redirect'] = False
        kwargs['retries'] = Retry(read=0)
        return self.pool.urlopen(
            method,
            path,
            body=data,
            preload_content=not stream,
            headers=headers,
            **kwargs
        )
682500
def authenticateRequest(self, request, service_request, *args, **kwargs):
        
        username = password = None

        if 'Credentials' in request.headers:
            cred = request.headers['Credentials']

            username = cred['userid']
            password = cred['password']

        return self.gateway.authenticateRequest(service_request, username,
            password, *args, **kwargs)
1081404
def authenticate(self, request):
        
        auth_header = get_authorization_header(request).decode(HTTP_HEADER_ENCODING)
        auth = auth_header.split()

        if not auth or auth[0].lower() != 'bearer':
            return None

        if len(auth) == 1:
            msg = 'Invalid token header. No backend provided.'
            raise exceptions.AuthenticationFailed(msg)
        elif len(auth) == 2:
            msg = 'Invalid token header. No credentials provided.'
            raise exceptions.AuthenticationFailed(msg)
        elif len(auth) > 3:
            msg = 'Invalid token header. Token string should not contain spaces.'
            raise exceptions.AuthenticationFailed(msg)

        token = auth[2]
        backend = auth[1]

        strategy = load_strategy(request=request)

        try:
            backend = load_backend(strategy, backend, reverse(NAMESPACE + ":complete", args=(backend,)))
        except MissingBackend:
            msg = 'Invalid token header. Invalid backend.'
            raise exceptions.AuthenticationFailed(msg)

        try:
            user = backend.do_auth(access_token=token)
        except requests.HTTPError as e:
            msg = e.response.text
            raise exceptions.AuthenticationFailed(msg)

        if not user:
            msg = 'Bad credentials.'
            raise exceptions.AuthenticationFailed(msg)
        return user, token
1022717
def get_authenticate_header(self, request):
        
        authenticators = self.get_authenticators()
        if authenticators:
            return authenticators[0].authenticate_header(request)
252144
def authenticated_session(username, password):
    
    session = requests.Session()
    session.headers.update(headers())

    response = session.get(url())
    login_path = path(response.text)
    login_url = urljoin(response.url, login_path)
    login_post_data = post_data(response.text, username, password)

    response = session.post(login_url, data=login_post_data)
    if response.headers['connection'] == 'close':
        raise Exception('Authencation failed')

    return session
1244235
def authenticate(self):
        
        resp = self.session.get(self.api_url, auth=self.auth)
        resp = self._process_response(resp)
        return resp
865748
def authenticateRequest(self, service_request, username, password, **kwargs):
        
        authenticator = self.getAuthenticator(service_request)

        if self.logger:
            self.logger.debug('Authenticator expands to: %r' % authenticator)

        if authenticator is None:
            return defer.succeed(True)

        args = (username, password)

        if hasattr(authenticator, '_pyamf_expose_request'):
            http_request = kwargs.get('http_request', None)
            args = (http_request,) + args

        return defer.maybeDeferred(authenticator, *args)
746619
function authenticate(ctx) {
  var fn = lookup(ctx.operation, 'middleware', 'authenticate');
  var prefix = describe(ctx);

  if (fn) {
    return fn(ctx);
  } else {
    debug(prefix + 'authenticate middleware disabled (not defined)');
  }
}
1160210
def authenticated(function):
    """"""
    def wrapped(session, *args, **kwargs):
        """Wrap function."""
        try:
            return function(session, *args, **kwargs)
        except VooblyError:
            with session.cache_disabled():
                _LOGGER.info("attempted to access page before login")
                login(session)
                return function(session, *args, **kwargs)
    return wrapped
377460
def authenticate(self):
        """"""
        postdata = self.authentication_postdata
        jar = requests.cookies.cookielib.CookieJar()
        self.cookies = jar
        resp = self.get(self.authentication_base_url)
        authtok = _extract_authenticity_token(resp.content)
        if postdata is None:
            # This works for GitHub
            postdata = {"login": self.oauth2_username,
                        "password": self._oauth2_password,
                        "authenticity_token": authtok,
                        "commit": "Sign+in",
                        "utf8": u"\u2713",
                        }  # pylint: disable=bad-continuation
            self.authentication_postdata = postdata
        if self.authentication_session_url is None:
            # This is also for GitHub
            authentication_session_url = "https://github.com/session"
            self.authentication_session_url = authentication_session_url
        self.post(self.authentication_session_url, data=postdata)