Permalink
Browse files

adding github authentication

  • Loading branch information...
1 parent f83a3bd commit fd1829a42fcbcb2f851d60ac3a9491793a4ded9c Nic Luciano committed Nov 4, 2011
Showing with 32 additions and 6 deletions.
  1. +1 −0 .gitignore
  2. +24 −5 app.coffee
  3. +4 −0 keys.coffee
  4. 0 public/{index.html → app.html}
  5. +3 −1 public/js/brain.js
View
@@ -0,0 +1 @@
+node_modules
View
@@ -1,22 +1,41 @@
# deps
fs = require 'fs'
connect = require 'connect'
+auth = require 'connect-auth'
+login = require './lib/login'
proxy = require './lib/tinyproxy'
# stuff
connect_server = connect.createServer()
+connect_server.use connect.cookieParser()
connect_server.use connect.bodyParser()
+connect_server.use connect.session secret: 'lol'
connect_server.use connect.static __dirname + '/public'
# ajax proxy
connect_server.use proxy '^/v3(/.+)', 'api.github.com'
-# serve page
+# github auth
+connect_server.use auth strategies: [auth.Github require './keys']
+connect_server.use login()
+
+# serve app
connect_server.use connect.router (app) ->
+
+ # logout
+ app.get '/logout', (req, res, next) ->
+ req.logout()
+
+ # main page
app.get '/', (req, res, next) ->
- res.writeHead 200,
- 'Content-Type': 'text/html'
- res.end fs.readFileSync __dirname + '/public/index.html'
+
+ res.writeHead 200, 'Content-Type': 'text/html'
+
+ if req.isAuthenticated()
+ res.end fs.readFileSync __dirname + '/public/app.html'
+
+ else
+ res.end '<a href="/login">login</a>'
# start server
-connect_server.listen 8080
+connect_server.listen 8000
View
@@ -0,0 +1,4 @@
+module.exports =
+ appId: '346f1cc5045e730c696a'
+ appSecret: 'cca6c730e7b661098033b643d880b35706e777fa'
+ callback: 'http://localhost:8000/login'
File renamed without changes.
View
@@ -1,3 +1,5 @@
+/*
$.get('/repos/catshirt/nautical2', function(d) {
console.log('hello world', d);
-});
+});
+*/

0 comments on commit fd1829a

Please sign in to comment.