Connect to the websocket.

        If uuid is None, the connection will be to the controller. Otherwise it
        will be to the model.
        :return: The response field of login response JSON object.
775941
async def _connect_with_login(self, endpoints):
        
        success = False
        try:
            await self._connect(endpoints)
            # It's possible that we may get several discharge-required errors,
            # corresponding to different levels of authentication, so retry
            # a few times.
            for i in range(0, 2):
                result = (await self.login())['response']
                macaroonJSON = result.get('discharge-required')
                if macaroonJSON is None:
                    self.info = result
                    success = True
                    return result
                macaroon = bakery.Macaroon.from_dict(macaroonJSON)
                self.bakery_client.handle_error(
                    httpbakery.Error(
                        code=httpbakery.ERR_DISCHARGE_REQUIRED,
                        message=result.get('discharge-required-error'),
                        version=macaroon.version,
                        info=httpbakery.ErrorInfo(
                            macaroon=macaroon,
                            macaroon_path=result.get('macaroon-path'),
                        ),
                    ),
                    # note: remove the port number.
                    'https://' + self.endpoint + '/',
                )
            raise errors.JujuAuthError('failed to authenticate '
                                       'after several attempts')
        finally:
            if not success:
                await self.close()
1244235
def authenticate(self):
        
        resp = self.session.get(self.api_url, auth=self.auth)
        resp = self._process_response(resp)
        return resp
49883
def login(self):
        
        data = {'user': self.options['username'], 'passwd':
                self.options['password'], 'api_type': 'json'}
        response = self.client.post('http://www.reddit.com/api/login', data=data)
        self.client.modhash = response.json()['json']['data']['modhash']
1271366
def session(self, auth=None):
        
        url = '{server}{auth_url}'.format(**self._options)

        if isinstance(self._session.auth, tuple) or auth:
            if not auth:
                auth = self._session.auth
            username, password = auth
            authentication_data = {'username': username, 'password': password}
            r = self._session.post(url, data=json.dumps(authentication_data))
        else:
            r = self._session.get(url)

        user = User(self._options, self._session, json_loads(r))
        return user
323073
def _server_response_handler(self, response: Dict[str, Any]):
        
        code = response.get("CODE")
        if code == 100:
            if self.debug:
                print("auth succeed")
            self._login_fut.set_result(response)
        if code == 101:
            if self.debug:
                print('pong')
        return True
1197255
async def connect(self) -> Connection:
        
        if self._conn is None:
            self._conn = await r.connect(host=self._host,
                                         port=self._port,
                                         db=self._db,
                                         auth_key=self._auth_key,
                                         user=self._user,
                                         password=self._password,
                                         timeout=self._timeout,
                                         ssl=self._ssl,
                                         io_loop=self._loop)
        return self._conn
846256
def authenticate(self):
        
        unique_id = self.new_unique_id()
        message = {
            'op': 'authentication',
            'id': unique_id,
            'appKey': self.app_key,
            'session': self.session_token,
        }
        self._send(message)
        return unique_id
133830
def login
    connect! unless connected?    
    json = <<-EOF
      {
        "user_auth": {
          "user_name": "#{@user}",
           "password": "#{OpenSSL::Digest::MD5.new(@pass)}",
            "version": 2
        },
        "application": "sugarcrm_rubygem"
      }
    EOF
    json.gsub!(/^\s{6}/,'')
    response = send!(:login, json)
  end
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
1115180
def login(request):
    '''
    
    '''
    serializer_class = registration_settings.LOGIN_SERIALIZER_CLASS
    serializer = serializer_class(data=request.data)
    serializer.is_valid(raise_exception=True)
    user = serializer.get_authenticated_user()

    if not user:
        raise BadRequest('Login or password invalid.')

    extra_data = perform_login(request, user)

    return get_ok_response('Login successful', extra_data=extra_data)
271065
def get_profile(self):
        
        r = self._session.get(API_URL + "/logins/me")
        r.raise_for_status()

        return r.json()
132692
def to_json(self):
        
        data = dict(self.__dict__)
        data.pop('context',None)
        data['oauth'] = self.oauth.to_dict()
        data['cache'] = self.cache.to_dict()
        return json.dumps(data)
53290
def get_json_response(self):
        
        self.json_response = self.get_response().json()
        if self.json_response is not None:
            error_code = self.json_response.get("errcode", None)
            self.call_status = True if error_code == 0 else False
        return self.json_response
324102
def login(self, username, password):
        '''
        '''
        response = self.request(
            ACCESS_TOKEN,
            {
                'x_auth_mode': 'client_auth',
                'x_auth_username': username,
                'x_auth_password': password
            },
            returns_json=False
        )
        token = dict(parse_qsl(response['data'].decode()))
        self.token = oauth.Token(
            token['oauth_token'], token['oauth_token_secret'])
        self.oauth_client = oauth.Client(self.consumer, self.token)
86149
def connect(self):
        
        if self._sock:
            return
        try:
            sock = self._connect()
        except socket.error:
            e = sys.exc_info()[1]
            raise ConnectionError(self._error_message(e))

        self._sock = sock
        try:
            self.on_connect()
        except SSDBError:
            # clean up after any error in on_connect
            self.disconnect()
            raise

        # run any user callbacks. right now the only internal callback
        # is for pubsub channel/pattern resubscription
        for callback in self._connect_callbacks:
            callback(self)
1172308
def connect(self):
        
        if self.token:
            self.phab_session = {'token': self.token}
            return

        req = self.req_session.post('%s/api/conduit.connect' % self.host, data={
            'params': json.dumps(self.connect_params),
            'output': 'json',
            '__conduit__': True,
        })

        # Parse out the response (error handling ommitted)
        result = req.json()['result']
        self.phab_session = {
            'sessionKey': result['sessionKey'],
            'connectionID': result['connectionID'],
        }
512230
def connect(self, frame, response=None):
        
        self.engine.log.debug("CONNECT")

        if self.engine.authenticator:
            login = frame.headers.get('login')
            passcode = frame.headers.get('passcode')
            if not self.engine.authenticator.authenticate(login, passcode):
                raise AuthError("Authentication failed for %s" % login)

        self.engine.connected = True

        response = response or Frame(frames.CONNECTED)
        response.headers['session'] = uuid.uuid4()

        # TODO: Do we want to do anything special to track sessions?
        # (Actually, I don't think the spec actually does anything with this at all.)
        self.engine.connection.send_frame(response)