Just Connect SDK for JavaScript
This is an SDK to talk to the Just Connect REST API from Node.js and web applications. It supports OAuth2 authorization with the Implicit, Authorization Code and Credentials grants.
Details on the API can be found here.
Prerequisites
To use this SDK, you need Node.js >= 0.12 or io.js. Node.js <= 0.10 is not compatible since it doesn't have some ES6-Features that the SDK uses.
Installing
Node.js
The preferred way to install the SDK is via the npm package manager. Type this into your terminal:
npm install just-sdk
Browser
For using the SDK in your web application, clone this repo, call npm install
followed by grunt dist
and copy the resulting file from the dist/
directory
to your web server.
First Steps
The simplest way to try out this SDK is to fire it up in a Node.js application with the OAuth2 credentials grant, i.e. you authenticate with your username and password. Simply require the library, configure it with a domain, flow, username and password and then call its functions.
Here is a simple example:
var SDK = require('just-sdk');
var sdk = new SDK({
domain: "just.loveyourintranet.com",
oauth2: {
flow: "credentials",
username: "yourmail@example.org",
password: "yourpassword",
client_id: "your_client_id",
client_secret: "your_client_secret"
}
});
sdk.oauth2.token()
.then(sdk.user.me.bind(sdk.user))
.then(function(me) {
console.log("You are using the API as " + me.name);
})
.catch(function(error) {
console.log("There was an error fetching your profile information: " + error.message);
});
The examples directory holds more examples to get you started.
Configuration
The SDK is configured by passing a config object to the constructor:
Key | Description | Type |
---|---|---|
domain |
The Just domain you would like to talk to. | string |
oauth2 |
An object containing the OAuth2-specific configuration. See below for details. | object |
For the different OAuth2 grant types, the oauth2
object holds different
values:
Implicit Grant Flow
Key | Description | Type |
---|---|---|
oauth2.flow |
Set this to implicit . |
string |
oauth2.redirect_uri |
The URI to redirect the user to after he has authenticated the application. | string |
oauth2.client_id |
The client ID of your application. | string |
Credentials Grant Flow (Username/Password)
Key | Description | Type |
---|---|---|
oauth2.flow |
Set this to credentials . |
string |
oauth2.username |
The username for authenticating towards Just. | string |
oauth2.password |
The password for authenticating towards Just. | string |
oauth2.client_id |
The client ID of your application. | string |
oauth2.client_secret |
The client secret of your application. | string |
Authorization Code Grant Flow
Key | Description | Type |
---|---|---|
oauth2.flow |
Set this to authorization_code . |
string |
oauth2.client_id |
The client ID of your application. | string |
oauth2.client_secret |
The client secret of your application. | string |
oauth2.redirect_uri |
The URI of your application that receives the authorization code. | string |
License
This SDK is distributed under the BSD 2-Clause License, see LICENSE for more information.