Website Authentication

Website Authentication

in API Development

Posted by: Abbot.8496

Abbot.8496

This isn’t strictly related to the API, but this is where all the cool kids hang out so I’m posting here.

I’m currently building some automated tools for guild management using the information from the Achievements Leaderboard page. The program first needs to log in, however. Looking at the sign-in page, the form submits an ‘email’ field and a ‘password’ field via POST method.

When attempting to log in, I get back an error 400 (bad request) in response. Any ideas on how to diagnose the issue?

For reference, python code is as follows:


        import Request

        url = "https://account.guildwars2.com/login"
        content_type = 'text/html'
        payload = {"email" : username, "password" : password}
        headers2 = {"User-Agent" : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
                    "Content-Type" : content_type,
                    }
        
        s = Session()
        req = Request ('POST', url, data=payload, headers=headers2)
        prepped = req.prepare()
        resp = s.send(prepped)

Website Authentication

in API Development

Posted by: Abominable Snowman.2036

Abominable Snowman.2036

Well, first, your content-type is off (it should be application/x-www-form-urlencoded), but second, the login page seems to check the Referer. Simply adding

"Referer": url,

to your headers2 dict would do the trick.

Website Authentication

in API Development

Posted by: Healix.5819

Healix.5819

(edited by Healix.5819)

Website Authentication

in API Development

Posted by: Abbot.8496

Abbot.8496

Thanks for the references, Healix. Those will come in handy.

Snowman, adding the entry to the dictionary was just the trick. How did you know about or where did you find reference to “Referer”?

Website Authentication

in API Development

Posted by: Healix.5819

Healix.5819

How did you know about or where did you find reference to “Referer”?

When making a login script, you simply replicate the headers your web browser would send. Discovering that the referrer is required is simply a task of trial and error.