I'm trying to use everyauth with Google OAuth2, and I only want authentication to succeed if Google sends me a user in my company's Google Apps domain. I can't figure out how to gracefully abort authentication based on arguments to findOrCreateUser.
express = require "express"
everyauth = require "everyauth"
app = express()
nextUserId = 0
usersById = {}
app.get "/", (req, res) ->
res.send "Secret"
everyauth.everymodule
.findUserById (id, callback) ->
callback null, usersById[id]
everyauth.google
.appId(process.env.GOOGLE_CLIENT_ID)
.appSecret(process.env.GOOGLE_CLIENT_SECRET)
.scope("...")
.redirectPath("/")
.findOrCreateUser (session, token, extra, googleUser) ->
# I want to abort authentication if googleUser.email != foo
# Redirecting to /unauthorized would be awesome but I don't know how
googleUser.id = nextUserId++
usersById[googleUser.id] = googleUser
app.use express.cookieParser()
app.use express.session { secret: "secret" }
app.use everyauth.middleware()
app.listen process.env.PORT