0.2.0 • Published 7 years ago

loopback-boot-create-access-token v0.2.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

This module is exclusively designed for Strongloop Loopback. It provides model and method testing thanks to an access token with quick access.

Getting started

Install

npm install --save loopback-boot-create-access-token

Usage

Modify server.js file by adding BOOTOPTIONS as below. This change will run the module startup script, and then start the scripts in the server/boot directory.

// app.start = function () { ... }

const BOOTOPTIONS = {
    'appRootDir': __dirname,
    'bootDirs': [
        '../node_modules/loopback-boot-create-access-token/lib/index.js'
    ]
};
boot(app, BOOTOPTIONS, function (err) {
    if (err) throw err;
    
    // start the server if `$ node server.js`
    if (require.main === module)
        app.start();
});

In order to take full advantage of the access token, you will need to create a new ACL rule that allows the new user to access any type of method. To do this type command : lb acl or apic loopback:acl or slc loopback:acl. Then choose the options as below :

  • Select the template to apply the ACL entry : (all existing models)
  • Select ACL scope : All methods and properties
  • Select type of access : All (match all types)
  • Select the role : other
  • Enter the role name : {The name of the role you chose or the default (superadmin)}
  • Select the right to apply : Explicitly grant access

Configuration

The initial configuration is set to work with the basic user model (User). This configuration will create a superadmin role and a DeveloperAdmin user.

KeyTypeDefault valueDescription
showDebugbooleantrueDisplay additional console log
userModelNamestringUserName of the user model to manage users
defaultRoleUserobjectAn object contains all the information about the role and the user to create
defaultRoleUser.namestringsuperadminName of the role that will allow you to have all the access after the configuration of the ACLs.
defaultRoleUser.descriptionstringRole having all access and no restrictions (Provider : loopback-boot-create-access-token).Description of the role for better visibility in the database.
defaultRoleUser.userobjectAn object containing the administrator user
defaultRoleUser.user.usernamestringDeveloperAdminUsername that you will use to log in
defaultRoleUser.user.emailstringdeveloper.admin@domain.comEmail address that you will use to log in
defaultRoleUser.user.emailVerifiedbooleantrueAllows you to creates a user without sending a validation email
defaultRoleUser.user.passwordstring@dminD€vPassword you will use to log in

The configuration is customizable by modifying server.js and add/modifying items as the following example:

var loopback = require('loopback');
var boot = require('loopback-boot');
var bootCreateAccessToken = require('loopback-boot-create-access-token');

// => Configuration
bootCreateAccessToken.configurations({
    showDebug: false,
    userModelName: "Account",
    defaultRoleUser: {
        name: "admin",
        user: {
            username: "RedekProject",
            email: "contact@redekproject.fr",
            emailVerified: true,
            password: "l00pb@ck@d!n",
            firstName: "Philippe",
            lastName: "Desplats"
        }
    }
});

Testing

Run the unit tests

npm test

Author

License

This project is licensed under the MIT License - see the LICENSE.md file for details.