我正在尝试将everyauth 与Google OAuth2 一起使用,并且我只想在Google 向我发送我公司的Google Apps 域中的用户时才能成功进行身份验证。我不知道如何根据 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