def test_can_saml_assertion_is_encoded(): ticket = 'test-ticket' client = cas.CASClient(version='CAS_2_SAML_1_0') saml = client.get_saml_assertion(ticket) if sys.version_info > (3, 0): assert type(saml) is bytes assert ticket.encode('utf-8') in saml else: assert ticket in saml
def get_client(self, request, action=AuthAction.AUTHENTICATE): """ Returns the CAS client to interact with the CAS server. """ auth_params = self.provider.get_auth_params(request, action) service_url = self.adapter.get_service_url(request) client = cas.CASClient( service_url=service_url, server_url=self.adapter.url, version=self.adapter.version, renew=self.adapter.renew, extra_login_params=auth_params, ) return client
def get(self, request): ticket = request.GET.get('ticket') next_url = request.GET.get(REDIRECT_FIELD_NAME) if not next_url: next_url = utils.get_redirect_url( request, default_url=self.default_redirect_url, use_referer=True) # If the user is already authenticated, proceed to next page if request.user.is_authenticated: return _login_success_redirect(request, request.user, next_url) service_url = utils.get_service_url(request, redirect_url=next_url, service_url=self.service_root_url) client = cas.CASClient(version=2, service_url=service_url, server_url=str( utils.get_setting('CAS_SERVER_URL'))) # If a ticket was provided, attempt to authenticate with it if ticket: user = authenticate(request=request, ticket=ticket, service=service_url) # Authentication successful: setup session + proceed if user: if not request.session.exists(request.session.session_key): request.session.create() django_login(request, user) return _login_success_redirect(request, user, next_url, ["ticket", "service"]) # Authentication failed: raise permission denied else: url = "%s?failed=True" % str(self.default_fail_url) return HttpResponseRedirect(url) # If no ticket was provided, redirect to the # login URL for the institution's CAS server else: return HttpResponseRedirect(client.get_login_url())
def logout_client_v3(): return cas.CASClient( version='3', server_url='http://www.example.com/cas/' )
def test_unsupported_protocol_version(): with pytest.raises(ValueError): cas.CASClient(version='unknown')
def client_v3(): return cas.CASClient( version='3', server_url='https://cas.example.com/cas/', service_url='https://example.com/login')