def METHOD_NAME(request):
    Application = get_application_model()
    client_id, ac, app = None, None, None
    if request.GET.get("client_id", None) is not None:
        client_id = request.GET.get("client_id", None)
    elif request.POST.get("client_id", None):
        client_id = request.POST.get("client_id", None)
    elif request.POST.get("token", None):
        # introspect
        ac = AccessToken.objects.get(token=request.POST.get("token", None))
    try:
        if client_id is not None:
            app = Application.objects.get(client_id=client_id)
        elif ac is not None:
            app = Application.objects.get(id=ac.application_id)
        if app and not app.active:
            raise InvalidClientError(
                description=settings.APPLICATION_TEMPORARILY_INACTIVE.format(app.name)
            )
    except Application.DoesNotExist:
        pass
    if app and app.active:
        # Check for application RESEARCH_STUDY type end_date expired.
        if app.has_research_study_expired():
            raise InvalidClientError(
                description=settings.APPLICATION_RESEARCH_STUDY_ENDED_MESG
            )
        # Is this for a token refresh request?
        post_grant_type = request.POST.get("grant_type", None)
        if post_grant_type == "refresh_token":
            # Check for application ONE_TIME type where token refresh is not allowed.
            if app.has_one_time_only_data_access():
                raise InvalidClientError(
                    description=settings.APPLICATION_ONE_TIME_REFRESH_NOT_ALLOWED_MESG
                )
            # Check if data access grant is expired for THIRTEEN_MONTH app type?
            if hasattr(request, 'user'):
                if not request.user.is_anonymous:
                    try:
                        dag = DataAccessGrant.objects.get(
                            beneficiary=request.user,
                            application=app
                        )
                        if dag:
                            if dag.has_expired():
                                raise InvalidClientError(
                                    description=settings.APPLICATION_THIRTEEN_MONTH_DATA_ACCESS_EXPIRED_MESG
                                )
                    except DataAccessGrant.DoesNotExist:
                        pass
    return app