Twitter login using javascript?

Ankit Agrawal picture Ankit Agrawal · Jun 21, 2016 · Viewed 12.7k times · Source

I want to add a twitter login functionality for my website using only JavaScript and HTML.

is it possible ?

Answer

dre-hh picture dre-hh · Jun 21, 2016

Yes and no.

It is not possible at the time of writing, if you want to do it only with browser client side javascript, because twitter does not allow cross site requests.

Browsers execute javascript code in a sandbox environment, which does not allow you to do a request to another domain as yours, except the 3rd party domain explicitly allows it. This is called Http Access Control (CORS)

However the twitter api can of course be consumed by a javascript app, which is not running in a browser.

So if you want this functionality for your website and you want to code it only in javascript, you would have to write a backend api for your website in nodejs or use another 3rd party service like @RationalDev suggested