Comments (22)
Try this: Go to server/boot/authentication.js and comment the line where it says server.enableAuth();
and rerun again.
from loopback-example-access-control.
Authorization issues when using mongo
Does not occur when using memory as datasource
Mongo collections and data are created successfully.
Then, authentication works but authorization does not.
datasources.json:
{
"db": {
"name": "db",
"connector": "memory"
},
"mongoDS": {
"host": "localhost",
"port": 0,
"url": "",
"database": "AccessTest",
"password": "",
"name": "mongoDS",
"user": "",
"connector": "mongodb"
}
}
package.json:
{
"name": "loopback-example-access-control",
"version": "1.0.0",
"main": "server/server.js",
"scripts": {
"pretest": "jshint .",
"start": "node .",
"test": "mocha test/*test.js"
},
"dependencies": {
"bcrypt": "^1.0.2",
"body-parser": "^1.10.1",
"compression": "^1.0.3",
"cors": "^2.8.1",
"loopback": "^3.0.0",
"loopback-boot": "^2.4.0",
"loopback-connector-mongodb": "^3.0.1",
"serve-favicon": "^2.0.1",
"strong-error-handler": "^1.1.1",
"supertest": "^1.1.0"
},
"optionalDependencies": {
"loopback-component-explorer": "^2.1.0"
},
"devDependencies": {
"jshint": "^2.5.6",
"mocha": "^2.3.3"
},
"repository": {
"type": "git",
"url": "git://github.com/strongloop/loopback-example-access-control"
},
"license": "MIT"
}
Via explorer, generate and set access token using 'admin' role credentials.
Then request ... /api/projects and get authorization error
error log:
Unhandled error for request GET /projects: Error: Authorization Required
at /Users/dev/loopback-example-access-control/node_modules/loopback/lib/application.js:389:21
at /Users/dev/loopback-example-access-control/node_modules/loopback/lib/model.js:353:7
at /Users/dev/loopback-example-access-control/node_modules/loopback/common/models/acl.js:464:16
at /Users/dev/loopback-example-access-control/node_modules/async/dist/async.js:3694:9
at /Users/dev/loopback-example-access-control/node_modules/async/dist/async.js:359:16
at iteratorCallback (/Users/dev/loopback-example-access-control/node_modules/async/dist/async.js:935:13)
at /Users/dev/loopback-example-access-control/node_modules/async/dist/async.js:843:16
at /Users/dev/loopback-example-access-control/node_modules/async/dist/async.js:3691:13
at apply (/Users/dev/loopback-example-access-control/node_modules/async/dist/async.js:21:25)
at /Users/dev/loopback-example-access-control/node_modules/async/dist/async.js:56:12
at /Users/dev/loopback-example-access-control/node_modules/loopback/common/models/acl.js:449:17
at /Users/dev/loopback-example-access-control/node_modules/loopback/common/models/role.js:390:23
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
node v6.9.2
Whereas, the in-memory datasource works perfectly well.
Any insights would be appreciated.
from loopback-example-access-control.
same problem for me and not resolve with these solutions...
my model-config and datasource files are:
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
]
},
"User": {
"dataSource": "mongoDB",
"public": false
},
"AccessToken": {
"dataSource": "mongoDB",
"public": false
},
"ACL": {
"dataSource": "mongoDB",
"public": false
},
"RoleMapping": {
"dataSource": "mongoDB",
"options": {
"strictObjectIDCoercion": true
},
"public": false
},
"Role": {
"dataSource": "mongoDB",
"public": false
},
"user": {
"dataSource": "mongoDB",
"public": true
},
"team": {
"dataSource": "mongoDB",
"public": false
},
"project": {
"dataSource": "mongoDB",
"public": true
}
}
{
"db": {
"name": "db",
"connector": "memory"
},
"mongoDB": {
"host": "localhost",
"port": 27017,
"url": "",
"database": "Users",
"password": "",
"name": "mongoDB",
"user": "",
"connector": "mongodb"
}
}
If I set to use "connector": "memory" on model-config , it works perfectly, the problem is only when I choose mongDB connector
do I made some error?
from loopback-example-access-control.
Some solutions, the first breaks production:
strongloop/loopback#3121 (comment)
strongloop/loopback#3121 (comment)
strongloop/loopback#3121 (comment)
from loopback-example-access-control.
Any insights will be appreciated, thanks
from loopback-example-access-control.
I m the same problem !!!!
from loopback-example-access-control.
@wangdandong
Make it something like this :
{
"db": {
"name": "db",
"connector": "memory"
},
"mongoDb": {
"host": "localhost",
"port": 0,
"url": "",
"database": "test",
"password": "",
"name": "mongoDb",
"user": "",
"connector": "mongodb"
}
}
PS: Create a seperate datasource for mongo, I hope it works
Do let me know what happens.
Thank-You
from loopback-example-access-control.
a solution, see #94 (comment)
from loopback-example-access-control.
@Nygma297 I need the ACL feature, so I can't comment server.enableAuth();
.
Is there something wrong in my environment ?
from loopback-example-access-control.
Can you post the datasources.js file?
from loopback-example-access-control.
{
"db": {
"host": "localhost",
"port": 0,
"url": "",
"database": "test",
"password": "",
"name": "mongodb",
"user": "",
"connector": "mongodb"
}
}
Other function except ACL is working well.
from loopback-example-access-control.
Try adding a DataSourceJuggler Npm Package Maybe that'd help.
Here: https://www.npmjs.com/package/loopback-datasource-juggler
I Hope it works.
from loopback-example-access-control.
No, it does not resolve the issue.
I will debug and if successful get back.
from loopback-example-access-control.
Using DEBUG=loopback:connector:mongodb
it appears the request to the RoleMapping fails:
loopback:connector:mongodb all +5ms RoleMapping { where:
{ roleId: 58b5f81ce60625467c762913,
principalType: 'USER',
principalId: '58b5f81ce60625467c762910' },
limit: 1,
offset: 0,
skip: 0,
order: [ 'id' ] } null []
Check this:
loopbackio/loopback-connector-mongodb#327
from loopback-example-access-control.
I am also experiancing same problem, Any help will be appreciated
from loopback-example-access-control.
If you scaffolded then it should be ok, otherwise you need the solution here :
strongloop/loopback#3121 (comment)
If this does not work it could be because the example really only runs in memory. To run it in Mongo be aware that the hard coded simple ids e.g. 1, 2 ... in the form /server/views/project.ejs will not find your Mongo objectids.
So, you will need to edit form input values accordingly :
<input type="hidden" name="id" value="1">
to
<input type="hidden" name="id" value="[the object id from mongo]">
But, if you hack this, then you will need to edit the remote methods so that arg: id is a string not a number :
Project.remoteMethod('donate', { accepts: [ {arg: 'id', type: 'number'}
to
Project.remoteMethod('donate', { accepts: [ {arg: 'id', type: 'string'}
Perhaps this will help you get going.
from loopback-example-access-control.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS
file at the top-level of this repository.
from loopback-example-access-control.
Nygma297's comment works for
> node --version
v4.4.6
and
"loopback": "^3.0.0",
"loopback-boot": "^2.6.5",
"loopback-component-explorer": "^4.0.0",
"loopback-connector-mysql": "^5.2.0",
from loopback-example-access-control.
The issue still exits, any help will be appreciated
from loopback-example-access-control.
Same track, no solution found for this?
from loopback-example-access-control.
Am equally stuck with the same problem...any solution?
from loopback-example-access-control.
Guys i keep with the problem, even adding options to every of my models.
"options": {
"strictObjectIDCoercion": true
},
maybe i not understand exactly what i need to do.
i need just put the options on my models, or i need to change my role and role mapping model to use memoryDS ?
from loopback-example-access-control.
Related Issues (20)
- User creation HOT 2
- User model present in model-config.json HOT 11
- The roles aren't getting into the Coded ACL. HOT 6
- info about executing "lb relation" is missing HOT 1
- ValidationError: The `user` instance is not valid. Details: `email` is invalid (value: "[email protected]") HOT 4
- Sample with mongo db connection not working as expected HOT 2
- Access Control Bug? HOT 3
- Define role for inbuilt models HOT 2
- automigrate to mongoDB HOT 2
- There is an error in the withdraw remote definition HOT 2
- How to emit this function : Role.registerResolver(role, resolver)?
- Weird relation between the model team and user HOT 3
- how do I apply ACL based permission rather then roles
- How to create a Model names 'device', that a user owns that deivce. HOT 1
- role-resolver.js HOT 2
- Is it possible to filter the projects owned by an owner without adding additional API? HOT 1
- ACL for third-party login HOT 2
- Readme 'Tutorial' links broken HOT 2
- Cannot read property 'registerResolver' of undefined HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loopback-example-access-control.