def get_google_contacts_service(self, user): if self.contact_service is None: storage = Storage(CredentialsModel, 'id', user, 'credential') auth_token = OAuth2TokenFromCredentials(storage.get()) self.contact_service = gdata.contacts.client.ContactsClient() auth_token.authorize(self.contact_service) return self.contact_service
def auth_return(request): if not xsrfutil.validate_token(settings.SECRET_KEY, str(request.GET['state']), request.user): return HttpResponseBadRequest() credential = FLOW.step2_exchange(request.GET) storage = Storage(CredentialsModel, 'id', request.user, 'credential') storage.put(credential) return HttpResponseRedirect("/main")
def _get_calendar_service(self, user): if self.calendar_service: self.calendar_service else: storage = Storage(CredentialsModel, 'id', user, 'credential') credentials = storage.get() http = credentials.authorize(httplib2.Http()) self.calendar_service = discovery.build('calendar', 'v3', http=http) return self.calendar_service
def check_google_authenticated(request): storage = Storage(CredentialsModel, 'id', request.user, 'credential') credentials = storage.get() if credentials is None or credentials.invalid is True: FLOW.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY, request.user) FLOW.params['access_type'] = 'offline' authorize_url = FLOW.step1_get_authorize_url() logger.debug(authorize_url) return HttpResponseRedirect(authorize_url) else: return HttpResponseRedirect('/main')
def _build_service(self, user=None): storage = Storage(CredentialsModel, 'id', user, 'credential') cred = storage.get() self.service = build('drive', 'v3', credentials=cred) return self.service