   CONTENT_ATTR = '''content=['"](.+)['"]'''
   ///#{NAME_ATTR}\s*#{CONTENT_ATTR}|#{CONTENT_ATTR}\s*#{NAME_ATTR}///
 
+# We don't want to wait until the token is already expired before refreshing it.
+TOKEN_EXPIRATION_ALLOWANCE = 10 * 1000
+
 module.exports = new Model
   _currentUserPromise: null
   _bearerToken: ''
+  _bearerRefreshTimeout: NaN
 
   _getAuthToken: ->
     console?.log 'Getting auth token'


      makeHTTPRequest 'POST', config.host + '/oauth/token', data, JSON_HEADERS
        .then (request) =>
          response = JSON.parse request.responseText
          @_bearerToken = response.access_token
          client.headers['Authorization'] = "Bearer #{@_bearerToken}"
          console?.info 'Got bearer token', @_bearerToken
          @_bearerToken

        .catch (request) ->
          # You're probably not signed in.
          console?.error 'Failed to get bearer token'
          client.handleError request

  _deleteBearerToken: ->
    @_bearerToken = ''
    delete client.headers['Authorization']
    console?.log 'Deleted bearer token'

  _getSession: ->

config = require './config'
client = require './client'

# Use this to override the default API-specific headers.
JSON_HEADERS =
  'Content-Type': 'application/json'
  'Accept': 'application/json'
