Beispiel #1
0
def start_social_login(
    request: HttpRequest,
    backend: str,
    extra_arg: Optional[str] = None,
) -> HttpResponse:
    backend_url = reverse("social:begin", args=[backend])
    extra_url_params: Dict[str, str] = {}
    if backend == "saml":
        if not SAMLAuthBackend.check_config():
            return config_error(request, "saml")

        # This backend requires the name of the IdP (from the list of configured ones)
        # to be passed as the parameter.
        if not extra_arg or extra_arg not in settings.SOCIAL_AUTH_SAML_ENABLED_IDPS:
            logging.info(
                "Attempted to initiate SAML authentication with wrong idp argument: %s", extra_arg
            )
            return config_error(request, "saml")
        extra_url_params = {"idp": extra_arg}

    if backend == "apple" and not AppleAuthBackend.check_config():
        return config_error(request, "apple")

    # TODO: Add AzureAD also.
    if backend in ["github", "google", "gitlab"]:
        key_setting = "SOCIAL_AUTH_" + backend.upper() + "_KEY"
        secret_setting = "SOCIAL_AUTH_" + backend.upper() + "_SECRET"
        if not (getattr(settings, key_setting) and getattr(settings, secret_setting)):
            return config_error(request, backend)

    return oauth_redirect_to_root(request, backend_url, "social", extra_url_params=extra_url_params)
Beispiel #2
0
def start_social_login(request: HttpRequest,
                       backend: str,
                       extra_arg: Optional[str] = None) -> HttpResponse:
    backend_url = reverse('social:begin', args=[backend])
    extra_url_params = {}  # type: Dict[str, str]
    if backend == "saml":
        result = SAMLAuthBackend.check_config()
        if result is not None:
            return result

        # This backend requires the name of the IdP (from the list of configured ones)
        # to be passed as the parameter.
        if not extra_arg or extra_arg not in settings.SOCIAL_AUTH_SAML_ENABLED_IDPS:
            logging.info(
                "Attempted to initiate SAML authentication with wrong idp argument: {}"
                .format(extra_arg))
            return redirect_to_config_error("saml")
        extra_url_params = {'idp': extra_arg}
    if (backend == "github") and not (settings.SOCIAL_AUTH_GITHUB_KEY
                                      and settings.SOCIAL_AUTH_GITHUB_SECRET):
        return redirect_to_config_error("github")
    if (backend == "google") and not (settings.SOCIAL_AUTH_GOOGLE_KEY
                                      and settings.SOCIAL_AUTH_GOOGLE_SECRET):
        return redirect_to_config_error("google")
    if (backend == "gitlab") and not (settings.SOCIAL_AUTH_GITLAB_KEY
                                      and settings.SOCIAL_AUTH_GITLAB_SECRET):
        return redirect_to_config_error("gitlab")
    # TODO: Add a similar block for AzureAD.

    return oauth_redirect_to_root(request,
                                  backend_url,
                                  'social',
                                  extra_url_params=extra_url_params)
Beispiel #3
0
def start_social_login(request: HttpRequest, backend: str, extra_arg: Optional[str]=None
                       ) -> HttpResponse:
    backend_url = reverse('social:begin', args=[backend])
    extra_url_params = {}  # type: Dict[str, str]
    if backend == "saml":
        result = SAMLAuthBackend.check_config()
        if result is not None:
            return result

        # This backend requires the name of the IdP (from the list of configured ones)
        # to be passed as the parameter.
        if not extra_arg or extra_arg not in settings.SOCIAL_AUTH_SAML_ENABLED_IDPS:
            logging.info("Attempted to initiate SAML authentication with wrong idp argument: {}"
                         .format(extra_arg))
            return redirect_to_config_error("saml")
        extra_url_params = {'idp': extra_arg}
    backends = ["github", "google", "gitlab"]
    # TODO: Add AzureAD also.
    for backend in backends:
        key_setting = "SOCIAL_AUTH_" + backend.upper() + "_KEY"
        secret_setting = "SOCIAL_AUTH_" + backend.upper() + "_SECRET"
        if not (getattr(settings, key_setting) and getattr(settings, secret_setting)):
            return redirect_to_config_error(backend)

    return oauth_redirect_to_root(request, backend_url, 'social', extra_url_params=extra_url_params)
Beispiel #4
0
def start_social_signup(request: HttpRequest, backend: str, extra_arg: Optional[str]=None,
                        ) -> HttpResponse:
    backend_url = reverse('social:begin', args=[backend])
    extra_url_params: Dict[str, str] = {}
    if backend == "saml":
        if not SAMLAuthBackend.check_config():
            return config_error(request, 'saml')

        if not extra_arg or extra_arg not in settings.SOCIAL_AUTH_SAML_ENABLED_IDPS:
            logging.info("Attempted to initiate SAML authentication with wrong idp argument: %s",
                         extra_arg)
            return config_error(request, "saml")
        extra_url_params = {'idp': extra_arg}
    return oauth_redirect_to_root(request, backend_url, 'social', is_signup=True,
                                  extra_url_params=extra_url_params)
Beispiel #5
0
def start_social_login(request: HttpRequest,
                       backend: str,
                       extra_arg: Optional[str] = None) -> HttpResponse:
    user_agent = parse_user_agent(
        request.META.get("HTTP_USER_AGENT", "Missing User-Agent"))
    if user_agent["name"] == "ZulipElectron":
        return render(request, "zerver/desktop_login.html")

    backend_url = reverse('social:begin', args=[backend])
    extra_url_params: Dict[str, str] = {}
    if backend == "saml":
        result = SAMLAuthBackend.check_config()
        if result is not None:
            return result

        # This backend requires the name of the IdP (from the list of configured ones)
        # to be passed as the parameter.
        if not extra_arg or extra_arg not in settings.SOCIAL_AUTH_SAML_ENABLED_IDPS:
            logging.info(
                "Attempted to initiate SAML authentication with wrong idp argument: %s",
                extra_arg)
            return redirect_to_config_error("saml")
        extra_url_params = {'idp': extra_arg}

    # TODO: Add AzureAD also.
    if backend in ["github", "google", "gitlab"]:
        key_setting = "SOCIAL_AUTH_" + backend.upper() + "_KEY"
        secret_setting = "SOCIAL_AUTH_" + backend.upper() + "_SECRET"
        if not (getattr(settings, key_setting)
                and getattr(settings, secret_setting)):
            return redirect_to_config_error(backend)

    return oauth_redirect_to_root(request,
                                  backend_url,
                                  'social',
                                  extra_url_params=extra_url_params)