     if err && err.name != "NoSuchThingError"
       callback err
     else
-      if cot && Date.parse(cot.expiresAt) > (Date.now() + ONE_HOUR)
+      if cot && !cot.expired()
         callback null, cot.token
       else
         params =


  callback null

ONE_HOUR = 1000 * 60 * 60

ClientOnlyToken.ensure = (clientID, clientSecret, callback) ->

              cot = new ClientOnlyToken({clientID: clientID})
            cot.token = results.access_token
            # XXX: expiration in seconds or milliseconds?
            if _.isNumber results.expires_in
              expiresAt = new Date(Date.now() + (results.expires_in * 1000))
              cot.expiresAt = expiresAt.toISOString()

            cot.save (err) ->
              if err
                callback err
              else
                callback null, cot.token

module.exports = ClientOnlyToken
