Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Latest commit

 

History

History
111 lines (90 loc) · 6.05 KB

File metadata and controls

111 lines (90 loc) · 6.05 KB

Redek Project

Loopback 3 Starter Script

Travis status

Loopback Boot Script : Create access token

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.

Key Type Default value Description
showDebug boolean true Display additional console log
userModelName string User Name of the user model to manage users
defaultRoleUser object An object contains all the information about the role and the user to create
defaultRoleUser.name string superadmin Name of the role that will allow you to have all the access after the configuration of the ACLs.
defaultRoleUser.description string Role having all access and no restrictions (Provider : loopback-boot-create-access-token). Description of the role for better visibility in the database.
defaultRoleUser.user object An object containing the administrator user
defaultRoleUser.user.username string DeveloperAdmin Username that you will use to log in
defaultRoleUser.user.email string [email protected] Email address that you will use to log in
defaultRoleUser.user.emailVerified boolean true Allows you to creates a user without sending a validation email
defaultRoleUser.user.password string @dminD€v Password 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: "[email protected]",
            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.