(request, default=DIGEST)
return default
Guess the auth type, based on the headers found in the request.

    If default is set to something other than DIGEST, digest auth will not work

    CommCare mobile sends an unauthenticated request first, and we need to
    issue a basic auth challenge in response. This means we can't support both
    CommCare mobile and digest auth at the same endpoint (since digest auth
    requires a digest auth challenge).

    For non-mobile endpoints (such as APIs), we can support basic, digest,
    token, and apikey by defaulting to digest, since in all other cases, the
    client should send the initial request with an Authorization header.
Guess the auth type, based on the headers found in the request.
Guess the auth type based on the headers found in the request .
def determine_authtype_from_header(request, default=DIGEST):
    """
    Guess the auth type, based on the headers found in the request.

    If default is set to something other than DIGEST, digest auth will not work

    CommCare mobile sends an unauthenticated request first, and we need to
    issue a basic auth challenge in response. This means we can't support both
    CommCare mobile and digest auth at the same endpoint (since digest auth
    requires a digest auth challenge).

    For non-mobile endpoints (such as APIs), we can support basic, digest,
    token, and apikey by defaulting to digest, since in all other cases, the
    client should send the initial request with an Authorization header.
    """
    auth_header = (request.META.get('HTTP_AUTHORIZATION') or '').lower()
    if auth_header.startswith('basic '):
        return BASIC
    elif auth_header.startswith('digest '):
        # Note: this will not identify initial, uncredentialed digest requests
        return DIGEST
    elif auth_header.startswith('bearer '):
        return OAUTH2
    elif _is_api_key_authentication(request):
        return API_KEY

    if request.META.get('HTTP_X_MAC_DIGEST', None):
        return FORMPLAYER

    return default
def determine_authtype_from_header ( request , default = DIGEST ) : auth_header = ( request . META . get ( 'HTTP_AUTHORIZATION' ) or '' ) . lower ( ) if auth_header . startswith ( 'basic ' ) : return BASIC elif auth_header . startswith ( 'digest ' ) : # Note: this will not identify initial, uncredentialed digest requests return DIGEST elif auth_header . startswith ( 'bearer ' ) : return OAUTH2 elif _is_api_key_authentication ( request ) : return API_KEY if request . META . get ( 'HTTP_X_MAC_DIGEST' , None ) : return FORMPLAYER return default