scratchapi2 icon indicating copy to clipboard operation
scratchapi2 copied to clipboard

Auth API!

Open apple502j opened this issue 6 years ago • 9 comments

I wanted to add this kind of things, but it seems not working...

apple502j avatar Oct 26 '18 23:10 apple502j

Here is a reference I wrote recently (it's not published anywhere else yet): https://gist.github.com/towerofnix/cd5c0771446dc0ba81355fccc70ed1ea - It should be helpful for anyone implementing this.

towerofnix avatar Jan 12 '19 22:01 towerofnix

@towerofnix That didn't work either. I got [{'username': '', 'num_tries': 0, 'success': 0, 'msg': '', 'messages': [], 'id': None}]

apple502j avatar Jan 13 '19 07:01 apple502j

@apple502j Worked for me:

>>> r = s.post('https://scratch.mit.edu/accounts/login/', json={'username': 'TemplatesFTW', 'password': password, 'useMessages': True}, headers={'Cookie': 'scratchcsrftoken=' + s.cookies['scratchcsrftoken'], 'X-CSRFToken': s.cookies['scratchcsrftoken'], 'Referer': 'https://scratch.mit.edu', 'Origin': 'https://scratch.mit.edu', 'X-Requested-With': 'XMLHttpRequest'})
>>> len(r.text)
103
>>> r.text
'[{"username": "TemplatesFTW", "num_tries": 1, "success": 1, "msg": "", "messages": [], "id": 25341849}]'

Kenny2github avatar Jan 13 '19 10:01 Kenny2github

@Kenny2github hm, I can guess one stupid thing: Requests doesn't automaticlly add Cookie header

apple502j avatar Jan 13 '19 10:01 apple502j

I'm not so sure, let me test without explicit Cookie

Kenny2github avatar Jan 13 '19 10:01 Kenny2github

In my JavaScript programs I have to explicitly specify/parse cookie and set-cookie as well - cookies are a browser concept that node-fetch doesn't know how to handle (even though the fetch defined in browser JS code does).

towerofnix avatar Jan 13 '19 13:01 towerofnix

@towerofnix the problem here is that apparently the Python Requests library doesn't send cookies with Session requests like it should.

Kenny2github avatar Jan 13 '19 14:01 Kenny2github

I got it working. Will be released on April after finding what made POST/PUT unable to do.

apple502j avatar Mar 12 '19 08:03 apple502j

April came and went... forgot to close? BTW do u know any profile comment API ?

Quantum-Codes avatar Jul 26 '21 10:07 Quantum-Codes