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

TypeError: Cannot read property 'set' of undefined #29

Open
wehriam opened this issue Mar 18, 2015 · 4 comments
Open

TypeError: Cannot read property 'set' of undefined #29

wehriam opened this issue Mar 18, 2015 · 4 comments

Comments

@wehriam
Copy link

wehriam commented Mar 18, 2015

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: thomseddon/node-oauth2-server@c19719e

@babsonmatt
Copy link

@wehriam just ran into this issue as well

@babsonmatt
Copy link

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.

@larron
Copy link

larron commented Apr 15, 2015

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);

@aguegu
Copy link

aguegu commented Apr 20, 2015

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

thomseddon added a commit to oauthjs/node-oauth2-server that referenced this issue May 17, 2015
laverite pushed a commit to laverite/koa-oauth-server that referenced this issue Jun 20, 2015
night pushed a commit to night/node-oauth2-server that referenced this issue Jan 19, 2021
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

4 participants