MCPcopy Create free account
hub / github.com/TimMcCool/scratchattach / login_by_id

Function login_by_id

scratchattach/site/session.py:1367–1397  ·  view source on GitHub ↗

Creates a session / log in to the Scratch website with the specified session id. Structured similarly to Session._connect_object method. Args: session_id (str) Keyword arguments: username (str) password (str) xtoken (str) Returns: scrat

(session_id: str, *, username: Optional[str] = None, password: Optional[str] = None, xtoken=None)

Source from the content-addressed store, hash-verified

1365
1366
1367def login_by_id(session_id: str, *, username: Optional[str] = None, password: Optional[str] = None, xtoken=None) -> Session:
1368 """
1369 Creates a session / log in to the Scratch website with the specified session id.
1370 Structured similarly to Session._connect_object method.
1371
1372 Args:
1373 session_id (str)
1374
1375 Keyword arguments:
1376 username (str)
1377 password (str)
1378 xtoken (str)
1379
1380 Returns:
1381 scratchattach.session.Session: An object that represents the created login / session
1382 """
1383 # Generate session_string (a scratchattach-specific authentication method)
1384 # should this be changed to a @property?
1385 issue_login_warning()
1386 if password is not None:
1387 session_data = dict(id=session_id, username=username, password=password)
1388 session_string = base64.b64encode(json.dumps(session_data).encode()).decode()
1389 else:
1390 session_string = None
1391
1392 _session = Session(id=session_id, username=username or "", session_string=session_string)
1393 if xtoken is not None:
1394 # xtoken is retrievable from session id, so the most we can do is assert equality
1395 assert xtoken == _session.xtoken
1396
1397 return _session
1398
1399
1400def login(username, password, *, timeout=10) -> Session:

Callers 3

loginFunction · 0.85
login_by_session_stringFunction · 0.85
login_from_browserFunction · 0.85

Calls 4

issue_login_warningFunction · 0.85
SessionClass · 0.85
decodeMethod · 0.80
encodeMethod · 0.80

Tested by

no test coverage detected