

def _handle_standalone_auth(self, request, **kwargs):
    authorization = pecan.request.authorization
    auth_backend = self._auth_backend.__class__.__name__
    remote_addr = pecan.request.remote_addr
    extra = {
        'auth_backend': auth_backend,
        'remote_addr': remote_addr,
    }
    if (not authorization):
        LOG.audit('Authorization header not provided', extra=extra)
        self._abort_request()
        return
    (auth_type, auth_value) = authorization
    if (auth_type.lower() not in ['basic']):
        extra['auth_type'] = auth_type
        LOG.audit(('Unsupported authorization type: %s' % auth_type), extra=extra)
        self._abort_request()
        return
    try:
        auth_value = base64.b64decode(auth_value)
    except Exception:
        LOG.audit('Invalid authorization header', extra=extra)
        self._abort_request()
        return
    split = auth_value.split(':')
    if (len(split) != 2):
        LOG.audit('Invalid authorization header', extra=extra)
        self._abort_request()
        return
    (username, password) = split
    result = self._auth_backend
    result = self._auth_backend.authenticate(username=username, password=password)
    if (result is True):
        ttl = getattr(request, 'ttl', None)
        try:
            token = self._create_token_for_user(username=username, ttl=ttl)
            return self._process_successful_response(token=token)
        except TTLTooLargeException as e:
            self._abort_request(status_code=http_client.BAD_REQUEST, message=e.message)
            return
    LOG.audit('Invalid credentials provided', extra=extra)
    self._abort_request()

dataset/ETHPy150Open StackStorm/st2/st2auth/st2auth/controllers/v1/auth.py TokenController._handle_standalone_auth/original