Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter login using javascript?

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

is it possible ?

like image 421
Ankit Agrawal Avatar asked Jan 05 '23 20:01

Ankit Agrawal


2 Answers

If you mean only JavaScript and HTML on the client, there are some third party libraries.

Auth0 is popular and has instructions for Twitter.

Another possible solution is to use Firebase auth. It has a JavaScript API which can be used as follows:

Create an instance of the Twitter provider object:

var provider = new firebase.auth.TwitterAuthProvider();

Authenticate with Firebase using the Twitter provider object. You can prompt your users to sign in with their Twitter accounts either by opening a pop-up window or by redirecting to the sign-in page.

like image 118
RationalDev likes GoFundMonica Avatar answered Jan 16 '23 04:01

RationalDev likes GoFundMonica


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

like image 20
dre-hh Avatar answered Jan 16 '23 03:01

dre-hh