Overrides ``requests.Session.request`` to provide basic access
        authentication.
427221
def request(self, method, url, **kwargs):
        
        auth = None
        if self._username is not None and self._password is not None:
            auth = (self._username, self._password)

        return super(BasicSession, self).request(
            method, url, auth=auth, **kwargs)
1359647
def _make_request(self, session=None):
        

        if session is None:
            session = NURESTSession.get_current_session()

        self._has_timeouted = False

        # Add specific headers
        controller = session.login_controller

        enterprise = controller.enterprise
        user_name = controller.user
        api_key = controller.api_key
        certificate = controller.certificate

        if self._root_object:
            enterprise = self._root_object.enterprise_name
            user_name = self._root_object.user_name
            api_key = self._root_object.api_key

        if self._uses_authentication:
            self._request.set_header('X-Nuage-Organization', enterprise)
            self._request.set_header('Authorization', controller.get_authentication_header(user_name, api_key))

        if controller.is_impersonating:
            self._request.set_header('X-Nuage-ProxyUser', controller.impersonation)

        headers = self._request.headers
        data = json.dumps(self._request.data)

        bambou_logger.info('> %s %s %s' % (self._request.method, self._request.url, self._request.params if self._request.params else ""))
        bambou_logger.debug('> headers: %s' % headers)
        bambou_logger.debug('> data:\n  %s' % json.dumps(self._request.data, indent=4))

        response = self.__make_request(requests_session=session.requests_session, method=self._request.method, url=self._request.url, params=self._request.params, data=data, headers=headers, certificate=certificate)

        retry_request = False

        if response.status_code == HTTP_CODE_MULTIPLE_CHOICES:
            self._request.url += '?responseChoice=1'
            bambou_logger.debug('Bambou got [%s] response. Trying to force response choice' % HTTP_CODE_MULTIPLE_CHOICES)
            retry_request = True

        elif response.status_code == HTTP_CODE_AUTHENTICATION_EXPIRED and session:
            bambou_logger.debug('Bambou got [%s] response . Trying to reconnect your session that has expired' % HTTP_CODE_AUTHENTICATION_EXPIRED)
            session.reset()
            session.start()
            retry_request = True

        if retry_request:
            response = self.__make_request(requests_session=session.requests_session, method=self._request.method, url=self._request.url, params=self._request.params, data=data, headers=headers, certificate=certificate)

        return self._did_receive_response(response)
96568
def authenticate(user=None):  # noqa: E501
    
    if connexion.request.is_json:
        user = UserAuth.from_dict(connexion.request.get_json())  # noqa: E501
    return 'do some magic!'
952560
def authenticate(self, request):
        
        auth = get_authorization_header(request).split()

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

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

        # Authenticate the user
        # The AdfsAuthCodeBackend authentication backend will notice the "access_token" parameter
        # and skip the request for an access token using the authorization code
        user = authenticate(access_token=auth[1])

        if user is None:
            raise exceptions.AuthenticationFailed('Invalid access token.')

        if not user.is_active:
            raise exceptions.AuthenticationFailed('User inactive or deleted.')

        return user, auth[1]
644249
def check_basic_auth(user, passwd):
    """"""

    auth = request.authorization
    return auth and auth.username == user and auth.password == passwd
1157699
def authenticate(self, request, username=None, password=None):
        
        if isinstance(username, basestring):
            username = username.encode('utf-8')

        if isinstance(password, basestring):
            password = password.encode('utf-8')

        server = self._get_server_from_settings()
        result = self._radius_auth(server, username, password)

        if result:
            return self.get_django_user(username, password)

        return None
1130411
def authenticate(self, request):
        
        authenticators = self._meta.authenticators

        if request.method == 'OPTIONS' and ADREST_ALLOW_OPTIONS:
            self.auth = AnonimousAuthenticator(self)
            return True

        error_message = "Authorization required."
        for authenticator in authenticators:
            auth = authenticator(self)
            try:
                if not auth.authenticate(request):
                    raise AssertionError(error_message)

                self.auth = auth
                auth.configure(request)
                return True
            except AssertionError, e:
                error_message = str(e)

        raise HttpError(error_message, status=status.HTTP_401_UNAUTHORIZED)
110560
def basic(request, response, verify_user, realm='simple', context=None, **kwargs):
    """"""
    http_auth = request.auth
    response.set_header('WWW-Authenticate', 'Basic')
    if http_auth is None:
        return

    if isinstance(http_auth, bytes):
        http_auth = http_auth.decode('utf8')
    try:
        auth_type, user_and_key = http_auth.split(' ', 1)
    except ValueError:
        raise HTTPUnauthorized('Authentication Error',
                               'Authentication header is improperly formed',
                               challenges=('Basic realm="{}"'.format(realm), ))

    if auth_type.lower() == 'basic':
        try:
            user_id, key = base64.decodebytes(bytes(user_and_key.strip(), 'utf8')).decode('utf8').split(':', 1)
            try:
                user = verify_user(user_id, key)
            except TypeError:
                user = verify_user(user_id, key, context)
            if user:
                response.set_header('WWW-Authenticate', '')
                return user
        except (binascii.Error, ValueError):
            raise HTTPUnauthorized('Authentication Error',
                                   'Unable to determine user and password with provided encoding',
                                   challenges=('Basic realm="{}"'.format(realm), ))
    return False
84314
def authenticate_user(self, request, user):
        
        return user.check_password(request.data.get('password')) or \
               self.check_user_token(request, user)
544988
def requires_basic_auth(func):
    
    @wraps(func)
    def auth_wrapper(self, *args, **kwargs):
        if hasattr(self, '_session') and self._session.auth:
            return func(self, *args, **kwargs)
        else:
            from .models import GitHubError
            # Mock a 401 response
            r = generate_fake_error_response(
                '{"message": "Requires username/password authentication"}'
            )
            raise GitHubError(r)
    return auth_wrapper
18152
def before_request(self) -> Optional[Response]:
        """"""
        auth = request.authorization
        if not auth or not self._check_auth(auth.username, auth.password):
            return Response(
                'Could not verify your access level for that URL.\n'
                'You have to login with proper credentials', 401,
                {'WWW-Authenticate': 'Basic realm="Login Required"'}
            )
        session['logged_in'] = auth.username
        # pylint wants this return statement
        return None
1170656
def raw_request(self, method, resource, access_token=None, **kwargs):
        
        headers = self._pop_headers(kwargs)
        headers['Authorization'] = self._get_authorization_header(access_token)
        url = self._get_resource_url(resource)
        return self.session.request(method, url, allow_redirects=True, headers=headers, **kwargs)
1218542
def authenticated(viewfunc):
    """"""
    @wraps(viewfunc)
    def wrapper(*args, **kwargs):
        ctx = stack.top
        if ctx and hasattr(ctx, 'htauth'):
            auth_header = request.headers.get('Authorization', None)
            if not auth_header:
                return _unauthorized_response()

            if not auth_header.startswith('Basic '):
                raise RuntimeError('Flask-HTAuth supports only Basic auth.')

            auth_header = auth_header.replace('Basic ', '')
            auth_header = base64.b64decode(auth_header)
            username, password = auth_header.split(':', 1)

            if not username in ctx.htauth['users']:
                return _unauthorized_response()

            if not check_password(password, ctx.htauth['users'][username]):
                return _unauthorized_response()

            g.htauth_user = username

        return viewfunc(*args, **kwargs)

    return wrapper
1207178
def set_basic_auth(self, username, password):
        
        from requests.auth import HTTPBasicAuth
        self.auth = HTTPBasicAuth(username, password)
        return self
356376
def _authenticate(self):
        """"""
        data = {'username': self.username,
                'password': self.password}
        url = '{base}/client/login'.format(base=self.base_url)
        response = self._session.get(url, params=data)
        print(response.text)
        data = response.json()
        if not data.get('success'):
            raise InvalidCredentials(data.get('reason', None))
        self._populate_info(data)
1151746
def send(self, request):
        ''''''
        return self.session.send(request(self.url, self.auth))
1024418
def _request(self, method, url, **kwargs):
        '''  '''
        self._ask_for_password()
        return request(method, url, user=self._user, password=self._password,
                       **kwargs)