Generates the error header for a request using a Bearer token based on a given OAuth exception.

def request_error_header(exception):
    """
    Generates the error header for a request using a Bearer token based on a given OAuth exception.
    """

    from .conf import options
    
    header = "Bearer realm=\"%s\"" % (options.realm, )
    
    if hasattr(exception, "error"):
        header = header + ", error=\"%s\"" % (exception.error, )
    
    if hasattr(exception, "reason"):
        header = header + ", error_description=\"%s\"" % (exception.reason, )
    
    return header