Python 3: Fix an str vs bytes issue in tempfile

In Python 3, one cannot write:

    from tempfile import NamedTemporaryFile
    with NamedTemporaryFile() as f:
        f.write('foobar')

The input of f.write() must be bytes. Encode it when necessary in
middleware/auth_token.py, in a way that is compatible with Python 2.

Change-Id: Ib60afbc5e01c35f59cd7c9b68bfedb10ad897ff9
Test commit