ofcapl ofcapl - 1 year ago 68
Ajax Question

Let's chat authentication via ajax request

I've deployed a Let's Chat application for my own server.

However, instead of using currently built, original Let's Chat web application I would like to develop my own, using its API.

And according to Let's Chat wiki:

Revoke an API Token

In the top-left dropdown menu:

  • Select "Auth tokens"

  • Click "Revoke token"

  • Choose "Yes". This will delete any previously generated token.

Basic Authentication

Use the API token as the username when authenticating. The password
can be set to anything, but it must not be blank (simply because most
clients require it).

So far I've generated own token and tried to send
request to retrieve all rooms that I have in the app, but I've got an error:
401 - Unauthorized
- I've tried to send this request with
{ data: my_token, password: my_random_password }
credentials but without success. So my main question is: how exactly I can authenticate with Let's Chat API using ajax request?

I couldn't find any API url / endpoint dedicated for such task - please help.


I've tried also setting headers but it still doesn't work:

url: CHAT_URL + 'rooms',
beforeSend: function(xhr){
xhr.setRequestHeader('username', 'NTczYzZ1111111111111111111JiMWE3MGUwYThiNzZhYjhmYjFjOWJkOTQ5ZDQ2YjhjNWUyMzkwNmMzYjhjMQ==');
xhr.setRequestHeader('password', '123qwe');

Answer Source

Okay, finally I've solved it:

 xhr.setRequestHeader('Authentication', 'bearer NTczYzZ1111111111111111111JiMWE3MGUwYThiNzZhYjhmYjFjOWJkOTQ5ZDQ2YjhjNWUyMzkwNmMzYjhjMQ==');