def _third_party_auth_context(request): """Context for third party auth providers and the currently running pipeline. Arguments: request (HttpRequest): The request, used to determine if a pipeline is currently running. Returns: dict """ context = {"currentProvider": None, "providers": []} course_id = request.GET.get("course_id") login_urls = auth_pipeline_urls( third_party_auth.pipeline.AUTH_ENTRY_LOGIN_2, course_id=course_id) register_urls = auth_pipeline_urls( third_party_auth.pipeline.AUTH_ENTRY_REGISTER_2, course_id=course_id) if third_party_auth.is_enabled(): context["providers"] = [{ "name": enabled.NAME, "iconClass": enabled.ICON_CLASS, "loginUrl": login_urls[enabled.NAME], "registerUrl": register_urls[enabled.NAME] } for enabled in third_party_auth.provider.Registry.enabled()] running_pipeline = third_party_auth.pipeline.get(request) if running_pipeline is not None: current_provider = third_party_auth.provider.Registry.get_by_backend_name( running_pipeline.get('backend')) context["currentProvider"] = current_provider.NAME return context
def _third_party_auth_context(request): """Context for third party auth providers and the currently running pipeline. Arguments: request (HttpRequest): The request, used to determine if a pipeline is currently running. Returns: dict """ context = { "currentProvider": None, "providers": [] } course_id = request.GET.get("course_id") email_opt_in = request.GET.get('email_opt_in') login_urls = auth_pipeline_urls( third_party_auth.pipeline.AUTH_ENTRY_LOGIN_2, course_id=course_id, email_opt_in=email_opt_in ) register_urls = auth_pipeline_urls( third_party_auth.pipeline.AUTH_ENTRY_REGISTER_2, course_id=course_id, email_opt_in=email_opt_in ) if third_party_auth.is_enabled(): context["providers"] = [ { "name": enabled.NAME, "iconClass": enabled.ICON_CLASS, "loginUrl": login_urls[enabled.NAME], "registerUrl": register_urls[enabled.NAME] } for enabled in third_party_auth.provider.Registry.enabled() ] running_pipeline = third_party_auth.pipeline.get(request) if running_pipeline is not None: current_provider = third_party_auth.provider.Registry.get_by_backend_name( running_pipeline.get('backend') ) context["currentProvider"] = current_provider.NAME return context
def _third_party_auth_context(request): """Context for third party auth providers and the currently running pipeline. Arguments: request (HttpRequest): The request, used to determine if a pipeline is currently running. Returns: dict """ context = {"currentProvider": None, "providers": []} course_id = request.GET.get("course_id") email_opt_in = request.GET.get("email_opt_in") redirect_to = request.GET.get("next") # Check if the user is trying to enroll in a course # that they don't have access to based on country # access rules. # # If so, set the redirect URL to the blocked page. # We need to set it here, rather than redirecting # from within the pipeline, because a redirect # from the pipeline can prevent users # from completing the authentication process. # # Note that we can't check the user's country # profile at this point, since the user hasn't # authenticated. If the user ends up being blocked # by their country preference, we let them enroll; # they'll still be blocked when they try to access # the courseware. if course_id: try: course_key = CourseKey.from_string(course_id) redirect_url = embargo_api.redirect_if_blocked(course_key, ip_address=get_ip(request), url=request.path) if redirect_url: redirect_to = embargo_api.message_url_path(course_key, "enrollment") except InvalidKeyError: pass login_urls = auth_pipeline_urls( third_party_auth.pipeline.AUTH_ENTRY_LOGIN, course_id=course_id, email_opt_in=email_opt_in, redirect_url=redirect_to, ) register_urls = auth_pipeline_urls( third_party_auth.pipeline.AUTH_ENTRY_REGISTER, course_id=course_id, email_opt_in=email_opt_in, redirect_url=redirect_to, ) if third_party_auth.is_enabled(): context["providers"] = [ { "name": enabled.NAME, "iconClass": enabled.ICON_CLASS, "loginUrl": login_urls[enabled.NAME], "registerUrl": register_urls[enabled.NAME], } for enabled in third_party_auth.provider.Registry.enabled() ] running_pipeline = third_party_auth.pipeline.get(request) if running_pipeline is not None: current_provider = third_party_auth.provider.Registry.get_by_backend_name(running_pipeline.get("backend")) context["currentProvider"] = current_provider.NAME return context
def _third_party_auth_context(request): """Context for third party auth providers and the currently running pipeline. Arguments: request (HttpRequest): The request, used to determine if a pipeline is currently running. Returns: dict """ context = { "currentProvider": None, "providers": [] } course_id = request.GET.get("course_id") email_opt_in = request.GET.get('email_opt_in') redirect_to = request.GET.get("next") # Check if the user is trying to enroll in a course # that they don't have access to based on country # access rules. # # If so, set the redirect URL to the blocked page. # We need to set it here, rather than redirecting # from within the pipeline, because a redirect # from the pipeline can prevent users # from completing the authentication process. # # Note that we can't check the user's country # profile at this point, since the user hasn't # authenticated. If the user ends up being blocked # by their country preference, we let them enroll; # they'll still be blocked when they try to access # the courseware. if course_id: try: course_key = CourseKey.from_string(course_id) redirect_url = embargo_api.redirect_if_blocked( course_key, ip_address=get_ip(request), url=request.path ) if redirect_url: redirect_to = embargo_api.message_url_path(course_key, "enrollment") except InvalidKeyError: pass login_urls = auth_pipeline_urls( third_party_auth.pipeline.AUTH_ENTRY_LOGIN, course_id=course_id, email_opt_in=email_opt_in, redirect_url=redirect_to ) register_urls = auth_pipeline_urls( third_party_auth.pipeline.AUTH_ENTRY_REGISTER, course_id=course_id, email_opt_in=email_opt_in, redirect_url=redirect_to ) if third_party_auth.is_enabled(): context["providers"] = [ { "name": enabled.NAME, "iconClass": enabled.ICON_CLASS, "loginUrl": login_urls[enabled.NAME], "registerUrl": register_urls[enabled.NAME] } for enabled in third_party_auth.provider.Registry.enabled() ] running_pipeline = third_party_auth.pipeline.get(request) if running_pipeline is not None: current_provider = third_party_auth.provider.Registry.get_by_backend_name( running_pipeline.get('backend') ) context["currentProvider"] = current_provider.NAME return context