def tokenFromRequest(request):
    """Extract token from header of query parameter.

    :param request: The request to look for an access token in.
    :type request: twisted.web.server.Request

    :return: The token or None if not found
    :rtype: unicode or None
    """
    token = None
    authHeader = request.getHeader('Authorization')
    if authHeader is not None and authHeader.startswith('Bearer '):
        token = authHeader[len('Bearer '):]
    if token is None and 'access_token' in request.args:
        token = request.args['access_token'][0]
    if token and isinstance(token, bytes):
        token = token.decode('UTF-8')
    return token
