Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/credentials/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/client/
3 changes: 3 additions & 0 deletions examples/credentials/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "loopback"
}
File renamed without changes.
File renamed without changes.
21 changes: 17 additions & 4 deletions examples/credentials/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
>WORK IN PROGRESS
# Credentials (header) scheme

# Access token or credentials
Credential schemes provide tenant information as credentials or as part of the
access token (ie. in the HTTP headers or query parameters).

An example that provides tenant information as part of the access token or
credentials (ie. in the HTTP headers or query parameters).
In this example, we provide the credentials using basic access authentication
(AKA basic auth).

## Usage

```shell
npm start

curl -u Joe:doe localhost:3000/api/Joe/Todos
# returns [{"content":"a","id":1},{"content":"b","id":2},{"content":"c","id":3}]

curl -u Bob:doe localhost:3000/api/Bob/Todos
# returns [{"content":"d","id":1},{"content":"e","id":2},{"content":"f","id":3}]
```
3 changes: 3 additions & 0 deletions examples/credentials/common/models/one-joe-todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(Onejoetodo) {

};
3 changes: 3 additions & 0 deletions examples/credentials/common/models/two-bob-todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(Twobobtodo) {

};
3 changes: 3 additions & 0 deletions examples/credentials/common/models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function(User) {

};
20 changes: 20 additions & 0 deletions examples/credentials/common/models/user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "user",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"username": {
"type": "string"
},
"password": {
"type": "string"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
32 changes: 32 additions & 0 deletions examples/credentials/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "credentials",
"version": "1.0.0",
"main": "server/server.js",
"scripts": {
"start": "node .",
"pretest": "eslint .",
"posttest": "nsp check"
},
"dependencies": {
"basic-auth": "^1.0.4",
"compression": "^1.0.3",
"cors": "^2.5.2",
"helmet": "^1.3.0",
"loopback": "^2.22.0",
"loopback-boot": "^2.6.5",
"loopback-component-explorer": "^2.4.0",
"loopback-datasource-juggler": "^2.39.0",
"loopback-multitenancy": "git+ssh://git@github.com/strongloop/loopback-multitenancy.git",
"serve-favicon": "^2.0.1"
},
"devDependencies": {
"eslint": "^2.5.3",
"nsp": "^2.1.0"
},
"repository": {
"type": "",
"url": ""
},
"license": "UNLICENSED",
"description": "credentials"
}
12 changes: 12 additions & 0 deletions examples/credentials/server/boot/create-bob-sample-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = function(app, cb) {
app.models.Two_Bob_Todo.create([
{content: 'd'},
{content: 'e'},
{content: 'f'},
], function(err, models) {
if (err) throw err;

console.log('created bob models:', models);
cb();
});
};
12 changes: 12 additions & 0 deletions examples/credentials/server/boot/create-joe-sample-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = function(app, cb) {
app.models.One_Joe_Todo.create([
{content: 'a'},
{content: 'b'},
{content: 'c'},
], function(err, models) {
if (err) throw err;

console.log('created joe models:', models);
cb();
});
};
11 changes: 11 additions & 0 deletions examples/credentials/server/boot/create-users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = function(app, cb) {
app.models.user.create([
{username: 'Joe', password: 'doe'},
{username: 'Bob', password: 'doe'}
], function(err, users) {
if (err) throw err;

console.log('created users:', users);
cb();
});
};
19 changes: 19 additions & 0 deletions examples/credentials/server/component-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"loopback-component-explorer": {
"mountPath": "/explorer"
},
"../node_modules/loopback-multitenancy": {
"scheme": "header",
"mountPath": "/:groupId/:resourceId",
"tenants": [
{
"tenantId": "One",
"username": "Joe"
},
{
"tenantId": "Two",
"username": "Bob"
}
]
}
}
14 changes: 14 additions & 0 deletions examples/credentials/server/datasources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"db1": {
"name": "db1",
"localStorage": "",
"file": "",
"connector": "memory"
},
"db2": {
"name": "db2",
"localStorage": "",
"file": "",
"connector": "memory"
}
}
52 changes: 52 additions & 0 deletions examples/credentials/server/middleware.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"initial:before": {
"loopback#favicon": {}
},
"initial": {
"compression": {},
"cors": {
"params": {
"origin": true,
"credentials": true,
"maxAge": 86400
}
},
"helmet#xssFilter": {},
"helmet#frameguard": {
"params": [
"deny"
]
},
"helmet#hsts": {
"params": {
"maxAge": 0,
"includeSubdomains": true
}
},
"helmet#hidePoweredBy": {},
"helmet#ieNoOpen": {},
"helmet#noSniff": {},
"helmet#noCache": {
"enabled": false
}
},
"session": {},
"auth": {
"./middleware/basic-auth": {}
},
"parse": {},
"routes": {
"loopback#rest": {
"paths": [
"${restApiRoot}"
]
}
},
"files": {},
"final": {
"loopback#urlNotFound": {}
},
"final:after": {
"loopback#errorHandler": {}
}
}
22 changes: 22 additions & 0 deletions examples/credentials/server/middleware/basic-auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var auth = require('basic-auth');

module.exports = function() {
return function(req, res, next) {
var credentials = auth(req);
if (!credentials)
return next(new Error('Invalid credentials'));

req.app.models.user.findOne({
where: {
username: credentials.name
}
}, function(err, user) {
if (err) return next(err);

if (!user) return next(new Error('Invalid credentials'));

req.user = user;
next();
});
};
};
28 changes: 28 additions & 0 deletions examples/credentials/server/model-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"loopback/server/mixins",
"../common/mixins",
"./mixins"
]
},
"user": {
"dataSource": "db1",
"public": true
},
"One_Joe_Todo": {
"dataSource": "db1",
"public": true
},
"Two_Bob_Todo": {
"dataSource": "db2",
"public": true
}
}
Empty file.
13 changes: 13 additions & 0 deletions examples/url/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
19 changes: 19 additions & 0 deletions examples/url/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*.csv
*.dat
*.iml
*.log
*.out
*.pid
*.seed
*.sublime-*
*.swo
*.swp
*.tgz
*.xml
.DS_Store
.idea
.project
.strong-pm
coverage
node_modules
npm-debug.log
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions examples/url/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"generator-loopback": {}
}
File renamed without changes.
3 changes: 3 additions & 0 deletions examples/url/client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Client

This is the place for your application front-end files.
17 changes: 17 additions & 0 deletions examples/url/common/models/one-joe-todo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "One_Joe_Todo",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"content": {
"type": "string"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
17 changes: 17 additions & 0 deletions examples/url/common/models/two-bob-todo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Two_Bob_Todo",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"content": {
"type": "string"
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
File renamed without changes.
6 changes: 6 additions & 0 deletions examples/url/server/boot/root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function(server) {
// Install a `/` route that returns server status
var router = server.loopback.Router();
router.get('/', server.loopback.status());
server.use(router);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"mountPath": "/explorer"
},
"../node_modules/loopback-multitenancy": {
"tenantResolverMountPath": "/api/:tenantId/:modelId/:modelName",
"modelResolverMountPath": "/api"
"scheme": "url",
"mountPath": "/:tenantId/:groupId/:resourceId"
}
}
27 changes: 27 additions & 0 deletions examples/url/server/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"restApiRoot": "/api",
"host": "0.0.0.0",
"port": 3000,
"remoting": {
"context": {
"enableHttpContext": false
},
"rest": {
"normalizeHttpPath": false,
"xml": false
},
"json": {
"strict": false,
"limit": "100kb"
},
"urlencoded": {
"extended": true,
"limit": "100kb"
},
"cors": false,
"errorHandler": {
"disableStackTrace": false
}
},
"legacyExplorer": false
}
Loading