koa-oauth-server icon indicating copy to clipboard operation
koa-oauth-server copied to clipboard

TypeError: Cannot read property 'set' of undefined

Open wehriam opened this issue 9 years ago • 4 comments

Version 2.4.0 of node-oauth2-server seems to have introduced a breaking change. I'll provide more information as soon as I can.

 TypeError: Cannot read property 'set' of undefined
      at Grant.sendResponse (/Users/johnwehr/Projects/test-project/node_modules/koa-oauth-server/node_modules/oauth2-server/lib/grant.js:471:5)
      at run (/Users/johnwehr/Projects/test-project/node_modules/koa-oauth-server/node_modules/oauth2-server/lib/runner.js:15:14)
      at /Users/johnwehr/Projects/test-project/node_modules/koa-oauth-server/node_modules/oauth2-server/lib/runner.js:17:7
      at Grant.saveRefreshToken (/Users/johnwehr/Projects/test-project/node_modules/koa-oauth-server/node_modules/oauth2-server/lib/grant.js:430:29)
      at run (/Users/johnwehr/Projects/test-project/node_modules/koa-oauth-server/node_modules/oauth2-server/lib/runner.js:15:14)
      at /Users/johnwehr/Projects/test-project/node_modules/koa-oauth-server/node_modules/oauth2-server/lib/runner.js:17:7
      at Grant.generateRefreshToken (/Users/johnwehr/Projects/test-project/node_modules/koa-oauth-server/node_modules/oauth2-server/lib/grant.js:412:66)
      at run (/Users/johnwehr/Projects/test-project/node_modules/koa-oauth-server/node_modules/oauth2-server/lib/runner.js:15:14)
      at /Users/johnwehr/Projects/test-project/node_modules/koa-oauth-server/node_modules/oauth2-server/lib/runner.js:17:7
      at /Users/johnwehr/Projects/test-project/node_modules/koa-oauth-server/node_modules/oauth2-server/lib/grant.js:401:5
      at /Users/johnwehr/Projects/test-project/models/oauth2-model.js:62:7

The offending function:

/**
 * Create an access token and save it with the model
 *
 * @param  {Function} done
 * @this   OAuth
 */
function sendResponse (done) {
  var response = {
    token_type: 'bearer',
    access_token: this.accessToken
  };

  if (this.config.accessTokenLifetime !== null) {
    response.expires_in = this.config.accessTokenLifetime;
  }

  if (this.refreshToken) response.refresh_token = this.refreshToken;

  this.res
    .set('Cache-Control', 'no-store') // Line 471
    .set('Pragma', 'no-cache')
    .jsonp(response);

  if (this.config.continueAfterResponse)
    done();
}

See the commit: https://github.com/thomseddon/node-oauth2-server/commit/c19719e68625e2c568f09e30d2f264debfa3fcee

wehriam avatar Mar 18 '15 04:03 wehriam

@wehriam just ran into this issue as well

babsonmatt avatar Apr 06 '15 21:04 babsonmatt

Replacing

this.res
    .set('Cache-Control', 'no-store') // Line 471
    .set('Pragma', 'no-cache')
    .jsonp(response);

with

this.res
    .set({
      'Cache-Control': 'no-store',
      'Pragma': 'no-cache'
    });
this.res.jsonp(response);

Seems to remedy the problem.

babsonmatt avatar Apr 07 '15 05:04 babsonmatt

Got me as well. @babsonmatt for whatever reason your fix didn't work for me but this did seem to fix it:

  this.res.header['Cache-Control'] = 'no-store';
  this.res.header['Pragma'] = 'no-cache';
  this.res.jsonp(response);

larron avatar Apr 15 '15 05:04 larron

run into this issue too. Wish node-oauth2-server would release a upgrade soon. @babsonmatt 's solution works for me.

aguegu avatar Apr 20 '15 14:04 aguegu