Enter website by logging in Google Account using Python [closed]

 ̄綄美尐妖づ 提交于 2019-12-03 14:15:56

Don't let all the code samples and howto's lead you astray. They are intended for more complicated cases.

  • This is not oauth2 authorization, its oauth2 authentication
  • You're not the client with the clientID and the secret. Codecademy is the client with the clientID and the secret. Your codecademybot account simply is the user.

This means that you only need to automate what ordinary users do when logging into codecademy. Play that interaction that in the browser a couple times with a dev tool listening in (IE dev tool, FireBug, whatever) and look at the conversation of HTTP requests.

This is what you wish to emulate.

From what I can see,

  • Conversation starts by sending a request to http://codecademy.com/auth/google_oauth2.
  • The request gets forwarded to a https url at google
  • If I've previously logged in at google, a couple cookies get sent along and I get authenticated. The request gets sent back to the codecademy redirect_url at http://www.codecademy.com/auth/google_oauth2/callback with the oauth2 authentication code as a parameter.
  • Supposedly codecademy and google chat, for this takes about three seconds.
  • They agree that I'm me and two cookies (remember_user_token and _session_id) get set in my browser before I get forwarded to http://www.codecademy.com/

That last bit, I think, is interesting. How about you manually log in using your browser, listen in on the conversation and copy these two cookies to your automated code. See if they suffice as authentication tokens and allow you to fetch the data from the website.

If not, then I warmly recommend @CrisBee21 s answer. Let's hope pyCurl can emulate the browser well enough to do the conversation for you.

One more thing, when I browse around the site, I see one REST api request, namely http://www.codecademy.com/api/v1/notifications/userid/unread_count?authentication_token=some token

Surfing to http://www.codecademy.com/api/v1/users/userid/?authentication_token=the token gives me more info about myself

http://www.codecademy.com/api/v1/users/userid/groups?authentication_token=the token gives me the groups I'm in.

If you have more documentation about the codecademy REST api, you could try and take it from there. I couldn't find any documentation, am making this up as I go along.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!