Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def logout(self, request, data, binding):
conf = get_config(request=request)
state = StateCache(request.session)
client = Saml2Client(
conf, state_cache=state, identity_cache=IdentityCache(request.session)
)
if 'SAMLResponse' in data:
# Logout started by us
client.parse_logout_request_response(data['SAMLResponse'], binding)
http_response = logout_completed()
else:
# Logout started by IdP
subject_id = _get_subject_id(request.session)
if subject_id is None:
http_response = logout_completed()
else:
http_info = client.handle_logout_request(
data['SAMLRequest'],
subject_id,
binding,
relay_state=data.get('RelayState', ''),
)
http_response = HttpResponseRedirect(get_location(http_info))
state.sync()
user = request.user
if user.is_anonymous:
return http_response
Token.objects.get(user=user).delete()
def get(self, request):
state = StateCache(request.session)
conf = get_config(request=request)
client = Saml2Client(
conf, state_cache=state, identity_cache=IdentityCache(request.session)
)
subject_id = _get_subject_id(request.session)
if subject_id is None:
return logout_failed(_('You cannot be logged out.'))
try:
result = client.global_logout(subject_id)
except KeyError:
return logout_failed(_('You are not logged in any IdP/AA.'))
state.sync()
if not result:
return logout_failed(_('You are not logged in any IdP/AA.'))
# Logout is supported only from 1 IdP
binding, http_info = list(result.values())[0]
return HttpResponseRedirect(get_location(http_info))