Giter VIP home page Giter VIP logo

Comments (22)

Nygma297 avatar Nygma297 commented on August 18, 2024 9

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.

BuchyOne avatar BuchyOne commented on August 18, 2024 3

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.

sminodonte avatar sminodonte commented on August 18, 2024 3

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.

BuchyOne avatar BuchyOne commented on August 18, 2024 2

@Nygma297

Some solutions, the first breaks production:
strongloop/loopback#3121 (comment)
strongloop/loopback#3121 (comment)
strongloop/loopback#3121 (comment)

from loopback-example-access-control.

sminodonte avatar sminodonte commented on August 18, 2024 2

Any insights will be appreciated, thanks

from loopback-example-access-control.

emazzu avatar emazzu commented on August 18, 2024 2

I m the same problem !!!!

from loopback-example-access-control.

Nygma297 avatar Nygma297 commented on August 18, 2024 1

@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.

wangdandong avatar wangdandong commented on August 18, 2024 1

a solution, see #94 (comment)

strongloop/loopback#3121 (comment)

from loopback-example-access-control.

wangdandong avatar wangdandong commented on August 18, 2024

@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.

Nygma297 avatar Nygma297 commented on August 18, 2024

Can you post the datasources.js file?

from loopback-example-access-control.

wangdandong avatar wangdandong commented on August 18, 2024

@Nygma297

{
  "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.

Nygma297 avatar Nygma297 commented on August 18, 2024

@BuchyOne

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.

BuchyOne avatar BuchyOne commented on August 18, 2024

@Nygma297

No, it does not resolve the issue.

I will debug and if successful get back.

from loopback-example-access-control.

BuchyOne avatar BuchyOne commented on August 18, 2024

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.

YSTomar avatar YSTomar commented on August 18, 2024

I am also experiancing same problem, Any help will be appreciated

from loopback-example-access-control.

BuchyOne avatar BuchyOne commented on August 18, 2024

@YSTomar @sminodonte

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.

stale avatar stale commented on August 18, 2024

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.

quinnliu avatar quinnliu commented on August 18, 2024

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.

kuongknight avatar kuongknight commented on August 18, 2024

The issue still exits, any help will be appreciated

from loopback-example-access-control.

anupammaurya avatar anupammaurya commented on August 18, 2024

Same track, no solution found for this?

from loopback-example-access-control.

felixia avatar felixia commented on August 18, 2024

Am equally stuck with the same problem...any solution?

from loopback-example-access-control.

marcus-gomes-v avatar marcus-gomes-v commented on August 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.