def test_constructor_explicit(self): dictionary = {} key = 'test-key' storage = DictionaryStorage(dictionary, key) lock = object() storage = DictionaryStorage(dictionary, key, lock=lock) self.assertEqual(storage._lock, lock)
def get_storage(request): # TODO(issue 319): Make this pluggable with different storage providers # https://github.com/google/oauth2client/issues/319 """ Gets a Credentials storage object for the Django OAuth2 Helper object :param request: Reference to the current request object :return: A OAuth2Client Storage implementation based on sessions """ return DictionaryStorage(request.session, key=_CREDENTIALS_KEY)
def test_constructor_defaults(self): dictionary = {} key = 'test-key' storage = DictionaryStorage(dictionary, key) self.assertEqual(dictionary, storage._dictionary) self.assertEqual(key, storage._key) self.assertIsNone(storage._lock)
def main(): if sys.version_info.major < 3: print('Python 3+ required') return tools.argparser.add_argument('year', type=int, help='The year of the first event') tools.argparser.add_argument('month', type=int, help='The month of the first event') tools.argparser.add_argument('day', type=int, help='The day of the first event') flags = tools.argparser.parse_args() eventDay = datetime.date(flags.year, flags.month, flags.day) userResponse = input('Is date {} correct? y/n: '.format( eventDay.strftime('%A, %B %d, %Y'))) if userResponse.lower() != 'y': return storage_dict = {} store = DictionaryStorage(storage_dict, u'credentials') flow = client.OAuth2WebServerFlow( client_id= '570017343303-nf4f1vaclctc8d0c7ma4rahm5v49rnbm.apps.googleusercontent.com', client_secret='BDhRKaNZh4iRRfr2V95y3y2O', scope='https://www.googleapis.com/auth/calendar', auth_uri='https://accounts.google.com/o/oauth2/auth', token_uri='https://www.googleapis.com/oauth2/v3/token') creds = tools.run_flow(flow, store) service = build('calendar', 'v3', http=creds.authorize(Http())) oneDay = datetime.timedelta(days=1) for week in range(1, 5): for day in range(1, 8): event = { 'summary': 'W{}D{}'.format(week, day), 'transparency': 'transparent', 'start': { 'date': str(eventDay), }, 'end': { 'date': str(eventDay), }, } eventDay += oneDay event = service.events().insert(calendarId='primary', body=event).execute() print('') print('Events created')
def test_delete(self): credentials = _generate_credentials() dictionary = {} key = 'credentials' storage = DictionaryStorage(dictionary, key) storage.put(credentials) self.assertIn(key, dictionary) storage.delete() self.assertNotIn(key, dictionary) self.assertIsNone(storage.get())
def test_put(self): credentials = _generate_credentials() dictionary = {} key = 'credentials' storage = DictionaryStorage(dictionary, key) storage.put(credentials) returned = storage.get() self.assertIn(key, dictionary) self.assertIsNotNone(returned) self.assertEqual(returned.access_token, credentials.access_token) self.assertEqual(returned.id_token, credentials.id_token) self.assertEqual(returned.refresh_token, credentials.refresh_token) self.assertEqual(returned.client_id, credentials.client_id)
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 GOOGLE_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 = DictionaryStorage(session, key=_CREDENTIALS_KEY) 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())
def __init__(self): self.storage_dict = {} self.storage = DictionaryStorage(self.storage_dict, "creds")