def get_cred(self): """ Reads current user credentials from saved file """ try: store = Storage( os.path.join(self._appdir, 'gcal_credentials') ) return store.locked_get() except: self._log.exception("Failed to get google authentication credential") return None
def open_client(): from goffice.client import GClient, authorize_client, authorize_credentials from oauth2client.file import Storage keypath = _load_default_keypath() s = Storage(keypath) try: cr = s.locked_get() except Exception: cr = None if cr is None: cr = authorize_credentials(keypath.replace("_store", '')) s.locked_put(cr) return GClient(cr)
def load_oauth2_credentials(self, fname_secret, fname_creds): store = Storage(fname_creds) if os.path.isfile(fname_creds): store.acquire_lock() self.credentials = store.locked_get() store.release_lock() else: flow = flow_from_clientsecrets(fname_secret, scope='https://mail.google.com/', redirect_uri='urn:ietf:wg:oauth:2.0:oob') auth_uri = flow.step1_get_authorize_url() webbrowser.open(auth_uri) auth_code = raw_input('Enter the auth code: ') self.credentials = flow.step2_exchange(auth_code) store.acquire_lock() store.locked_put(self.credentials) store.release_lock() self.credentials.set_store(store)
def load_oauth2_credentials(self, fname_secret, fname_creds): store = Storage(fname_creds) if os.path.isfile(fname_creds): store.acquire_lock() self.credentials = store.locked_get() store.release_lock() else: flow = flow_from_clientsecrets( fname_secret, scope='https://mail.google.com/', redirect_uri='urn:ietf:wg:oauth:2.0:oob') auth_uri = flow.step1_get_authorize_url() webbrowser.open(auth_uri) auth_code = raw_input('Enter the auth code: ') self.credentials = flow.step2_exchange(auth_code) store.acquire_lock() store.locked_put(self.credentials) store.release_lock() self.credentials.set_store(store)