ubilogix / koa2-oauth-server

Koa 2 wrapper for node-oauth2-server.
19 stars 4 forks source link

options.headers.hasOwnProperty is not a function #3

Open fjeddy opened 5 years ago

fjeddy commented 5 years ago

Add the popular cors module to your koa setup, or add a middleware changing the headers

use( async ( ctx, next ) => {
    ctx.set( 'Access-Control-Allow-Origin', '*' )
    await next()
} )

Will instantly result in

TypeError: options.headers.hasOwnProperty is not a function
      at new Response (/home/*/api/node_modules/oauth2-server/lib/response.js:16:25)
      at /home/*/api/node_modules/ubx-koa2-oauth2-server/index.js:61:30
      at dispatch (/home/*/api/node_modules/koa-router/node_modules/koa-compose/index.js:44:32)
      at next (/home/*/api/node_modules/koa-router/node_modules/koa-compose/index.js:45:18)
      at routes.get (/home/*/api/src/routes.js:42:14)
 .....

Related issues with oauth2-server

https://github.com/oauthjs/node-oauth2-server/pull/430 https://github.com/oauthjs/node-oauth2-server/issues/413

64bits commented 3 years ago

I worked around this by setting the header after the rest of the middleware:

use( async ( ctx, next ) => {
    await next();
    ctx.set( 'Access-Control-Allow-Origin', '*' );
} )