import re


def _negotiate_value(r):
    """Extracts the gssapi authentication token from the appropriate header"""

    authreq = r.headers.get('www-authenticate', None)

    if authreq:
        rx = re.compile('(?:.*,)*\s*Negotiate\s*([^,]*),?', re.I)
        mo = rx.search(authreq)
        if mo:
            return mo.group(1)

    return None