def __init__(self, ably, options):
    self.__ably = ably
    self.__auth_options = options
    if options.token_details:
        self.__client_id = options.token_details.client_id
    else:
        self.__client_id = options.client_id
    self.__client_id_validated = False
    self.__basic_credentials = None
    self.__auth_params = None
    self.__token_details = None
    self.__time_offset = None
    must_use_token_auth = (options.use_token_auth is True)
    must_not_use_token_auth = (options.use_token_auth is False)
    can_use_basic_auth = (options.key_secret is not None)
    if ((not must_use_token_auth) and can_use_basic_auth):
        log.debug('anonymous, using basic auth')
        self.__auth_mechanism = Auth.Method.BASIC
        basic_key = ('%s:%s' % (options.key_name, options.key_secret))
        basic_key = base64.b64encode(basic_key.encode('utf-8'))
        self.__basic_credentials = basic_key.decode('ascii')
        return
    elif (must_not_use_token_auth and (not can_use_basic_auth)):
        raise ValueError('If use_token_auth is False you must provide a key')
    self.__auth_mechanism = Auth.Method.TOKEN
    if options.token_details:
        self.__token_details = options.token_details
    elif options.auth_token:
        self.__token_details = TokenDetails(token=options.auth_token)
    else:
        self.__token_details = None
    if options.auth_callback:
        log.debug('using token auth with auth_callback')
    elif options.auth_url:
        log.debug('using token auth with auth_url')
    elif options.key_secret:
        log.debug('using token auth with client-side signing')
    elif options.auth_token:
        log.debug('using token auth with supplied token only')
    elif options.token_details:
        log.debug('using token auth with supplied token_details')
    else:
        raise ValueError("Can't authenticate via token, must provide auth_callback, auth_url, key, token or a TokenDetail")
def __init__(self, ably, options):
    self.__ably = ably
    self.__auth_options = options
    if options.token_details:
        self.__client_id = options.token_details.client_id
    else:
        self.__client_id = options.client_id
    self.__client_id_validated = False
    self.__basic_credentials = None
    self.__auth_params = None
    self.__token_details = None
    self.__time_offset = None
    must_use_token_auth = (options.use_token_auth is True)
    must_not_use_token_auth = (options.use_token_auth is False)
    can_use_basic_auth = (options.key_secret is not None)
    if ((not must_use_token_auth) and can_use_basic_auth):
        log.debug('anonymous, using basic auth')
        self.__auth_mechanism = Auth.Method.BASIC
        basic_key = ('%s:%s' % (options.key_name, options.key_secret))
        basic_key = base64.b64encode(basic_key.encode('utf-8'))
        self.__basic_credentials = basic_key.decode('ascii')
        return
    elif (must_not_use_token_auth and (not can_use_basic_auth)):
        raise ValueError('If use_token_auth is False you must provide a key')
    self.__auth_mechanism = Auth.Method.TOKEN
    if options.token_details:
        self.__token_details = options.token_details
    elif options.auth_token:
        self.__token_details = TokenDetails(token=options.auth_token)
    else:
        self.__token_details = None
    if options.auth_callback:
        log.debug('using token auth with auth_callback')
    elif options.auth_url:
        log.debug('using token auth with auth_url')
    elif options.key_secret:
        log.debug('using token auth with client-side signing')
    elif options.auth_token:
        log.debug('using token auth with supplied token only')
    elif options.token_details:
        log.debug('using token auth with supplied token_details')
    else:
        raise ValueError("Can't authenticate via token, must provide auth_callback, auth_url, key, token or a TokenDetail")