0

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 GET 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.

EDIT:

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

$.ajax({
    url: CHAT_URL + 'rooms',
    beforeSend: function(xhr){
        xhr.setRequestHeader('username', 'NTczYzZ1111111111111111111JiMWE3MGUwYThiNzZhYjhmYjFjOWJkOTQ5ZDQ2YjhjNWUyMzkwNmMzYjhjMQ==');
        xhr.setRequestHeader('password', '123qwe');
    }
}).done(function(resp){
    console.log('1');
    console.log(resp);
}).done(function(resp){
    console.log('2');
    console.log(resp);
});
lukaszkups
  • 5,790
  • 9
  • 47
  • 85

1 Answers1

1

From that wiki page:

Use the API token as the Bearer token.

This is done by setting the header Authentication to the value bearer YOUR_TOKEN_HERE

So,

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

If you want to use basic authentication, this answers that question

How to use Basic Auth with jQuery and AJAX?

Community
  • 1
  • 1
Jamiec
  • 133,658
  • 13
  • 134
  • 193
  • I've tried You suggestion and I'm having an `401 - unauthorized` error :/ Tried with different combination (upper/downcase replacing order etc. but without success) – lukaszkups May 20 '16 at 11:15
  • (I'm sorry for my previous answer that was the copy of Yours) - at first I've made a mistake and I was using `Authorization` as a header name and when I finally found answer at other website I've pasted it here and didn't realise that You already give me the proper header name (`Authentication` <-- `Authorization`) - really sorry again about that! – lukaszkups May 23 '16 at 13:55