我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用oauth2client.client.Storage()。
def __init__(self, model_class, key_name, key_value, property_name): """Constructor for Storage. Args: model: string, fully qualified name of db.Model model class. key_name: string, key name for the entity that has the credentials key_value: string, key value for the entity that has the credentials. property_name: string, name of the property that is an CredentialsProperty. """ super(DjangoORMStorage, self).__init__() self.model_class = model_class self.key_name = key_name self.key_value = key_value self.property_name = property_name
def locked_get(self): """Retrieve stored credential from the Django ORM. Returns: oauth2client.Credentials retrieved from the Django ORM, associated with the ``model``, ``key_value``->``key_name`` pair used to query for the model, and ``property_name`` identifying the ``CredentialsProperty`` field, all of which are defined in the constructor for this Storage object. """ query = {self.key_name: self.key_value} entities = self.model_class.objects.filter(**query) if len(entities) > 0: credential = getattr(entities[0], self.property_name) if getattr(credential, 'set_store', None) is not None: credential.set_store(self) return credential else: return None
def __init__(self, session, model_class, key_name, key_value, property_name): """Constructor for Storage. Args: session: An instance of :class:`sqlalchemy.orm.Session`. model_class: SQLAlchemy declarative mapping. key_name: string, key name for the entity that has the credentials key_value: key value for the entity that has the credentials property_name: A string indicating which property on the ``model_class`` to store the credentials. This property must be a :class:`CredentialsType` column. """ super(Storage, self).__init__() self.session = session self.model_class = model_class self.key_name = key_name self.key_value = key_value self.property_name = property_name
def __init__(self, model, key_name, property_name, cache=None, user=None): """Constructor for Storage. Args: model: db.Model or ndb.Model, model class key_name: string, key name for the entity that has the credentials property_name: string, name of the property that is a CredentialsProperty or CredentialsNDBProperty. cache: memcache, a write-through cache to put in front of the datastore. If the model you are using is an NDB model, using a cache will be redundant since the model uses an instance cache and memcache for you. user: users.User object, optional. Can be used to grab user ID as a key_name if no key name is specified. """ if key_name is None: if user is None: raise ValueError('StorageByKeyName called with no key name or user.') key_name = user.user_id() self._model = model self._key_name = key_name self._property_name = property_name self._cache = cache
def __init__(self, model, key_name, property_name, cache=None, user=None): """Constructor for Storage. Args: model: db.Model or ndb.Model, model class key_name: string, key name for the entity that has the credentials property_name: string, name of the property that is a CredentialsProperty or CredentialsNDBProperty. cache: memcache, a write-through cache to put in front of the datastore. If the model you are using is an NDB model, using a cache will be redundant since the model uses an instance cache and memcache for you. user: users.User object, optional. Can be used to grab user ID as a key_name if no key name is specified. """ if key_name is None: if user is None: raise ValueError('StorageByKeyName called with no ' 'key name or user.') key_name = user.user_id() self._model = model self._key_name = key_name self._property_name = property_name self._cache = cache
def __init__(self, model, key_name, property_name, cache=None, user=None): """Constructor for Storage. Args: model: db.Model or ndb.Model, model class key_name: string, key name for the entity that has the credentials property_name: string, name of the property that is a CredentialsProperty or CredentialsNDBProperty. cache: memcache, a write-through cache to put in front of the datastore. If the model you are using is an NDB model, using a cache will be redundant since the model uses an instance cache and memcache for you. user: users.User object, optional. Can be used to grab user ID as a key_name if no key name is specified. """ super(StorageByKeyName, self).__init__() if key_name is None: if user is None: raise ValueError('StorageByKeyName called with no ' 'key name or user.') key_name = user.user_id() self._model = model self._key_name = key_name self._property_name = property_name self._cache = cache
def __init__(self, service_name, user_name): """Constructor. Args: service_name: string, The name of the service under which the credentials are stored. user_name: string, The name of the user to store credentials for. """ super(Storage, self).__init__(lock=threading.Lock()) self._service_name = service_name self._user_name = user_name
def __init__(self, model, key_name, property_name, cache=None): """Constructor for Storage. Args: model: db.Model, model class key_name: string, key name for the entity that has the credentials property_name: string, name of the property that is a CredentialsProperty cache: memcache, a write-through cache to put in front of the datastore """ self._model = model self._key_name = key_name self._property_name = property_name self._cache = cache
def test_locked_get_abstract(self): storage = client.Storage() with self.assertRaises(NotImplementedError): storage.locked_get()
def test_locked_put_abstract(self): storage = client.Storage() credentials = object() with self.assertRaises(NotImplementedError): storage.locked_put(credentials)
def test_locked_delete_abstract(self): storage = client.Storage() with self.assertRaises(NotImplementedError): storage.locked_delete()
def __init__(self, filename): super(Storage, self).__init__(lock=threading.Lock()) self._filename = filename
def init_app(self, app, scopes=None, client_secrets_file=None, client_id=None, client_secret=None, authorize_callback=None, storage=None, **kwargs): """Initialize this extension for the given app. Arguments: app: A Flask application. scopes: Optional list of scopes to authorize. client_secrets_file: Path to a file containing client secrets. You can also specify the OAUTH2_CLIENT_SECRETS_JSON config value. client_id: If not specifying a client secrets file, specify the OAuth2 client id. You can also specify the GOOGLE_OAUTH2_CLIENT_ID config value. You must also provide a client secret. client_secret: The OAuth2 client secret. You can also specify the GOOGLE_OAUTH2_CLIENT_SECRET config value. authorize_callback: A function that is executed after successful user authorization. storage: A oauth2client.client.Storage subclass for storing the credentials. By default, this is a Flask session based storage. kwargs: Any additional args are passed along to the Flow constructor. """ self.app = app self.authorize_callback = authorize_callback self.flow_kwargs = kwargs if storage is None: storage = FlaskSessionStorage() self.storage = storage if scopes is None: scopes = app.config.get('GOOGLE_OAUTH2_SCOPES', DEFAULT_SCOPES) self.scopes = scopes self._load_config(client_secrets_file, client_id, client_secret) app.register_blueprint(self._create_blueprint())