API call for Basic Authentication (Javascript)?

oauth
auth
authorization
javascript

#1

Hi I’m new to the twitter api. I’m creating a small web app in which requires basic authentication (i.e., username and password) to the twitter profile. I’m not able to get the solution how can i achieve this.

I’ve looked into api docs and found this: https://dev.twitter.com/oauth/reference/post/oauth2/token it is seems to be what i want to achieve but when i made an ajax call. couldn’t get any results… :frowning:

What i want is that I have created a small web page form in which username and password will be entered. then I will pick those username and password and generate token and make a api call to the twitter api and then get the basic profile info of user?

If basic authentication is not possible then tell me another way to achieve this. thanks.

I’m creating authorization token from username and password using this way:

function generateToken(username, password) {
    return 'Basic ' + window.btoa(username + ':' + password);
}

I’m using javascript (angular2). You can provide me Jquery (Ajax) call i will convert it to angular2 http then.

Any help would be appreciated.

Thanks.


#2

The Twitter API does not support basic username/password authorization, and requires OAuth.

You may be interested in looking into existing Javascript libraries for the Twitter API such as Codebird-JS. In general, you’ll find that client-side scripting of the Twitter API in Javascript will be problematic due to cross-domain issues.