Verifies CAS 1.0 authentication ticket.

        Returns username on success and None on failure.
968654
def verify_ticket(self, ticket):
        
        params = [('ticket', ticket), ('service', self.service_url)]
        if self.renew:
            params.append(('renew', 'true'))
        url = (urllib_parse.urljoin(self.server_url, 'validate') + '?' +
               urllib_parse.urlencode(params))
        page = urllib_request.urlopen(url)
        try:
            verified = page.readline().strip()
            if verified == b'yes':
                charset = self.get_page_charset(page, default="ascii")
                user = self.u(page.readline().strip(), charset)
                return user, None, None
            else:
                return None, None, None
        finally:
            page.close()
131001
def creds(self):
        
        session = self.client.session()
        if session is None:
            return None

        return {
            "basic_auth": self.client.basic_auth_str(),
            "user_ctx": session.get('userCtx')
        }
479411
def perform_service_validate(
        self,
        ticket=None,
        service_url=None,
        headers=None,
        ):
        '''
        
        '''
        url = self._get_service_validate_url(ticket, service_url=service_url)
        logging.debug('[CAS] ServiceValidate URL: {}'.format(url))
        return self._perform_cas_call(url, ticket=ticket, headers=headers)
711317
def verify_proxy_ticket(ticket, service):
    

    params = {'ticket': ticket, 'service': service}

    url = (urljoin(settings.CAS_SERVER_URL, 'proxyValidate') + '?' +
           urlencode(params))

    page = urlopen(url)

    try:
        response = page.read()
        tree = ElementTree.fromstring(response)
        if tree[0].tag.endswith('authenticationSuccess'):
            username = tree[0][0].text
            proxies = []
            if len(tree[0]) > 1:
                for element in tree[0][1]:
                    proxies.append(element.text)
            return {"username": username, "proxies": proxies}
        else:
            return None
    finally:
        page.close()
163031
def api_key(request, response, verify_user, context=None, **kwargs):
    
    api_key = request.get_header('X-Api-Key')

    if api_key:
        try:
            user = verify_user(api_key)
        except TypeError:
            user = verify_user(api_key, context)
        if user:
            return user
        else:
            return False
    else:
        return None
262385
def validate_registration(self):
        '''
        
        '''
        url = '/api/%s' % self.username
        response = self.make_request('GET', url)

        if 'error' in response:
            return False

        return True
7655
def authenticate(self, request, username=None, password=None, realm=None):
        
        if isinstance(username, basestring):
            username = username.encode('utf-8')

        if isinstance(password, basestring):
            password = password.encode('utf-8')

        server = self.get_server(realm)

        if not server:
            return None

        result = self._radius_auth(server, username, password)

        if result:
            full_username = self.construct_full_username(username, realm)
            return self.get_django_user(full_username, password)

        return None
1288572
def verify(self, user, identity):
        
        return UserIdentityRequest(self).put(self.endpoint.verify, user, identity)
689044
def verify_ticket(self, ticket):
        """"""
        (response, charset) = self.get_verification_response(ticket)
        return self.verify_response(response, charset)
680455
def verifyAccount(self, subject, vendorSpecific=None):
        
        response = self.verifyAccountResponse(subject, vendorSpecific)
        return self._read_boolean_response(response)
1045154
def _login_url(service, ticket='ST', gateway=False):
    

    LOGINS = {'ST': 'login',
              'PT': 'proxyValidate'}
    if gateway:
        params = {'service': service, 'gateway': 'true'}
    else:
        params = {'service': service}

    if settings.CAS_EXTRA_LOGIN_PARAMS:
        params.update(settings.CAS_EXTRA_LOGIN_PARAMS)

    if not ticket:
        ticket = 'ST'

    login_type = LOGINS.get(ticket[:2], 'login')

    return urlparse.urljoin(settings.CAS_SERVER_URL, login_type) + '?' + urlencode(params)
531564
def get_cas_client(service_url=None, request=None):
    
    # Handle CAS_SERVER_URL without protocol and hostname
    server_url = django_settings.CAS_SERVER_URL
    if server_url and request and server_url.startswith('/'):
        scheme = request.META.get("X-Forwarded-Proto", request.scheme)
        server_url = scheme + "://" + request.META['HTTP_HOST'] + server_url
    # assert server_url.startswith('http'), "settings.CAS_SERVER_URL invalid"

    if not django_settings.CAS_VERIFY_SSL_CERTIFICATE:
        warnings.warn(
            "`CAS_VERIFY_SSL_CERTIFICATE` is disabled, meaning that SSL certificates "
            "are not being verified by a certificate authority. This can expose your "
            "system to various attacks and should _never_ be disabled in a production "
            "environment."
        )

    return CASClient(
        service_url=service_url,
        version=django_settings.CAS_VERSION,
        server_url=server_url,
        extra_login_params=django_settings.CAS_EXTRA_LOGIN_PARAMS,
        renew=django_settings.CAS_RENEW,
        username_attribute=django_settings.CAS_USERNAME_ATTRIBUTE,
        proxy_callback=django_settings.CAS_PROXY_CALLBACK,
        verify_ssl_certificate=django_settings.CAS_VERIFY_SSL_CERTIFICATE
    )
74839
def cache_component_verify_ticket(self, msg, signature, timestamp, nonce):
        
        warnings.warn('`cache_component_verify_ticket` method of `WeChatComponent` is deprecated,'
                      'Use `parse_message` instead',
                      DeprecationWarning, stacklevel=2)
        content = self.crypto.decrypt_message(msg, signature, timestamp, nonce)
        message = xmltodict.parse(to_text(content))['xml']
        o = ComponentVerifyTicketMessage(message)
        self.session.set(o.type, o.verify_ticket)
893338
def verify_registration(request):
    
    user = process_verify_registration_data(request.data)
    extra_data = None
    if registration_settings.REGISTER_VERIFICATION_AUTO_LOGIN:
        extra_data = perform_login(request, user)
    return get_ok_response('User verified successfully', extra_data=extra_data)
799848
def verify_user(self):
        
        command = const.CMD_STARTVERIFY
        cmd_response = self.__send_command(command)
        if cmd_response.get('status'):
            return True
        else:
            raise ZKErrorResponse("Cant Verify")
874455
def validate_authentication(self, username, password, handler):
        
        user = authenticate(
            **{self.username_field: username, 'password': password}
        )
        account = self.get_account(username)
        if not (user and account):
            raise AuthenticationFailed("Authentication failed.")
716128
function validateCasResponse(req, res, ticket, casBody, options, next) {

  xml2js(casBody, {
    explicitRoot: false,
    tagNameProcessors: [stripPrefix]
  }, function(err, serviceResponse) {
    if (err) {
      console.error('Failed to parse CAS server response when trying to validate ticket.');
      console.error(err);
      return res.status(500).send({
        message: 'Failed to parse CAS server response when trying to validate ticket.',
        error: err
      });
    }

    var success = serviceResponse && serviceResponse.authenticationSuccess && serviceResponse.authenticationSuccess[0],
      user = success && success.user && success.user[0],
      pgtIou = success && success.proxyGrantingTicket && success.proxyGrantingTicket[0];

    if (!serviceResponse) {
      console.error('Invalid CAS server response.');
      return res.status(500).send({
        message: 'Invalid CAS server response, serviceResponse empty.'
      });
    }

    // TODO: 不成功回首页
    if (!success) {
      console.log('Receive response from CAS when validating ticket, but the validation is failed. Redirect to the last request url: ' + req.session.lastUrl);
      if (typeof options.redirect === 'function' && options.redirect(req, res, next)) {
        return;
      }

      return res.redirect(302, req.session.lastUrl);
    }

    req.session.st = ticket;

    if (req.ssoff) {
      req.sessionStore.set(ticket, { sid: req.session.id }, function(err) {
        if (err) {
          console.log('Trying to store ticket in sessionStore for ssoff failed!');
          console.error(err);
        }
      });
    }

    req.session.cas = {};
    for (var casProperty in success) {
      if (casProperty != 'proxyGrantingTicket') {
        req.session.cas[casProperty] = success[casProperty][0];
      }
    }

    if (!pgtIou) {
      if (options.paths.proxyCallback) {
        console.log('pgtUrl is specific, but havn\'t find pgtIou from CAS validation response!');
        return res.status(401).send({
          message: 'pgtUrl is specific, but havn\'t find pgtIou from CAS validation response!'
        });
      } else {
        if (debug) {
          console.log('None-proxy mode, validate ticket succeed, redirecting to lastUrl: ' + req.session.lastUrl);
        }
        req.session.save(function(err) {
          if (err) {
            console.log('Trying to save session failed!');
            console.error(err);
            return res.status(500).send({
              message: 'Trying to save session failed!',
              error: err
            });
          }
          if (typeof options.redirect === 'function' && options.redirect(req, res)) {
            return;
          }

          return res.redirect(302, req.session.lastUrl);
        });
      }

      return;
    }

    retrievePGTFromPGTIOU(req, res, pgtIou, options);
  });
}