strongloop / loopback-component-oauth2

oAuth 2.0 server for LoopBack
http://www.strongloop.com
Other
62 stars 63 forks source link

Models are not attaching to the db #57

Closed remotevision closed 7 years ago

remotevision commented 7 years ago

Bug or feature request

Description of feature (or steps to reproduce if bug)

When setting up an OAuth2 server, it appears the models are not being attached to the db. I have tried this a few different ways, including adding it to the model-config.json

  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models",
      "./node_modules/loopback-component-oauth2/lib/models",
      "./node_modules/loopback-component-passport/lib/models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "loopback/server/mixins",
      "../common/mixins",
      "./mixins"
    ]
  },

Link to sample repo to reproduce issue (if bug)

I created a gist that shows all of the relevant code and configurations. https://gist.github.com/remotevision/9bd478e08ce97929c69527dcff4e6a0d

Actual result (if bug)

a trace of the models.

$ DEBUG=loopback:oauth2 node .
------------------------------------------------
[sample-data]: Initializing
[sample-data]: create users 1
[sample-data]: create applications 1
Client application registered: id=123 name=test-app key=secret
User registered: id=1 username=bob password=secret
------------------------------------------------
[oAuth]: Initialized
Web server listening at: http://localhost:3000
Browse your REST API at http://localhost:3000/explorer
  loopback:oauth2 model: +0ms User
  loopback:oauth2 model: +0ms Application
  loopback:oauth2 model: +1ms AccessToken
  loopback:oauth2 model: +0ms ACL
  loopback:oauth2 model: +0ms RoleMapping
  loopback:oauth2 model: +0ms Role
  loopback:oauth2 clientLogin: bob +0ms
  loopback:oauth2 clientSecret: secret +0ms

Additional information (Node.js version, LoopBack version, etc)

I am using,

remotevision commented 7 years ago

Not a bug. This was fixed by removing the component config from oauth.js and adding it to the component-config.json

 // component-config.json
  "loopback-component-oauth2": {
    "dataSource": "db"
  }
juaneduardodelgado commented 7 years ago

hi @remotevision,

Do you mind sharing the sources to see how you configured the component. I have been trying to follow your steps but I can't make it work, always got an authorized.

I think I'm missing the Application entry as I haven't been able to use your sample-data.json. I have been trying with a seed script in the boot folder, but I can't find the model to insert the App entry (I just started playing with loopback 2 days ago).

Thanks

remotevision commented 7 years ago

@juaneduardodelgado yes, I'll create a standalone project and put it on github. you should know that I only needed it for clientCredentials