simov / grant

OAuth Proxy
MIT License
4.08k stars 257 forks source link

Grant does not work with Koa 2 #74

Closed frxstrem closed 7 years ago

frxstrem commented 7 years ago

Grant is incompatible with Koa 2 (which is the current version of Koa).

This is the code I'm using to test:

const Koa = require('koa');
const session = require('koa-session');
const mount = require('koa-mount');

const Grant = require('grant-koa');

const app = new Koa();
app.listen(8000);

app.keys = [ 'b39bfe95' ];

app.use(session(app));

const grant = new Grant({
  server: {
    protocol: 'http',
    host: 'localhost:8000',
  },
  github: {
    key: '[CLIENT_ID]',
    secret: '[CLIENT_SECRET]',
    scope: [ 'user:email', 'repo' ],
  },
});
app.use(mount(grant));

When using old versions of the dependencies (koa@1, koa-mount@1, koa-session@1), this code works as expected when accessing /connect/github, but when using the newest versions of each dependency, I only get the message Not Found (as if Koa ignores the Grant completely).

I've tried replacing github with other providers (such as facebook), to no avail.

Here's the complete list of versions:

{
  "dependencies": {
    "grant-koa": "3.7.1",
    "koa": "2.2.0",
    "koa-mount": "3.0.0",
    "koa-session": "5.0.0"
  }
}
simov commented 7 years ago

Hi @frxstrem, thanks for the detailed bug report!

Grant supports Koa2.x, I used this example with your dependency versions.

Your app.listen(8000); line looks out of place, it's a good idea to put it at the bottom. Let me know if it works that way.

frxstrem commented 7 years ago

Thanks, putting that line at the bottom seemed to work!