FreeboxOSAuth

FreeboxOS Authentication client

class FreeboxOSAuth.Failure(value, message)

A FreeboxOSAuth Deferred.Deferred() failure result. Inherits Http.Failure().

FreeboxOSAuth.Failure.FreeboxOSAuth.Failure.value

Failure value

FreeboxOSAuth.Failure.FreeboxOSAuth.Failure.message

Failure message

class FreeboxOSAuth.Client(opts)
Arguments
  • opts (variant()) – initial options, as an object.

Accepted options are:

base_url

Defaults to “http://mafreebox.freebox.fr/api/v3”.

http_transaction_factory

Defaults to Http.Transaction.factory().

app_id

Defaults to Qt.application.domain.

app_name

Defaults to Qt.application.name.

app_version

Defaults to Qt.application.version.

device_name

Defaults to Qt.platform.os || “Freebox Player”.

FreeboxOSAuth.Client.FreeboxOSAuth.Client.query()
Returns

a new Deferred.Deferred() instance.

FreeboxOSAuth.Client.FreeboxOSAuth.Client.check()
Returns

a new Deferred.Deferred() instance with status string.

FreeboxOSAuth.Client.FreeboxOSAuth.Client.register(tq, timeout)
Arguments
  • tq (TimeQueue()) – A TimeQueue id.

  • timeout (integer()) – A number of miliseconds before to timeout.

Returns

a new Deferred.Deferred().

An authorization request object can be created the following way:

var authz = new FreeboxOSAuth.Client({
   app_id: "...",
   app_name: "...",
   app_version: "...",
   device_name: "...",

   // function to call to create new HTTP transactions
   http_transaction_factory: ...,

   // previously obtained token
   app_token: "...",
});

Then API flow is:

authz.query().then(function () {
   // tell and wait user for button press on Freebox Server
});

Call (repeatedly) the check function until authorization is accepted:

authz.check().then(function(status) {
   console.log("Authorization status:", status);
   switch (status) {
      case "unknown":
      case "denied":
      case "timeout":
      // warn user, bail out
      return;

      case "pending":
      // still waiting
      return;

      case "granted":
      // yay !
      return;
   }
});

As a shortcut, you can call authz.register(tq, timeout) with a TimeQueue instance and a global timeout to wait response for. It does the registration query and the waiting for you:

// Tell user to go press the Server button
authz.register(tq, 30000).then(function(status) {
   // OK !
}, function (err) {
   // Warn the user with err.message
});

When authorization is done, one can issue a FreeboxOS call:

// Use client transaction factory to issue authorized API calls
authz.http_transaction_factory({
   url: "http://mafreebox.freebox.fr/api/v1/whatever/"
}).then(function(resp){
   console.log(resp);
});

Or one can use the FreeboxOS client interface:

// Or stack transaction factory in another client
var client = new FreeboxOS.Client({
   http_transaction_factory: authz.http_transaction_factory
});

client.add("system", {flat: true});
client.system.add("reboot", {flat: true});
client.system.reboot.create().then(function(response) {
   console.log(response);
});