Esempio n. 1
0
    def login(self, username, password):
        '''
        Used to initialize the client for use

            username, string
            Username of VRC account

            password, string
            Password of VRC account

        Returns void
        '''

        if self.loggedIn: raise AlreadyLoggedInError("Client is already logged in")

        auth = username+":"+password
        auth = str(base64.b64encode(auth.encode()))[2:-1]

        resp = self.api.call("/auth/user", headers={"Authorization": "Basic "+auth}, no_auth=True)

        self.api.set_auth(auth)
        self.api.session.cookies.set("auth", resp["response"].cookies["auth"])

        self.me = objects.CurrentUser(self, resp["data"])
        self.loggedIn = True
Esempio n. 2
0
    def login(self, username=None, password=None, b64=None):
        """
        Used to initialize the client for use

        :param username: Username of VRC account
        :type username: str

        :param password: Password of VRC account
        :type password: str
        """
        if self.logged_in:
            raise AlreadyLoggedInError("Client is already logged in")

        if b64 is None:
            if username is None or password is None:
                raise Exception(
                    "You have to provide either username and password directly, or a base64-encoded auth 'token'."
                )
            b64 = base64.b64encode(f'{username}:{password}'.encode()).decode()
        elif username is not None or password is not None:
            raise Exception(
                "You have to provide either username and password directly, or a base64-encoded auth 'token'."
            )

        resp = self.api.call('/auth/user',
                             headers={'Authorization': f'Basic {b64}'},
                             authenticate=True)

        self.api.set_auth_login(resp['response'].cookies['auth'])

        self.me = objects.CurrentUser(self, resp['data'])
        self.logged_in = True
Esempio n. 3
0
    def fetch_me(self):
        '''
        Used to refresh client.me
        Returns CurrentUser object
        '''

        resp = self.api.call("/auth/user")

        self.me = objects.CurrentUser(self, resp["data"])
        return self.me
Esempio n. 4
0
    def fetch_me(self):
        """
        Used to refresh client.me

        :return: CurrentUser object
        :rtype: objects.CurrentUser
        """
        resp = self.api.call('/auth/user')
        self.me = objects.CurrentUser(self, resp['data'])
        return self.me
Esempio n. 5
0
    def login2fa(self, username, password, code=None, verify=False):
        '''
        Used to initialize client for use (for accounts with 2FactorAuth)

            username, string
            Username of VRC account

            password, string
            Password of VRC account

            code, string
            2FactorAuth code

            verify, boolean
            Whether to verify 2FactorAuth code, or leave for later

        This will ignore the RequiresTwoFactorAuthError exception, so be careful!
        If kwarg verify is False, Client.verify2fa() must be called after
        '''

        if self.loggedIn:
            raise AlreadyLoggedInError("Client is already logged in")

        auth = username + ":" + password
        auth = str(base64.b64encode(auth.encode()))[2:-1]

        resp = None

        try:
            resp = self.api.call("/auth/user",
                                 headers={"Authorization": "Basic " + auth},
                                 no_auth=True,
                                 verify=False)
            raise_for_status(resp)

            self.api.set_auth(auth)
            self.api.session.cookies.set("auth",
                                         resp["response"].cookies["auth"])

            self.me = objects.CurrentUser(self, resp["data"])
            self.loggedIn = True
        except RequiresTwoFactorAuthError:
            self.api.set_auth(auth)
            self.api.session.cookies.set(
                "auth", resp["response"].cookies["auth"])  # Auth cookieeee
            if verify:
                self.needsVerification = True
                self.verify2fa(code)
            else:
                self.needsVerification = True
Esempio n. 6
0
    def verify2fa(self, code):
        '''
        Used to finish initializing client for use after Client.login2fa()

            code, string
            2FactorAuth code
        '''

        if self.loggedIn:
            raise AlreadyLoggedInError("Client is already logged in")

        resp = self.api.call("/auth/twofactorauth/totp/verify",
                             "POST",
                             json={"code": code})
        resp = self.api.call("/auth/user")

        self.me = objects.CurrentUser(self, resp["data"])
        self.loggedIn = True
        self.needsVerification = False
Esempio n. 7
0
    def loginb64(self, b64):
        '''
        Used to initialize the client for use

            b64, string
            Base64 Encoding of VRC account credentials

        Returns void
        '''

        if self.loggedIn:
            raise AlreadyLoggedInError("Client is already logged in")

        resp = self.api.call("/auth/user", headers={"Authorization": "Basic "+b64}, no_auth=True)

        self.api.set_auth(b64)
        self.api.session.cookies.set("auth", resp["response"].cookies["auth"])

        self.me = objects.CurrentUser(self, resp["data"])
        self.loggedIn = True