Returns user for credentials provided if credentials are valid.
        Returns ``None`` otherwise.
        
        :param request: HttpRequest instance
        :param credentials: keyword arguments
        :return: user object
485600
def authenticate(self, request, **credentials):
        
        username = credentials.get('username')
        password = credentials.get('password')
        login_server = credentials.get('login_server')
        port = credentials.get('port')

        user_model = get_user_model()
        try:
            user = user_model.objects.get(username=username)
        except user_model.DoesNotExist:
            return None
        try:
            response = poplib.POP3_SSL(host=login_server, port=port)
            response.user(user=username)
            password_string = response.pass_(pswd=password)
            if b'OK' in password_string:
                response.quit()
                return user
        except poplib.error_proto:
            return None
        except (ValueError, TypeError) as e:
            raise e
1285555
def retrieve_client_credentials(self):
        
        client_id = self.params.get('client_id')
        client_secret = self.params.get('client_secret')
        return (client_id, client_secret)
800753
def list_credentials(self, user=None):
        
        if not user:
            user = self.user
        user_id = utils.get_id(user)
        uri = "users/%s/OS-KSADM/credentials" % user_id
        resp, resp_body = self.method_get(uri)
        return resp_body.get("credentials")
1224077
def usernameFromRequest(request):
    
    username = request.args.get('username', [''])[0]
    if '@' not in username:
        username = '%s@%s' % (
            username, request.getHeader('host').split(':')[0])
    return username
553908
def callback(self, username, request):
        
        credentials = self._get_credentials(request)
        if credentials:
            username, api_key = credentials
            if self.check:
                return self.check(username, api_key, request)
868288
def authenticate_credentials(self, token: bytes, request=None):
        
        user = AuthToken.get_user_for_token(token)

        if user is None:
            raise AuthenticationFailed(_('Invalid auth token.'))

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

        return user, token
761462
def check_credentials(self, username, password):
        
        return password is not None and self.credentials.get(username, None) == password
406221
def get(self, request):
        

        if request.user.is_authenticated():
            return HttpResponseRedirect(self.get_next(request))

        try:
            user, profile, client = self.get_session_data(request)
        except KeyError:
            return self.error_to_response(request, dict(
                error=_("Social profile is missing from your session.")))
         
        if GENERATE_USERNAME:
            return self.generate_username_and_redirect(request, user, profile, client)
            
        form = self.get_form()(initial=self.get_initial_data(request, user, profile, client))
        
        additional_context = self.get_context(request, user, profile, client)
        return self.render_to_response(dict({'form': form}, **additional_context))
636707
def extract_credentials(self, url):
        
        if isinstance(url, urllib2.Request):
            result = urlparse.urlsplit(url.get_full_url())
        else:
            result = urlparse.urlsplit(url)
        scheme, netloc, path, query, frag = result

        username, password = self.parse_credentials(netloc)
        if username is None:
            return url, None, None
        elif password is None and self.prompting:
            # remove the auth credentials from the url part
            netloc = netloc.replace('%s@' % username, '', 1)
            # prompt for the password
            prompt = 'Password for %s@%s: ' % (username, netloc)
            password = urllib.quote(getpass.getpass(prompt))
        else:
            # remove the auth credentials from the url part
            netloc = netloc.replace('%s:%s@' % (username, password), '', 1)

        target_url = urlparse.urlunsplit((scheme, netloc, path, query, frag))
        return target_url, username, password
201713
def auth(context, request):
    

    if ploneapi.user.is_anonymous():
        request.response.setStatus(401)
        request.response.setHeader('WWW-Authenticate',
                                   'basic realm="JSONAPI AUTH"', 1)

    logger.info("*** BASIC AUTHENTICATE ***")
    return {}
743951
def get_user(request):
    
    if settings.LOCKDOWN and hasattr(request, 'user'):
        if request.user.is_authenticated:
            user = request.user.username
        else:
            # This may happen with crafted requests
            user = ''
    else:
        user = getattr(settings, 'DEFAULT_USER', getpass.getuser())

    return user
78645
def authenticate_credentials(self, payload):
        
        try:
            user_id = jwt_get_user_id_from_payload(payload)

            if user_id:
                user = User.objects.get(pk=user_id, is_active=True)
            else:
                msg = 'Invalid payload'
                raise exceptions.AuthenticationFailed(msg)
        except User.DoesNotExist:
            msg = 'Invalid signature'
            raise exceptions.AuthenticationFailed(msg)

        return user
1054756
def authenticated_get(username, password, url, verify=True):
    
    try:
        response = requests.get(url, auth=(username, password), verify=verify)
        if response.status_code == 401:
            raise BadCredentialsException(
                "Unable to authenticate user %s to %s with password provided!"
                % (username, url))
    except requests.exceptions.SSLError:
        raise CertificateException("Unable to verify certificate at %s!" % url)
    return response.content
1272411
def make_http_credentials(username=None, password=None):
    """"""
    credentials = ''
    if username is None:
        return credentials
    if username is not None:
        if ':' in username:
            return credentials
        credentials += username
    if credentials and password is not None:
        credentials += ":%s" % password
    return "%s@" % credentials
694800
def authbasic(request):
    
    if len(request.environ.get('HTTP_AUTHORIZATION', '')) > 0:
        auth = request.environ.get('HTTP_AUTHORIZATION')
        scheme, data = auth.split(None, 1)
        assert scheme.lower() == 'basic'
        data = base64.b64decode(data)
        if not isinstance(data, unicode):
            data = data.decode('utf-8')
        username, password = data.split(':', 1)
        if User.by_ldap_credentials(
                DBSession(), username, password, request.registry.settings):
            return HTTPFound(location=request.url)
        if User.by_credentials(DBSession(), username, password):
            return HTTPFound(location=request.url)
    return Response(status=401,
                    headerlist=[(str('WWW-Authenticate'),
                                 str('Basic realm="pyshop repository access"'),
                                 )],
                    )
781211
def authenticate(self, request):
        

        from doac.middleware import AuthenticationMiddleware

        try:
            response = AuthenticationMiddleware().process_request(request)
        except:
            raise exceptions.AuthenticationFailed("Invalid handler")

        if not hasattr(request, "user") or not request.user.is_authenticated():
            return None

        if not hasattr(request, "access_token"):
            raise exceptions.AuthenticationFailed("Access token was not valid")

        return request.user, request.access_token
619367
def create_verifier(self, request, credentials):
        
        verifier = {
            'oauth_token': request.resource_owner_key,
            'oauth_verifier': self.token_generator(),
        }
        verifier.update(credentials)
        self.request_validator.save_verifier(
            request.resource_owner_key, verifier, request)
        return verifier