async 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 = await self.api.call("/auth/user", headers={"Authorization": "Basic "+auth}, no_auth=True) self.api.openSession(auth) self.api.session.cookie_jar.update_cookies([["auth", resp["response"].headers["Set-Cookie"].split(';')[0].split("=")[1]]]) self.me = aobjects.CurrentUser(self, resp["data"]) self.loggedIn = True await self.me.cacheTask
async 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, AClient.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 = await self.api.call( "/auth/user", headers={"Authorization": "Basic " + auth}, no_auth=True, verify=False) raise_for_status(resp) self.api.openSession(auth) self.api.session.cookie_jar.update_cookies([[ "auth", resp["response"].headers["Set-Cookie"].split(';') [0].split("=")[1] ]]) self.me = aobjects.CurrentUser(self, resp["data"]) self.loggedIn = True await self.me.cacheTask except RequiresTwoFactorAuthError: self.api.openSession(auth) self.api.session.cookie_jar.update_cookies([[ "auth", resp["response"].headers["Set-Cookie"].split(';') [0].split("=")[1] ]]) if verify: self.needsVerification = True await self.verify2fa(code) else: self.needsVerification = True
async def fetch_me(self): ''' Used to refresh client.me Returns CurrentUser object ''' resp = await self.api.call("/auth/user") self.me = aobjects.CurrentUser(self, resp["data"]) return self.me
async def verify2fa(self, code): ''' Used to finish initializing client for use after AClient.login2fa() code, string 2FactorAuth code ''' if self.loggedIn: raise AlreadyLoggedInError("Client is already logged in") await self.api.call("/auth/twofactorauth/totp/verify", "POST", json={"code": code}) resp = await self.api.call("/auth/user") self.me = aobjects.CurrentUser(self, resp["data"]) self.loggedIn = True self.needsVerification = False if self.caching: await self.me.cacheTask
async 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 = await self.api.call("/auth/user", headers={"Authorization": "Basic "+b64}, no_auth=True) self.api.openSession(b64) self.api.session.cookie_jar.update_cookies( [["auth", resp["response"].headers["Set-Cookie"].split(';')[0].split("=")[1]]]) self.me = aobjects.CurrentUser(self, resp["data"]) self.loggedIn = True await self.me.cacheTask