Authorization Process

Authorization Process Overview

The Authorization Process is an important step throughout your Beefree SDK installation process. This steps validates your Beefree SDK credentials and provides you with a token. Take the steps outlined in this document to ensure you accurately complete the authorization process.

Beefree SDK Client-side Configuration

Beefree SDK requires the host application to pass a container parameter in the client-side configuration. This is the only required parameters for the configuration.

The following code sample shows an example of this parameter in the client-side configuration.

var config = {
    container: 'string'
}

Beefree SDK Server-side Login

To initialize your instance of the Beefree SDK builder, call the /loginV2 endpoint shown in the sample code below with your Client ID, Client Secret, and UID. The Client ID and Secret are available on the application details page of the Beefree SDK developer portal. UID represents your user as described in How the UID parameter works.

Important: Do not put your Beefree SDK credentials in client-side code.

The Beefree SDK system uses OAuth2 as the authorization framework.

Example

POST /loginV2 HTTP/1.1
Host: auth.getbee.io
Accept: application/json
Content-Type: application/json
{
“client_id”: YOUR_CLIENT_ID,
“client_secret”: YOUR_CLIENT_SECRET,
“uid”: uid of choice
}

Reference How the UID parameter works to learn more about UID.

The following code sample displays an example JSON response.

{
    "access_token": "...",
    "v2": true
}

The Beefree SDK authorization service will return a temporary access token if the authentication is successful. The client application can use the full response that contains the token to start or refresh a Beefree SDK session.

The token you receive from the authorization server should be passed to the BeePlugin.create(...) as it is. We strongly suggest not altering it in any way. Also, don’t rely on the token response's content or structure. If you do, any change to the schema could make your integration stop working.

The token expires after 5 minutes for security reasons. Beefree SDK will refresh an expired token automatically for 12 hours without re-authenticating the application. Beefree SDK will trigger the onError callback when the token can't be refreshed automatically.

Note: When a refreshable token expires, Beefree SDK receives a 401 error and attempts to refresh it automatically. 401 errors are expected and part of the process.

The following code sample displays an example of how to call the Beefree SDK endpoint, obtain a token, and then start it.

var req = new XMLHttpRequest();
req.onreadystatechange = function() {
  if (req.readyState === 4 && req.status === 200) {
    // Obtain token
    var token = req.responseText;
    // Call create method and pass token and beeConfig to obtain an instance of Beefree SDK
    BeePlugin.create(token, beeConfig, function(beePluginInstance) {
	// Call start method of beefree SDK instance
	beePluginInstance.start(template); // template is the JSON to be loaded in BEE
    });
  }
};

// This is a sample call to YOUR server-side application that calls the loginV2 endpoint on BEE the side
req.open(
	'POST', 	// Method
	'/YOUR_BACKEND_TOKEN_ENDPOINT', // your server endpoint
	false 		// sync request
);

Ensure to call the authorization endpoint server-side to protect your credentials.

Once you obtain the token, the configuration parameters object is passed to Beefree SDK to set up your customization options, for example setting the editor’s language to “Spanish”.

Then, you can use Beefree SDK methods to start your instance and display the editor on your page.

Beefree SDK will keep this session alive for 12 hours from the login. After 12 hours, you have to manage the token expiration, as follows:

  1. Obtain a new token via the new authorization endpoint.

  2. Inject the token obtained from step one via the updateToken method. Reference examples of this in the following section.

The following code example shows how to inject the token in the current Beefree SDK instance:

// obtain a new token with a new LoginV2 call
// update the token in the current Beefree SDK instance
beePluginInstance.updateToken(token);

The following code example displays how to get the current JSON from the expiration error:

onError: function (error) {
  var code = error.code
  var detail = error.detail

  // the template the user was working on before the error occurred
  var currentJson = error.template
  ... 


  beePluginInstance.updateToken(token);
  // the beePluginInstance comes from the BeePlugin.create 
  ...

Error Management

When you set up an onError callback you will get the error object as a parameter.

From that object, you can grab the code property and use it as explained in the table below.

Handling error management

The following code samples display how to handle the 5101 and 5102 errors.

Error management error 5101

onError: function (error) {
 var code = error.code
 var detail = error.detail
 switch (code) {
   case 5101: // re-login and update token in the beeInstance
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
 if (req.readyState === 4 && req.status === 200) {
   // Obtain token
   var token = req.responseText;
   // Call update method and pass the new token existent BeePlugin instance
   BeePlugin.updateToken(token);
 }
};
req.open(
 'POST',  // Method
 '/token',  // The server side endpoint that calls BEE REST auth endpoint
 false   // sync request
);

     break
   case 5102: // re-login and create a new beeInstance
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
 if (req.readyState === 4 && req.status === 200) {
   // Obtain token
   var token = req.responseText;
   // Call update method and pass token and beeConfig to obtain an instance of BEE Plugin
   BeePlugin.create(token, beeConfig, function(beePluginInstance) {
     // Call start method of bee plugin instance
     beePluginInstance.start(template); // template is the json to be loaded in BEE
   });
 }
};
req.open(
 'POST',  // Method
 '/token',  // The server side endpoint that calls BEE REST auth endpoint
 false   // sync request
);
     break
 }
},

Error Responses

Example error response for unsupported media type Only Content-Type: application/json is allowed.

{
  "code": 5001,
  "message": "Unsupported media type 'application/x-www-form-urlencoded'",
  "status_code": 415
}

Example error response for an invalid UID. Look at the properties of UID parameter.

{
  "code": 5005,
  "message": "Invalid UID",
  "status_code": 400
}

Example error response for invalid credentials. Obtain your credentials using the authorization process.

{
  "code": 5002,
  "message": "Unable to authenticate with provided credentials.",
  "status_code": 401
}

Example error response for disabled apps. Contact support if you encounter this error.

{
  "code": 5003,
  "message": "Application is disabled.",
  "status_code": 403
}

Last updated

Logo

© Bee Content Design, Inc. San Francisco, CA | Part of Growens