Exemplo n.º 1
0
    def pipeline(self, pipeline, *args, **kwargs):
        """Pipeline"""
        out = kwargs.copy()

        if 'pipeline_index' in kwargs:
            base_index = int(kwargs['pipeline_index'])
        else:
            base_index = 0

        for idx, name in enumerate(pipeline):
            out['pipeline_index'] = base_index + idx
            mod_name, func_name = name.rsplit('.', 1)
            try:
                mod = import_module(mod_name)
            except ImportError:
                log('exception', 'Error importing pipeline %s', name)
            else:
                func = getattr(mod, func_name, None)

                if callable(func):
                    try:
                        result = func(*args, **out) or {}
                    except StopPipeline:
                        # Clean partial pipeline on stop
                        if 'request' in kwargs:
                            clean_partial_pipeline(kwargs['request'])
                        break

                    if isinstance(result, dict):
                        out.update(result)
                    else:
                        return result
        return out
Exemplo n.º 2
0
def auth_process(request, backend):
    """Authenticate using social backend"""
    print(backend)
    data = request.POST if request.method == 'POST' else request.GET

    # Save extra data into session.
    for field_name in setting('SOCIAL_AUTH_FIELDS_STORED_IN_SESSION', []):
        if field_name in data:
            request.session[field_name] = data[field_name]

    # Save any defined next value into session
    if REDIRECT_FIELD_NAME in data:
        # Check and sanitize a user-defined GET/POST next field value
        redirect = data[REDIRECT_FIELD_NAME]
        if setting('SOCIAL_AUTH_SANITIZE_REDIRECTS', True):
            redirect = sanitize_redirect(request.get_host(), redirect)
        request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT

    # Clean any partial pipeline info before starting the process
    clean_partial_pipeline(request)
    if backend.uses_redirect:
        return HttpResponseRedirect(backend.auth_url())
    else:
        return HttpResponse(backend.auth_html(),
                            content_type='text/html;charset=UTF-8')
Exemplo n.º 3
0
    def pipeline(self, pipeline, *args, **kwargs):
        """Pipeline"""
        out = kwargs.copy()

        if 'pipeline_index' in kwargs:
            base_index = int(kwargs['pipeline_index'])
        else:
            base_index = 0

        for idx, name in enumerate(pipeline):
            out['pipeline_index'] = base_index + idx
            mod_name, func_name = name.rsplit('.', 1)
            mod = import_module(mod_name)
            func = getattr(mod, func_name, None)

            try:
                result = func(*args, **out) or {}
            except StopPipeline:
                # Clean partial pipeline on stop
                if 'request' in kwargs:
                    clean_partial_pipeline(kwargs['request'])
                break

            if isinstance(result, dict):
                out.update(result)
            else:
                return result
        return out
Exemplo n.º 4
0
    def pipeline(self, pipeline, *args, **kwargs):
        """Pipeline"""
        out = kwargs.copy()

        if "pipeline_index" in kwargs:
            base_index = int(kwargs["pipeline_index"])
        else:
            base_index = 0

        for idx, name in enumerate(pipeline):
            out["pipeline_index"] = base_index + idx
            mod_name, func_name = name.rsplit(".", 1)
            mod = __import__(mod_name, {}, {}, [func_name])
            func = getattr(mod, func_name, None)

            try:
                result = func(*args, **out) or {}
            except StopPipeline:
                # Clean partial pipeline on stop
                if "request" in kwargs:
                    clean_partial_pipeline(kwargs["request"])
                break

            if isinstance(result, dict):
                out.update(result)
            else:
                return result

        # clean the partial pipeline at the end of the process
        if "request" in kwargs:
            clean_partial_pipeline(kwargs["request"])
        return out
Exemplo n.º 5
0
def auth(request, backend):
    """Authenticate using social backend"""
    data = request.POST if request.method == "POST" else request.GET

    # Save extra data into session.
    for field_name in setting("SOCIAL_AUTH_FIELDS_STORED_IN_SESSION", []):
        if field_name in data:
            request.session[field_name] = data[field_name]

    # Save any defined next value into session
    if REDIRECT_FIELD_NAME in data:
        # Check and sanitize a user-defined GET/POST next field value
        redirect = data[REDIRECT_FIELD_NAME]
        # NOTE: django-sudo's `is_safe_url` is much better at catching bad
        # redirections to different domains than social_auth's
        # `sanitize_redirect` call.
        if not is_safe_url(redirect, host=request.get_host()):
            redirect = DEFAULT_REDIRECT
        request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT

    # Clean any partial pipeline info before starting the process
    clean_partial_pipeline(request)

    if backend.uses_redirect:
        return HttpResponseRedirect(backend.auth_url())
    else:
        return HttpResponse(backend.auth_html(), content_type="text/html;charset=UTF-8")
Exemplo n.º 6
0
    def pipeline(self, pipeline, *args, **kwargs):
        """Pipeline"""
        out = kwargs.copy()

        if 'pipeline_index' in kwargs:
            base_index = int(kwargs['pipeline_index'])
        else:
            base_index = 0

        for idx, name in enumerate(pipeline):
            out['pipeline_index'] = base_index + idx
            mod_name, func_name = name.rsplit('.', 1)
            mod = import_module(mod_name)
            func = getattr(mod, func_name, None)

            try:
                result = func(*args, **out) or {}
            except StopPipeline:
                # Clean partial pipeline on stop
                if 'request' in kwargs:
                    clean_partial_pipeline(kwargs['request'])
                break

            if isinstance(result, dict):
                out.update(result)
            else:
                return result

        # clean the partial pipeline at the end of the process
        if 'request' in kwargs:
            clean_partial_pipeline(kwargs['request'])
        return out
Exemplo n.º 7
0
def auth_process(request, backend):
    """Authenticate using social backend"""
    data = request.POST if request.method == 'POST' else request.GET

    # Save extra data into session.
    for field_name in setting('SOCIAL_AUTH_FIELDS_STORED_IN_SESSION', []):
        if field_name in data:
            request.session[field_name] = data[field_name]

    # Save any defined next value into session
    if REDIRECT_FIELD_NAME in data:
        # Check and sanitize a user-defined GET/POST next field value
        redirect = data[REDIRECT_FIELD_NAME]
        if setting('SOCIAL_AUTH_SANITIZE_REDIRECTS', True):
            redirect = sanitize_redirect(request.get_host(), redirect)
        request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT

    # Clean any partial pipeline info before starting the process
    clean_partial_pipeline(request)

    if backend.uses_redirect:
        return HttpResponseRedirect(backend.auth_url())
    else:
        return HttpResponse(backend.auth_html(),
                            content_type='text/html;charset=UTF-8')
Exemplo n.º 8
0
    def pipeline(self, pipeline, *args, **kwargs):
        """Pipeline"""
        out = kwargs.copy()

        for name in pipeline:
            mod_name, func_name = name.rsplit('.', 1)
            try:
                mod = import_module(mod_name)
            except ImportError:
                log('exception', 'Error importing pipeline %s', name)
            else:
                func = getattr(mod, func_name, None)

                if callable(func):
                    try:
                        result = func(*args, **out) or {}
                    except StopPipeline:
                        # Clean partial pipeline on stop
                        if 'request' in kwargs:
                            clean_partial_pipeline(kwargs['request'])
                        break

                    if isinstance(result, dict):
                        out.update(result)
                    else:
                        return result
        return out
Exemplo n.º 9
0
def auth_process(request, backend):
    """Authenticate using social backend"""
    data = request.POST if request.method == 'POST' else request.GET

    # Save extra data into session.
    for field_name in setting('SOCIAL_AUTH_FIELDS_STORED_IN_SESSION', []):
        if field_name in data:
            request.session[field_name] = data[field_name]

    # Save any defined next value into session
    if REDIRECT_FIELD_NAME in data:
        # Check and sanitize a user-defined GET/POST next field value
        redirect = data[REDIRECT_FIELD_NAME]
        # NOTE: django-sudo's `is_safe_url` is much better at catching bad
        # redirections to different domains than social_auth's
        # `sanitize_redirect` call.
        if not is_safe_url(redirect, host=request.get_host()):
            redirect = DEFAULT_REDIRECT
        request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT

    # Clean any partial pipeline info before starting the process
    clean_partial_pipeline(request)

    if backend.uses_redirect:
        return HttpResponseRedirect(backend.auth_url())
    else:
        return HttpResponse(backend.auth_html(),
                            content_type='text/html;charset=UTF-8')
Exemplo n.º 10
0
    def pipeline(self, pipeline, *args, **kwargs):
        """Pipeline"""
        out = kwargs.copy()

        for name in pipeline:
            mod_name, func_name = name.rsplit(".", 1)
            try:
                mod = import_module(mod_name)
            except ImportError:
                log("exception", "Error importing pipeline %s", name)
            else:
                func = getattr(mod, func_name, None)

                if callable(func):
                    try:
                        result = func(*args, **out) or {}
                    except StopPipeline:
                        # Clean partial pipeline on stop
                        if "request" in kwargs:
                            clean_partial_pipeline(kwargs["request"])
                        break

                    if isinstance(result, dict):
                        out.update(result)
                    else:
                        return result
        return out
Exemplo n.º 11
0
    def pipeline(self, pipeline, *args, **kwargs):
        """Pipeline"""
        out = kwargs.copy()

        if "pipeline_index" in kwargs:
            base_index = int(kwargs["pipeline_index"])
        else:
            base_index = 0

        for idx, name in enumerate(pipeline):
            out["pipeline_index"] = base_index + idx
            mod_name, func_name = name.rsplit(".", 1)
            mod = import_module(mod_name)
            func = getattr(mod, func_name, None)

            try:
                result = func(*args, **out) or {}
            except StopPipeline:
                # Clean partial pipeline on stop
                if "request" in kwargs:
                    clean_partial_pipeline(kwargs["request"])
                break

            if isinstance(result, dict):
                out.update(result)
            else:
                return result
        return out
Exemplo n.º 12
0
def auth_process(request, backend):
    """Authenticate using social backend"""
    # Save any defined next value into session
    data = (request.POST if request.method == 'POST' else request.GET).dict()
    if REDIRECT_FIELD_NAME in data:
        # Check and sanitize a user-defined GET/POST next field value
        redirect = data[REDIRECT_FIELD_NAME]
        if setting('SOCIAL_AUTH_SANITIZE_REDIRECTS', True):
            redirect = sanitize_redirect(request.get_host(), redirect)
        request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT

    # Clean any partial pipeline info before starting the process
    clean_partial_pipeline(request)

    if backend.uses_redirect:
        query = urlencode(data)
        auth_url = backend.auth_url(data.get('extra_scope', ''))

        if query:
            auth_url += "&" + query

        return HttpResponseRedirect(auth_url)
    else:
        return HttpResponse(backend.auth_html(),
                            content_type='text/html;charset=UTF-8')
Exemplo n.º 13
0
def auth_process(request, backend):
    """Authenticate using social backend"""
    # Added by Mike:
    # Save any query parameters into session.
    data = request.POST if request.method == 'POST' else request.GET
    for key, value in data.items():
        request.session[key] = value 

    # Save any defined next value into session
    data = request.POST if request.method == 'POST' else request.GET
    if REDIRECT_FIELD_NAME in data:
        # Check and sanitize a user-defined GET/POST next field value
        redirect = data[REDIRECT_FIELD_NAME]
        if setting('SOCIAL_AUTH_SANITIZE_REDIRECTS', True):
            redirect = sanitize_redirect(request.get_host(), redirect)
        request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT

    # Clean any partial pipeline info before starting the process
    clean_partial_pipeline(request)

    if backend.uses_redirect:
        return HttpResponseRedirect(backend.auth_url())
    else:
        return HttpResponse(backend.auth_html(),
                            content_type='text/html;charset=UTF-8')
Exemplo n.º 14
0
def auth_process(request, backend):
    """Authenticate using social backend"""
    # Save any defined next value into session
    data = request.POST if request.method == "POST" else request.GET
    for field in data:
        if field == REDIRECT_FIELD_NAME:
            # Check and sanitize a user-defined GET/POST next field value
            redirect = data[REDIRECT_FIELD_NAME]
            if setting("SOCIAL_AUTH_SANITIZE_REDIRECTS", True):
                redirect = sanitize_redirect(request.get_host(), redirect)
            request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT
        else:
            request.session[field] = data[field]

    # Clean any partial pipeline info before starting the process
    clean_partial_pipeline(request)

    if backend.uses_redirect:
        return HttpResponseRedirect(backend.auth_url())
    else:
        return HttpResponse(backend.auth_html(), content_type="text/html;charset=UTF-8")