gta5-map / Social-Club-API-cheat-sheet

Basically a guide that explains how to parse Rockstar's Social Club to obtain a specific piece of information using it's internal JSON endpoints.
http://rockstar-api.rtfd.io
Do What The F*ck You Want To Public License
74 stars 7 forks source link

Authentication steps that worked for me #6

Open hkors opened 7 years ago

hkors commented 7 years ago

Update June 13, 2017: The login page is now protected by reCAPTCHA, so we receive a HTTP status code 403 Forbidden now each time we login with this method. I haven't figured out a workaround for this.

Hello people,

The described authentication steps didn't work for me, probably because R* has changed the way we sign into SocialClub. But finally I managed to construct the correct HTTP requests, so here are the steps I've taken for everyone who's facing the same problem:

  1. Send a HTTP GET-request to https://socialclub.rockstargames.com/profile/signin, get the body and search for the hidden input field named __RequestVerificationToken. Note that there are multiple fields with this name. The one in front of <li class="twitter"> is used. Get the value of this input field and remember this verification token. The returned cookies must also be saved to a cookie jar.

  2. Now it is time to get the authentication cookie. Send a HTTP POST-request to https://socialclub.rockstargames.com/profile/signincompact with the cookie jar and add the following HTTP headers to this request:

    Accept: application/json, text/javascript, */*; q=0.01
    Content-Type: application/json; charset=UTF-8
    RequestVerificationToken: <VERIFICATION_TOKEN>

    The body of the request is a JSON string, as follows:

    {"login":"<SOCIALCLUB_USERNAME>","password":"<SOCIALCLUB_PASSWORD>","rememberme":true}

    Again, store the cookies in the cookie jar. If status code 403 Forbidden is returned, then you must sign into SocialClub manually on the same machine to get rid of the requested CAPTCHA. This CAPTCHA is requested for your IP address when you keep signing in a couple times during a short time. If status code 429 Too Many Requests is returned, you should wait a few minutes before trying it again. We should get status code 200 OK. If that is not the case, something went wrong, like missing required HTTP headers. If your credentials were invalid, you still receive status code 200 OK. To check whether the sign in was successful, check for the existence of a cookie named AuthenticateCookie. Nowadays it seems like we get a status code 401 Unauthorized when you provide invalid credentials.

  3. The cookie jar contains now the necessary cookies to retrieve the information you need. So if you want to get the information from http://socialclub.rockstargames.com/games/gtav/career/overviewAjax?character=Freemode&nickname=<SOCIALCLUB_USERNAME>&slot=Freemode&gamerHandle=&gamerTag=&_=<TIMESTAMP>, then send a HTTP GET-request to this URL with the cookie jar that contains the AuthenticateCookie cookie after step 2.

To each HTTP request I add the following HTTP headers (and override the Accept header in step 2):

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8,nl;q=0.6
Connection: keep-alive
Host: socialclub.rockstargames.com
Origin: https://socialclub.rockstargames.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36

Some POST-requests require the verification token again in the body to some URL's of SocialClub.

I've created a Node.js script based on the gta5-map/Social-Club-example-parser project that uses these authentication steps. It can be found in this pull request: https://github.com/gta5-map/Social-Club-example-parser/pull/12

frdmn commented 7 years ago

Well done!

LordTiggy commented 7 years ago

Do you mind sharing your code with u? So we have a working example.

hkors commented 7 years ago

@LordTiggy Check the other repository of @frdmn at https://github.com/gta5-map/Social-Club-example-parser. The code can be found in the index.js file. It is in Node.js, but I suppose it can be helpful for doing it in PHP using cURL or any other way you prefer.

timwoocker commented 6 years ago

Anyone found a working solution yet?

frdmn commented 6 years ago

@crey4fun The node.js parser doesn't work for you?

timwoocker commented 6 years ago

Nope, logging in does not work due to the recaptcha I guess

frdmn commented 6 years ago

The parser should notice if a captcha blocks the signin:

https://github.com/gta5-map/Social-Club-example-parser/blob/master/index.js#L274-L276