Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c84c73b9b1
Fetching contributors…

Cannot retrieve contributors at this time

file 54 lines (42 sloc) 1.374 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
express = require 'express'
everyauth = require 'everyauth'

everyauth.debug = true;

options =
  host: 'http://localhost:3000'
  id: '-- client id --'
  secret: '-- client secret --'

current = token = null

everyauth.github.myHostname options.host
everyauth.github.redirectPath '/'
everyauth.github.apiHost 'https://api.github.com'
everyauth.github.appId options.id
everyauth.github.appSecret options.secret
everyauth.github.scope 'gist'

everyauth.github.findOrCreateUser (session, accessToken, accessTokenExtra, user) ->
  [token, current] = [accessToken, user]

everyauth.github.fetchOAuthUser (accessToken) ->
  p = @Promise()
  @oauth.get @apiHost() + '/user', accessToken, (error, data) ->
    return p.fail error if error
    oauthUser = JSON.parse data
    p.fulfill oauthUser
  p

app = express.createServer()

app.use express.bodyParser()
app.use express.cookieParser()
app.use express.session secret: 'node-gisty'
app.use everyauth.middleware()

app.set 'views', __dirname + '/views'
app.set 'view engine', 'ejs'
app.set 'view options', layout: false

app.get '/', (request, response) ->
  if not request.loggedIn
    response.render 'login'
  else
    response.render 'result'
      login: current.login
      name: current.name
      token: token

everyauth.helpExpress app

app.listen 3000
console.log 'Go to ' + options.host
Something went wrong with that request. Please try again.