def METHOD_NAME(request):
    session_state = request.session.pop(SESSION_STATE, None)
    if request.GET.get("error") == "access_denied":
        raise exceptions.OAuth2AccessDeniedError()
    if not session_state:
        raise exceptions.OAuth2StateNotSetError()
    provider_state = request.GET.get("state")
    if not provider_state:
        raise exceptions.OAuth2StateNotProvidedError()
    if provider_state != session_state:
        raise exceptions.OAuth2StateMismatchError()
    code_grant = request.GET.get("code")
    if not code_grant:
        raise exceptions.OAuth2CodeNotProvidedError()
    return code_grant