예제 #1
0
 def get_credentials(self):
     r = DARedis()
     r_key = 'da:' + self.appname + ':status:user:'******'code' in self.url_args and 'state' in self.url_args:
             r.delete(r_key)
             if self.url_args['state'] != stored_state.decode():
                 raise Exception("State did not match")
             flow = self._get_flow()
             credentials = flow.step2_exchange(self.url_args['code'])
             storage = RedisCredStorage(self.appname)
             storage.put(credentials)
             del self.url_args['code']
             del self.url_args['state']
         else:
             message("Please wait.",
                     "You are in the process of authenticating.")
     storage = RedisCredStorage(self.appname)
     credentials = storage.get()
     if not credentials or credentials.invalid:
         state_string = random_string(16)
         pipe = r.pipeline()
         pipe.set(r_key, state_string)
         pipe.expire(r_key, 60)
         pipe.execute()
         flow = self._get_flow()
         uri = flow.step1_get_authorize_url(state=state_string)
         if 'state' in self.url_args:
             del self.url_args['state']
         if 'code' in self.url_args:
             del self.url_args['code']
         response(url=uri)
     return credentials
예제 #2
0
 def get_credentials(self):
     self._setup()
     r = DARedis()
     r_key = self._get_redis_key()
     stored_state = r.get(r_key)
     if stored_state is not None and stored_state.decode() == 'None':
         stored_state = None
     if stored_state is not None:
         if 'code' in self.url_args and 'state' in self.url_args:
             r.delete(r_key)
             if self.url_args['state'] != stored_state.decode():
                 raise Exception("State did not match.  " +
                                 repr(self.url_args['state']) + " vs " +
                                 repr(stored_state.decode()) +
                                 " where r_key is " + repr(r_key))
             flow = self._get_flow()
             credentials = flow.step2_exchange(self.url_args['code'])
             storage = self._get_redis_cred_storage()
             storage.put(credentials)
             del self.url_args['code']
             del self.url_args['state']
         else:
             message("Please wait.",
                     "You are in the process of authenticating.",
                     dead_end=True)
     storage = self._get_redis_cred_storage()
     credentials = storage.get()
     if not credentials or credentials.invalid:
         state_string = safeid(user_info().filename + '^' +
                               random_string(8))
         pipe = r.pipeline()
         pipe.set(r_key, state_string)
         pipe.expire(r_key, 300)
         pipe.execute()
         flow = self._get_flow()
         uri = flow.step1_get_authorize_url(state=state_string)
         if 'state' in self.url_args:
             del self.url_args['state']
         if 'code' in self.url_args:
             del self.url_args['code']
         response(url=uri)
     return credentials