 #
 serializeUser = (user, done) ->
   user.fetch
+    data:
+      auth_token: user.get('access_token')
     success: ->
-      keys = ['accessToken'].concat opts.userKeys
+      keys = ['access_token'].concat opts.userKeys
       done null, user.pick(keys)
-    error: (m, e) -> done e.text
+    error: (m, e) ->
+      done e.text
 
 deserializeUser = (userData, done) ->
   done null, new opts.CurrentUser(userData)

  if req.user
    res.locals.user = req.user
    res.locals.sd?.CURRENT_USER = req.user.toJSON()
    res.locals.sd?.XAuthToken = req.user.get('authentication_token')
  next()

headerLogin = (req, res, next) ->
  if token = req.get('X-AUTH-TOKEN') or req.query.access_token
    req.login new opts.CurrentUser(accessToken: token), next
  else
    next()


initPassport = ->
  passport.serializeUser serializeUser
  passport.deserializeUser deserializeUser
  passport.use new LocalStrategy(
    { usernameField: 'email', passReqToCallback: true }
    arenaCallback
  )

#
# Passport callbacks
#
arenaCallback = (req, username, password, done) ->
  request.post("#{opts.SECURE_ARENA_URL}/tokens").query(
    email: username
    password: password
