'**DEPRECATED**: Authenticate to use this database.
Authentication lasts for the life of the underlying client
instance, or until :meth:`logout` is called.
Raises :class:`TypeError` if (required) `name`, (optional) `password`,
or (optional) `source` is not an instance of :class:`basestring`
(:class:`str` in python 3).
.. note::
- This method authenticates the current connection, and
will also cause all new :class:`~socket.socket` connections
in the underlying client instance to be authenticated automatically.
- Authenticating more than once on the same database with different
credentials is not supported. You must call :meth:`logout` before
authenticating with new credentials.
- When sharing a client instance between multiple threads, all
threads will share the authentication. If you need different
authentication profiles for different purposes you must use
distinct client instances.
:Parameters:
- `name`: the name of the user to authenticate. Optional when
`mechanism` is MONGODB-X509 and the MongoDB server version is
>= 3.4.
- `password` (optional): the password of the user to authenticate.
Not used with GSSAPI or MONGODB-X509 authentication.
- `source` (optional): the database to authenticate on. If not
specified the current database is used.
- `mechanism` (optional): See
:data:`~pymongo.auth.MECHANISMS` for options.
By default, use SCRAM-SHA-1 with MongoDB 3.0 and later,
MONGODB-CR (MongoDB Challenge Response protocol) for older servers.
- `authMechanismProperties` (optional): Used to specify
authentication mechanism specific options. To specify the service
name for GSSAPI authentication pass
authMechanismProperties=\'SERVICE_NAME:<service name>\'
.. versionchanged:: 3.5
Deprecated. Authenticating multiple users conflicts with support for
logical sessions in MongoDB 3.6. To authenticate as multiple users,
create multiple instances of MongoClient.
.. versionadded:: 2.8
Use SCRAM-SHA-1 with MongoDB 3.0 and later.
.. versionchanged:: 2.5
Added the `source` and `mechanism` parameters. :meth:`authenticate`
now raises a subclass of :class:`~pymongo.errors.PyMongoError` if
authentication fails due to invalid credentials or configuration
issues.
.. mongodoc:: authenticate'

def authenticate(self, name=None, password=None, source=None, mechanism='DEFAULT', **kwargs):

    if ((name is not None) and (not isinstance(name, string_type))):
        raise TypeError(('name    must    be    an    instance    of    %s' % (string_type.__name__,)))
    if ((password is not None) and (not isinstance(password, string_type))):
        raise TypeError(('password    must    be    an    instance    of    %s' % (string_type.__name__,)))
    if ((source is not None) and (not isinstance(source, string_type))):
        raise TypeError(('source    must    be    an    instance    of    %s' % (string_type.__name__,)))
    common.validate_auth_mechanism('mechanism', mechanism)
    validated_options = {}
    for (option, value) in iteritems(kwargs):
        (normalized, val) = common.validate_auth_option(option, value)
        validated_options[normalized] = val
    credentials = auth._build_credentials_tuple(mechanism, (source or self.name), name, password, validated_options)
    self.client._cache_credentials(self.name, credentials, connect=True)
    return True
