
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
loopback-with-admin
Advanced tools
Run loopback server easier.
npm install loopback-with-admin
// model definitions
// see "models" section for more detail
const models = {
user: {
base: 'User'
}
};
require('loopback-with-admin').run(models).then(lbInfo => {
// see "LoopbackInfo" section for more detail
console.log(lbInfo.getURL()) // loopback api root
console.log(lbInfo.getAdminTokens()) // access tokens of admin
})
Or more strictly, pass models like
require('loopback-with-admin').run({models: models})
before running, you can prepare a directory which contains custom config information.
(config-dir) # any name is acceptable
|-- common
| |-- server.coffee
|-- development
| `-- datasources.coffee
`-- production
`-- datasources.coffee
const lbWithAdmin = require('loopback-with-admin')
const configDir = '/path/to/config-dir'
lbWithAdmin.run({models: models}, configDir).then(lbInfo => {
// loopback started with the config
})
See "configs" section for more details.
const lbWithAdmin = require('loopback-with-admin')
const config = {server: {port: 3001}}
lbWithAdmin.run({models: models}, config)
const configDir = '/path/to/config-dir'
require('loopback-with-admin').run({models: models}, configDir, {env: 'production'})
env is set following the rules.
When your config dir is
(config-dir) # any name is acceptable
|-- common
| |-- server.coffee
|-- development
| `-- datasources.coffee
|-- local
| `-- datasources.coffee
|-- production
| `-- datasources.coffee
and launching script like
$ NODE_ENV=local node app.js
then, loopback-with-admin selects configs in "local" directory.
const models = {
player: { // model name
base: 'User', // following loopback model definition
aclType: 'admin' // only 'aclType' is the specific property for loopback-with-admin
},
instrument: { // another model
aclType: 'owner-read'
}
}
require('loopback-with-admin').run({models: models})
aclType value.name is automatically set from definition information.plural is set to the same value as the name unless you set manually.aclType is prepared for defining complicated acls easier.
loopback-with-admin generates acls from aclType with the following rules.
| aclType | meaning |
|---|---|
| admin | only admin can CRUD the model (default) |
| owner | the owner of the model can CRUD |
| public-read | everyone can READ the model and admin can CRUD |
| member-read | authenticated users can READ the model and admin can CRUD |
| public-read-by-owner | CRUD by the owner, and read by everyone |
| member-read-by-owner | CRUD by the owner, and read by authenticated users |
| none | everyone can CRUD the model |
const models = {
player: {
base: 'User',
aclType: {
owner: 'rwx',
member: 'r'
}
}
}
aclType can be an object, whose key contains the following roles.
$owner role in LoopBack$authenticated role in LoopBack$everyone role in LoopBackparticipant role section)custom roles section.The values of the keys are rwx, which is the same as Unix permission.
x here means EXECUTE accessType in LoopBack.
See loopback roles for instructions. https://docs.strongloop.com/display/public/LB/Defining+and+using+roles
You can define custom roles like the following code.
const customRoles = {
'doctor': '/path/to/doctor-role.js',
'patient': '/path/to/patient-role.js'
}
require('loopback-with-admin').run({models: models, customRoles: customRoles})
In the file, you must export a function, which will be passed to the 2nd argument of Role.registerResolver in LoopBack.
See how to define custom roles in LoopBack. https://docs.strongloop.com/display/public/LB/Defining+and+using+roles
Example:
module.exports = function(role, context, cb) {
var app = this // `app` can be acquired via `this`
function reject(err) {
if (err) { return cb(err) }
cb(null, false)
}
if (context.modelName !== 'patient') { return reject() }
var userId = context.accessToken.userId
if (!userId || userId === context.modelId) {
return reject()
}
cb(null, true) // is in role
admin role is the role with which every REST APIs are available.
The role and one user with it are automatically generated at boot phase.
To be admin, you need to know its access tokens. The following code can get those.
require('loopback-with-admin').run(models, config).then(lbInfo => {
let tokens = lbInfo.getAdminTokens()
console.log(tokens) // access tokens (String[]) of admin.
})
fetch function to set tokensBy default, the token is fixed and it's loopback-with-admin-token.
You must change the value by passing fetch function.
const admin = {
fetch: function() {
return ['your-secret-token1', 'your-secret-token2']
}
}
require('loopback-with-admin').run(models, config, { admin: admin })
const admin = {
fetch: function() {
return generateSecretValuesByRandom().then(value => [ value ]) // fetch function allows Promise to return
},
intervalHours: 24 // change the value every day (by default, it's 12 hours)
}
require('loopback-with-admin').run(models, config, { admin: admin })
| property | value |
|---|---|
| id | loopback-with-admin-user-id |
| loopback-with-admin@example.com | |
| password | admin-user-password |
In fact, these value makes no sense as admin can never be accessed via REST APIs. No one can login with the account information.
Four types of configs are available.
See JSON files in default-values/non-model-configs directory.
You can set the same properties as these JSONs.
| config key | meaning |
|---|---|
| memory | on memory datasource |
| db | datasource for custom entities |
Each datasource name has its connectors.
Available datasources are
memory-idstr is the default connector, which stores data only in memory,
and id type is string whereas id type of "memory" is number.
See loopback-connector-memory-idstr.
To use mongodb, add dependencies in package.json of your repository
| config key | meaning | default |
|---|---|---|
| restApiRoot | REST api root | /api |
| port | port number | 3000 |
| config key | meaning |
|---|---|
| gcmServerApiKey | api key for Google Cloud Messaging (GCM) |
| apnsCertData | certificate pem contents for APNs |
| apnsKeyData | key pem contents for APNs |
require('loopback-with-admin').run() returns promise of LoopbackInfo.
It contains the information of the launched loopback.
Returns hosting URL.
const config = {
server: {
port: 4156,
restApiRoot: 'awesome-endpoint'
}
}
require('loopback-with-admin').run(models, config).then(lbInfo => {
lbInfo.getURL() // localhost:4156/awesome-endpoint
})
Returns Array of access tokens (string).
const admin = {
fetch: function() {
return ['your-secret-token1', 'your-secret-token2']
}
}
require('loopback-with-admin').run(models, config, { admin: admin }).then(lbInfo => {
console.log(lbInfo.getAdminTokens()) // ['your-secret-token1', 'your-secret-token2']
})
Returns environment name where loopback launched.
Contains all config values used to build loopback.
See configs section above.
Contains model definitions used to build loopback
See models section above.
The role for anonymous but limited access.
Programs which know a specific static access token can become the role.
The token is set by options param in run() method.
const participantToken = 'AbCdE'
require('loopback-with-admin').run(models, config, { participantToken })
Then, all accesses with the accessToken AbCdE will be participant role.
(coming soon)
FAQs
launch loopback with admin, push-notifications
We found that loopback-with-admin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.