Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example fails to work - Invalid argument: model does not implement getClient() #38

Open
alexellis opened this issue Nov 30, 2016 · 13 comments

Comments

@alexellis
Copy link

Example in README at https://github.com/oauthjs/express-oauth-server fails to work with error:

{"error":"invalid_argument","error_description":"Invalid argument: model does not implement `getClient()`"}

If this isn't a complete example it would help to mention that and suggest what is needed to get this working. Node version: 6.x

@alexellis
Copy link
Author

I've also tried passing this as the model: https://github.com/oauthjs/express-oauth-server/tree/master/examples/memory

It was missing a method that needed to be added btw.. not sure if this is being kept up to date?

@stauvel
Copy link

stauvel commented Dec 23, 2016

I have the same issue.
I tried to replace model: memorystore, by model: new memorystore(), then I have another problem with this in the getClient().
Any idea ?

@AlessandroAnnini
Copy link

I have the same problem... any news about this?
Thanks

@chitkosarvesh
Copy link

chitkosarvesh commented May 31, 2017

After I implemented the solution from @stauvel's comment, I got another error:
{"error":"invalid_argument","error_description":"Invalid argument: model does not implement saveAuthorizationCode()"}
I checked the model and found that such a function indeed did not exist in the model.
I also went through the documentation for OAuth2-server here : https://oauth2-server.readthedocs.io/en/latest/model/spec.html#saveauthorizationcode-code-client-user-callback and found the implementation of the function. However, after that, it is giving me an error : {"error":"invalid_request","error_description":"Missing parameter: client_id"}
Someone please help!

@TheModFather
Copy link

@chitkosarvesh I was able to resolve the message of client_id missing by appending it to the URL on the post or by adding it to the body of the request. However, with the example I still get an error.

Unhandled rejection RangeError: Invalid status code: undefined at ServerResponse.writeHead (_http_server.js:188:11) at ServerResponse._implicitHeader (_http_server.js:179:8) at write_ (_http_outgoing.js:645:9) at ServerResponse.end (_http_outgoing.js:764:5) at ServerResponse.send (C:\development\authserver\node_modules\express\lib\response.js:211:10) at ServerResponse.json (C:\development\authserver\node_modules\express\lib\response.js:256:15) at ServerResponse.send (C:\development\authserver\node_modules\express\lib\response.js:158:21) at ExpressOAuthServer.handleError (C:\development\authserver\node_modules\express-oauth-server\index.js:157:9) at ExpressOAuthServer.<anonymous> (C:\development\authserver\node_modules\express-oauth-server\index.js:86:28) at ExpressOAuthServer.tryCatcher (C:\development\authserver\node_modules\express-oauth-server\node_modules\bluebird\js\release\util.js:16:23) at Promise._settlePromiseFromHandler (C:\development\authserver\node_modules\express-oauth-server\node_modules\bluebird\js\release\promise.js:512:31) at Promise._settlePromise (C:\development\authserver\node_modules\express-oauth-server\node_modules\bluebird\js\release\promise.js:569:18) at Promise._settlePromise0 (C:\development\authserver\node_modules\express-oauth-server\node_modules\bluebird\js\release\promise.js:614:10) at Promise._settlePromises (C:\development\authserver\node_modules\express-oauth-server\node_modules\bluebird\js\release\promise.js:689:18) at Async._drainQueue (C:\development\authserver\node_modules\express-oauth-server\node_modules\bluebird\js\release\async.js:133:16) at Async._drainQueues (C:\development\authserver\node_modules\express-oauth-server\node_modules\bluebird\js\release\async.js:143:10) at Immediate.Async.drainQueues (C:\development\authserver\node_modules\express-oauth-server\node_modules\bluebird\js\release\async.js:17:14) at runCallback (timers.js:800:20) at tryOnImmediate (timers.js:762:5) at processImmediate [as _immediateCallback] (timers.js:733:5)

@rxpande
Copy link

rxpande commented Aug 24, 2017

Getting same issue @earmbrust

Anyone working this ?

Can anyone share there implementation of OAuth2 Server with NodeJS ?

Thanks.

@waychan23
Copy link

@somdey
Copy link

somdey commented Oct 10, 2017

I can generate bearer token using "oauth2-server": "^2.4.1" without express-oauth-server. Working copy (https://github.com/smndey/nodeapp/tree/v3-mongo-oauth-server/server). However I am facing same issue if I use "express-oauth-server":"^2.0.0" and "oauth2-server": "^3.0.0". In oauth2-server -3.x they have improved many things (Promises instead of callback, Use new keyword to initialize oauth server etc) and based on that we have to change our models.

@dman777
Copy link

dman777 commented Oct 21, 2017

Hitting this issue also with the mongoose example

@xjwalker
Copy link

xjwalker commented Dec 5, 2017

I get
{
error: "invalid_argument",
error_description: "Invalid argument: model does not implement saveAuthorizationCode()"
}
With, I know this is saying that I should implement (write the "saveAuthorizationCode()" function) inside the model.js file, but still after that I get:
{
error: "invalid_request",
error_description: "Missing parameter: client_id"
}

Does anyone know a way to solve this?
I'm kind of stuck

@chitkosarvesh Have you found a solution?

@s-a
Copy link

s-a commented Apr 27, 2018

It seems you need to pass an with new instanced model.

const MemoryStore = require('./model.js')
const memoryStore = new MemoryStore()

app.oauth = new OAuthServer({
	model: memoryStore // See https://github.com/oauthjs/node-oauth2-server for specification
})

@kobi
Copy link

kobi commented Nov 27, 2018

The example is outdated. I debugged it for a couple of days, and finally got it to work:
https://gist.github.com/kobi/7c0b8196d8b585dcc62d71947f909342
The main issue was InMemoryCache.prototype.saveToken that has to return the token, the user, and the client.

I only tested it for client_credentials, which is the simplest grant type, and it seems to work nicely. Should I submit a pull request anyway?

@richardaum
Copy link

richardaum commented Feb 12, 2019

As @kobi well said, the provided sample is only implementing the authorize() endpoint. There are other two endpoints: token(), authenticate().
Take a look on https://tools.ietf.org/html/rfc6749#section-6 to know how to use them.

Even so, I didn't get why getClient is being called with null as client_screen even if I pass it into the request query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests