Beispiel #1
0
def associate_complete(request, backend):
    """Authentication complete process"""
    backend = get_backend(backend, request, request.path)
    if not backend:
        return HttpResponseServerError("Incorrect authentication service")
    backend.auth_complete(user=request.user)
    url = request.session.pop(REDIRECT_FIELD_NAME, "") or DEFAULT_REDIRECT
    return HttpResponseRedirect(url)
Beispiel #2
0
def disconnect(request, backend):
    """Disconnects given backend from current logged in user."""
    backend = get_backend(backend, request, request.path)
    if not backend:
        return HttpResponseServerError("Incorrect authentication service")
    backend.disconnect(request.user)
    url = request.REQUEST.get(REDIRECT_FIELD_NAME, "") or DEFAULT_REDIRECT
    return HttpResponseRedirect(url)
Beispiel #3
0
def auth_process(request, backend, complete_url_name):
    """Authenticate using social backend"""
    redirect = reverse(complete_url_name, args=(backend,))
    backend = get_backend(backend, request, redirect)
    if not backend:
        return HttpResponseServerError("Incorrect authentication service")
    # Check and sanitize a user-defined GET/POST redirect_to field value.
    redirect = sanitize_redirect(request.get_host(), request.REQUEST.get(REDIRECT_FIELD_NAME))
    request.session[REDIRECT_FIELD_NAME] = redirect or DEFAULT_REDIRECT
    if backend.uses_redirect:
        return HttpResponseRedirect(backend.auth_url())
    else:
        return HttpResponse(backend.auth_html(), content_type="text/html;charset=UTF-8")
Beispiel #4
0
def complete_process(request, backend):
    """Authentication complete process"""
    backend = get_backend(backend, request, request.path)
    if not backend:
        return HttpResponseServerError("Incorrect authentication service")

    try:
        user = backend.auth_complete()
    except ValueError, e:  # some Authentication error ocurred
        user = None
        error_key = getattr(settings, "AUTHENTICATOR_ERROR_KEY", None)
        if error_key:  # store error in session
            request.session[error_key] = str(e)