Closed mvaullerin closed 7 years ago
Can you show me the code in server/server.js? It seems that the User
model hasn't been attached to a data source yet.
var loopback = require('loopback');
var boot = require('loopback-boot');
var oauth2 = require('loopback-component-oauth2');
var app = module.exports = loopback();
app.start = function() {
// start the web server
return app.listen(function() {
app.emit('started');
console.log('Web server listening at: %s', app.get('url'));
});
};
// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function(err) {
if (err) throw err;
var options = {
dataSource: app.dataSources.db, // Data source for oAuth2 metadata persistence
loginPage: '/login', // The login page url
loginPath: '/login' // The login form processing url
};
oauth2.oAuth2Provider(
app, // The app instance
options // The options
);
// start the server if `$ node server.js`
if (require.main === module)
app.start();
});
@KCypher13, I see this is an old issue, but I'm just wondering if you got it resolved or not?
@KCypher13, I'm going to close this issue. Please re-open and mention me in a comment if the issue persists.
Hello @richardpringle ! I'm having the same problem right now, any ideas ? Thanks
Hey @Samox, best thing to do is to fork the loopback-sandbox and reproduce the issue in there so that I can clone and take a look myself.
I'll re-open the issue for now since you are still running into it.
I am having the same issue...
This OAuth2 implementation shouldn't be in the LB 3.0 docs if no one is going to support it.
This problem is caused when you either didn't use the User model or at least extend the User model. As soon as I had my Client model extend User it started to work.
@deviant32, you can see the dependency here: https://github.com/strongloop/loopback-component-oauth2/blob/master/lib/models/index.js#L26
@richardpringle Why wouldn't this be in the documentation?
@deviant32, not sure, I don't actually work on this project anymore. @crandmck, looks like this is an issue for you (and if not, I'm guessing you'll know where to assign it).
AFAIK, OAuth component is still supported, but I need to confirm.
Confirmed this component is still supported.
... either didn't use the User model or at least extend the User model. As soon as I had my Client model extend User it started to work.
So, docs should just say that to use this component, the app must have a User model or model that extends User?
Yeah @crandmck, I would just add that somewhere as a disclaimer.
@crandmck It will work if one of your models is already extending the User model. If you do not have any models extending User, then you have to specify in the options what model to set as the User model.
It worked once I did this, however I am not stuck on another problem. I cannot generate any access tokens when I make a request to /oauth/authorize.
OK, thanks. I created a separate doc issue. As I delved into it, I also found additional options that may need to be documented.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
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.
Hi guys,
I've tried to install oauth2 component on a fresh install of loopback and I got this error :
I just add the following code in the callback of boot in server.js (+require at the begining):
Any idea ?
Thanks in advance