Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
# Koa Session Example | ||
|
||
|
||
## Install | ||
|
||
```bash | ||
$ cd examples/koa-session | ||
$ npm install | ||
``` | ||
|
||
## OAuth Application | ||
|
||
Create OAuth application for Facebook and set the application domain to be `dummy.com` | ||
|
||
In your `hosts` file add this line `dummy.com 127.0.0.1` | ||
|
||
|
||
## Configure | ||
|
||
Edit the `config.json` file with your own OAuth application credentials | ||
|
||
|
||
## Run the App | ||
|
||
You need at least NodeJS version 11 or higher! | ||
|
||
```bash | ||
$ node --harmony koa-session.js | ||
$ node --harmony koa-generic-session-redis.js | ||
$ node --harmony koa-generic-session-mongo.js | ||
$ node --harmony koa-session-store.js | ||
$ node --harmony koa-session-store-mongo.js | ||
``` | ||
|
||
## Start the Flow | ||
|
||
To start the OAuth flow for Facebook navigate to `http://dummy.com:3000/connect/facebook` in your browser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"server": { | ||
"protocol": "http", | ||
"host": "dummy.com:3000" | ||
}, | ||
"facebook": { | ||
"key": "[APP_ID]", | ||
"secret": "[APP_SECRET]", | ||
"callback": "/handle_facebook_callback", | ||
"scope": [ | ||
"user_groups", | ||
"user_likes" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
// https://github.com/koajs/generic-session | ||
// https://github.com/freakycue/koa-generic-session-mongo | ||
|
||
var koa = require('koa') | ||
, route = require('koa-route') | ||
, mount = require('koa-mount') | ||
, session = require('koa-generic-session') | ||
, MongoStore = require('koa-generic-session-mongo') | ||
|
||
var Grant = require('grant-koa') | ||
, grant = new Grant(require('./config.json')) | ||
|
||
var app = koa() | ||
app.keys = ['whatever'] | ||
app.use(session({ | ||
store: new MongoStore() | ||
})) | ||
app.use(mount(grant)) | ||
|
||
app.use(route.get('/handle_facebook_callback', function* (next) { | ||
console.log(this.query) | ||
this.body = JSON.stringify(this.query, null, 2) | ||
})) | ||
|
||
app.listen(3000, function() { | ||
console.log('Koa server listening on port ' + 3000) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
// https://github.com/koajs/generic-session | ||
// https://github.com/koajs/koa-redis | ||
|
||
var koa = require('koa') | ||
, route = require('koa-route') | ||
, mount = require('koa-mount') | ||
, session = require('koa-generic-session') | ||
, redisStore = require('koa-redis') | ||
|
||
var Grant = require('grant-koa') | ||
, grant = new Grant(require('./config.json')) | ||
|
||
var app = koa() | ||
app.keys = ['whatever'] | ||
app.use(session({ | ||
store: redisStore() | ||
})) | ||
app.use(mount(grant)) | ||
|
||
app.use(route.get('/handle_facebook_callback', function* (next) { | ||
console.log(this.query) | ||
this.body = JSON.stringify(this.query, null, 2) | ||
})) | ||
|
||
app.listen(3000, function() { | ||
console.log('Koa server listening on port ' + 3000) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
// https://github.com/hiddentao/koa-session-store | ||
// https://github.com/hiddentao/koa-session-mongo | ||
|
||
var koa = require('koa') | ||
, route = require('koa-route') | ||
, mount = require('koa-mount') | ||
, session = require('koa-session-store') | ||
, mongoStore = require('koa-session-mongo') | ||
|
||
var Grant = require('grant-koa') | ||
, grant = new Grant(require('./config.json')) | ||
|
||
var app = koa() | ||
app.keys = ['whatever'] | ||
app.use(session({ | ||
store: mongoStore.create({ | ||
db: 'test' | ||
}) | ||
})) | ||
app.use(mount(grant)) | ||
|
||
app.use(route.get('/handle_facebook_callback', function* (next) { | ||
console.log(this.query) | ||
this.body = JSON.stringify(this.query, null, 2) | ||
})) | ||
|
||
app.listen(3000, function() { | ||
console.log('Koa server listening on port ' + 3000) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
// https://github.com/hiddentao/koa-session-store | ||
|
||
var koa = require('koa') | ||
, route = require('koa-route') | ||
, mount = require('koa-mount') | ||
, session = require('koa-session-store') | ||
|
||
var Grant = require('grant-koa') | ||
, grant = new Grant(require('./config.json')) | ||
|
||
var app = koa() | ||
app.keys = ['whatever'] | ||
app.use(session()) | ||
app.use(mount(grant)) | ||
|
||
app.use(route.get('/handle_facebook_callback', function* (next) { | ||
console.log(this.query) | ||
this.body = JSON.stringify(this.query, null, 2) | ||
})) | ||
|
||
app.listen(3000, function() { | ||
console.log('Koa server listening on port ' + 3000) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
// https://github.com/koajs/session | ||
|
||
var koa = require('koa') | ||
, route = require('koa-route') | ||
, mount = require('koa-mount') | ||
, session = require('koa-session') | ||
|
||
var Grant = require('grant-koa') | ||
, grant = new Grant(require('./config.json')) | ||
|
||
var app = koa() | ||
app.keys = ['whatever'] | ||
app.use(session(app)) | ||
app.use(mount(grant)) | ||
|
||
app.use(route.get('/handle_facebook_callback', function* (next) { | ||
console.log(this.query) | ||
this.body = JSON.stringify(this.query, null, 2) | ||
})) | ||
|
||
app.listen(3000, function() { | ||
console.log('Koa server listening on port ' + 3000) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "grant-koa-session-example", | ||
"version": "0.0.0", | ||
"description": "Koa Session Example", | ||
"private": true, | ||
|
||
"keywords": [], | ||
|
||
"license": "MIT", | ||
"homepage": "https://github.com/simov/grant", | ||
|
||
"author": "Simeon Velichkov <simeonvelichkov@gmail.com> (http://simov.github.io)", | ||
|
||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/simov/grant.git" | ||
}, | ||
|
||
"dependencies": { | ||
"koa" : "0.14.0", | ||
"koa-route" : "2.4.0", | ||
"koa-mount" : "1.3.0", | ||
|
||
"koa-session" : "3.0.0", | ||
|
||
"koa-generic-session" : "1.8.0", | ||
"koa-generic-session-mongo" : "0.1.1", | ||
"koa-redis" : "1.0.0", | ||
|
||
"koa-session-store" : "1.1.1", | ||
"koa-session-mongo" : "1.0.1", | ||
|
||
"grant-koa" : "*" | ||
}, | ||
|
||
"main": "koa-session.js" | ||
} |