Authentication

Components that require authentication from the user must implement an authentication module for the service/module they belong to. The authentication module must be named auth.js and must be stored under either the service or module directory (i.e. [vendor]/[service]/auth.js or [vendor/[service]/[module]/auth.js. Appmixer currently supports three types of authentication mechanisms that are common for today's APIs: API key, OAuth 1 and OAuth 2.

An example of an API key-based authentication used by Twilio components:

const twilio = require('twilio');
module.exports = {
type: 'apiKey',
definition() {
return {
tokenType: 'authentication-token',
accountNameFromProfileInfo: 'accountSID',
auth: {
accountSID: {
type: 'text',
name: 'Account SID',
tooltip: 'Log into your Twilio account and find <i>API Credentials</i> on your settings page.'
},
authenticationToken: {
type: 'text',
name: 'Authentication Token',
tooltip: 'Found directly next to your Account SID.'
}
},
validate: context => {
let client = new twilio(context.accountSID, context.authenticationToken);
return client.api.accounts.list();
}
};
}
};

And example of an OAuth 2 authentication used by Github components:

module.exports = {
type: 'oauth2',
definition: {
accountNameFromProfileInfo: 'login',
authUrl: 'https://github.com/login/oauth/authorize',
requestAccessToken: 'https://github.com/login/oauth/access_token',
requestProfileInfo: {
method: 'GET',
url: 'https://api.github.com/user?access_token={{accessToken}}',
headers: {
'Accept': 'application/vnd.github.v3+json',
'User-Agent': 'AppMixer'
}
},
validateAccessToken: {
method: 'GET',
url: 'https://api.github.com/user?access_token={{accessToken}}',
headers: {
'Accept': 'application/vnd.github.v3+json',
'User-Agent': 'AppMixer'
}
}
}
};

As you can see in the examples above, Appmixer provides an easy way to configure authentication modules. Most of the time, it's just about configuring a 3rd party service provider URLs for authentication, requesting access tokens and token validation.

Authentication Module Structure

Each authentication module is a NodeJS module that returns an object with type and definition properties. type can be either apiKey, oauth (for OAuth 1) and oauth2 (for OAuth 2). definition is either an object or a function (useful in cases where there's a code that you need to run dynamically).

type

The type of the authentication mechanism. Any of apiKey, oauth and oauth2.

definition

The definition of the authentication mechanism specific to the API service provider. An object or a function.