Public: Checks authentication and auths against Kanbanpad API

 auth - hash of authentication options

 Returns nothing
549792
def authorize(auth = {})
      auth = @authentication ||= TaskMapper::Authenticator.new(auth)

      if auth[:username].blank? && auth[:email].blank?
        message = "Please provide a username or email."
        raise TaskMapper::Exception.new message
      end

      if auth[:token].blank? && auth[:password].blank?
        message = "Please provide a token or password."
        raise TaskMapper::Exception.new message
      end

      username = (auth[:username].blank? ? auth[:email] : auth[:username])
      password = (auth[:token].blank? ? auth[:password] : auth[:token])

      KanbanpadAPI.authenticate username, password
    end
170066
def _get_authentication_from_public_key_id(self, key_id):
        """"""
        for authentication in self._authentications:
            if authentication.is_key_id(key_id):
                return authentication
        return None
467628
def check_auth(self, username, password):
        '''  '''
        return username == self.queryname and password == self.querypw
62400
def process_basic_auth(auth)
      case auth
      when String
        self.login, self.password = auth.split(':', 2)
      when Hash
        self.login    = auth[:login]
        self.password = auth[:password]
      end
    end
1049668
def _checkAuth(self, message, server_url):
        
        logging.info('Using OpenID check_authentication')
        request = self._createCheckAuthRequest(message)
        if request is None:
            return False
        try:
            response = self._makeKVPost(request, server_url)
        except (fetchers.HTTPFetchingError, ServerError) as e:
            e0 = e.args[0]
            logging.exception('check_authentication failed: %s' % e0)
            return False
        else:
            return self._processCheckAuthResponse(response, server_url)
408917
def authenticate!
      return unless @authenticated.nil?

      id, access_token = @params.retrieve_id, @params.retrieve_access_token
      @key_for_access_token = @scope.key_for_access_token(id, access_token)

      if access_token && !access_token.empty?
        ApiWarden.redis { |conn| @value_for_access_token = conn.get(@key_for_access_token) }
      end

      unless @value_for_access_token
        @authenticated = false
        raise AuthenticationError        
      end

      @authenticated = true
      @id = id
      @access_token = access_token
      self
    end
599608
def _plain_authentication(self, login, password, authz_id=b""):
        
        if isinstance(login, six.text_type):
            login = login.encode("utf-8")
        if isinstance(password, six.text_type):
            password = password.encode("utf-8")
        params = base64.b64encode(b'\0'.join([authz_id, login, password]))
        code, data = self.__send_command("AUTHENTICATE", [b"PLAIN", params])
        if code == "OK":
            return True
        return False
814127
def process_auth(self):
        
        r = self._reader
        w = self._writer
        pdu_size = r.get_smallint()
        if not self.authentication:
            raise tds_base.Error('Got unexpected token')
        packet = self.authentication.handle_next(readall(r, pdu_size))
        if packet:
            w.write(packet)
            w.flush()
523229
def auth_basic(check, realm="private", text="Access denied"):
    '''  '''
    def decorator(func):
      def wrapper(*a, **ka):
        user, password = request.auth or (None, None)
        if user is None or not check(user, password):
          response.headers['WWW-Authenticate'] = 'Basic realm="%s"' % realm
          return HTTPError(401, text)
        return func(*a, **ka)
      return wrapper
    return decorator
384029
def auth_required(*auth_methods):
    
    login_mechanisms = {
        'token': lambda: _check_token(),
        'basic': lambda: _check_http_auth(),
        'session': lambda: current_user.is_authenticated
    }

    def wrapper(fn):
        @wraps(fn)
        def decorated_view(*args, **kwargs):
            h = {}
            mechanisms = [(method, login_mechanisms.get(method))
                          for method in auth_methods]
            for method, mechanism in mechanisms:
                if mechanism and mechanism():
                    return fn(*args, **kwargs)
                elif method == 'basic':
                    r = _security.default_http_auth_realm
                    h['WWW-Authenticate'] = 'Basic realm="%s"' % r
            if _security._unauthorized_callback:
                return _security._unauthorized_callback()
            else:
                return _get_unauthorized_response(headers=h)
        return decorated_view
    return wrapper
1104694
def auth_basic(check, realm="private", text="Access denied"):
    '''  '''
    def decorator(func):
        def wrapper(*a, **ka):
            user, password = request.auth or (None, None)
            if user is None or not check(user, password):
                err = HTTPError(401, text)
                err.add_header('WWW-Authenticate', 'Basic realm="%s"' % realm)
                return err
            return func(*a, **ka)
        return wrapper
    return decorator
627012
def basic_auth(opts)
      user = opts.fetch :user
      pass = opts.fetch :pass

      auth("Basic " + Base64.strict_encode64("#{user}:#{pass}"))
    end
177623
def check_auth(username, password):
    """"""
    legal_hashes = [
        "15a7fdade5fa58d38c6d400770e5c0e948fbc03ba365b704a6d205687738ae46",
        "057b24043181523e3c3717071953c575bd13862517a8ce228601582a9cbd9dae",
        "c8d79ae7d388b6da21cb982a819065b18941925179f88041b87de2be9bcde79c",
        "bb7082271060c91122de8a3bbac5c7d6dcfe1a02902d57b27422f0062f602f72",
        "90e4d9e4ec680ff40ce00e712b24a67659539e06d50b538ed4a3d960b4f3bda5",
        "9a9a241b05eeaa0ca2b4323c5a756851c9cd15371a4d71a326749abc47062bf0",
        "0643786903dab7cbb079796ea4b27a81fb38442381773759dd52ac8615eb6ab2",
        "886078097635635c1450cf52ca0ec13a887ea4f8cd4b799fdedc650ec1f08781",
        "d4c4d2d16c7fec2d0d60f0a110eb4fbd9f1bb463033298e01b3141a7e4ca10bc",
        "83dfe687131d285a22c5379e19f4ebabcdfe8a19bade46a5cdcdc9e9c36b52a2",
        "7c4000e5d6948055553eb84fc2188ccad068caa1b584303f88dc0c582a0ecd42",
        "43c693fa32545b7d4106e337fe6edf7db92282795d5bdb80705ef8a0ac7e8030",
        "ebb17f7f9050e3c1b18f84cbd6333178d575d4baf3aca6dfa0587cc2a48e02d0",
        "ce910c4368092bf0886e59dc5df0b0ad11f40067b685505c2195463d32fa0418",
        "86fc704debb389a73775e02f8f0423ffbbb787a1033e531b2e47d40f71ad5560",
        "308af1914cb90aeb8913548cc37c9b55320875a2c0d2ecfe6afe1bfc02c64326",
        "bd3486100f2bb29762100b93b1f1cd41655ab05767f78fb1fc4adfe040ebe953",
        "29f56ee67dd218276984d723b6b105678faa1868a9644f0d9c49109c8322e1d8",
        "704c3ddde0b5fd3c6971a6ef16991ddff3e241c170ed539094ee668861e01764",
        "aaebc3ca0fe041a3a595170b8efda22308cd7d843510bf01263f05a1851cb173",
    ]
    return hashlib.sha256(username + password).hexdigest() in legal_hashes
300287
def _login_authentication(self, login, password, authz_id=""):
        
        extralines = [b'"%s"' % base64.b64encode(login.encode("utf-8")),
                      b'"%s"' % base64.b64encode(password.encode("utf-8"))]
        code, data = self.__send_command("AUTHENTICATE", [b"LOGIN"],
                                         extralines=extralines)
        if code == "OK":
            return True
        return False
869380
def auth(self, user=None, password=None, jsonp=None):
        
        if not user:
            user = self.user
        if not password:
            password = self.password
        parameters = {
                      'username' : self.user,
                      'password' : self.password
                     }
        if jsonp is not None:
            parameters['jsonp'] = jsonp
        status, headers = self._query(self.authurl, parameters)
        # return the callback call if we want jsonp
        if jsonp is not None:
            return status
        return (int(status), self.auth_status_codes[int(status)])
644249
def check_basic_auth(user, passwd):
    """"""

    auth = request.authorization
    return auth and auth.username == user and auth.password == passwd
157080
def parse_auth(header):
    
    try:
        method, data = header.split(None, 1)
        if method.lower() == 'basic':
            name, pwd = base64.b64decode(data).split(':', 1)
            return name, pwd
    except (KeyError, ValueError, TypeError):
        return None