def setup_oauth(self, consumer_key, consumer_secret, server_rpc_base='https://www-opensocial.googleusercontent.com/api/rpc'): """Configure this robot to use the oauth'd json rpc. Args: consumer_key: consumer key received from the verification process. consumer_secret: secret received from the verification process. server_rpc_base: url of the rpc gateway to use. Specify None for default. For wave preview, https://www-opensocial.googleusercontent.com/api/rpc should be used. For wave sandbox, https://www-opensocial-sandbox.googleusercontent.com/api/rpc should be used. """ consumer_key_prefix = '' # NOTE(ljvderijk): Present for backwards capability. if server_rpc_base in [waveservice.WaveService.SANDBOX_RPC_URL, waveservice.WaveService.RPC_URL]: consumer_key_prefix = 'google.com:' self._consumer_key = consumer_key_prefix + consumer_key self._waveservice = waveservice.WaveService( consumer_key=consumer_key, consumer_secret=consumer_secret, server_rpc_base=server_rpc_base, http_post=self._http_post)
def _oauth_helper(request): "Check if we're authenticated and if not, execute the oauth dance." consumer_key = getattr(settings, 'WAVE_CONSUMER_KEY', 'anonymous') consumer_secret = getattr(settings, 'WAVE_CONSUMER_SECRET', 'anonymous') use_sandbox = getattr(settings, 'WAVE_USE_SANDBOX', False) service = waveservice.WaveService(consumer_key=consumer_key, consumer_secret=consumer_secret, use_sandbox=use_sandbox) access_token = request.COOKIES.get('WAVE_ACCESS_TOKEN') if access_token: service.set_access_token(access_token) request.waveservice = service return None # no access token. dance monkey dance. oauth_token = request.GET.get('oauth_token') verifier = request.GET.get('oauth_verifier') request_token = request.COOKIES.get('WAVE_REQUEST_TOKEN') meta = request.META # you'd think there would be something better than this madness: this_url = meta.get('HTTP_HOST') if not this_url: this_url = meta.get('SERVER_NAME') port = meta.get('SEVER_PORT') if port: this_url += ':' + port this_url += request.path schema = meta.get('wsgi.url_scheme', 'http') this_url = schema + '://' + this_url if not oauth_token or not verifier or not request_token: # we're here not returning from a callback. Start. request_token = service.fetch_request_token(callback=this_url) auth_url = service.generate_authorization_url() response = HttpResponseRedirect(auth_url) # set a session cookie response.set_cookie('WAVE_REQUEST_TOKEN', request_token.to_string()) return response else: logging.info('upgrading to access token') access_token = service.upgrade_to_access_token( request_token=request_token, verifier=verifier) # This redirect could be avoided if the caller would set the cookie. This way # however we keep the cgi arguments clean. response = HttpResponseRedirect(this_url) response.set_cookie('WAVE_ACCESS_TOKEN', access_token.to_string(), max_age=24 * 3600 * 365) return response
def __init__(self, name, image_url='', profile_url=DEFAULT_PROFILE_URL): """Initializes self with robot information. Args: name: The name of the robot image_url: (optional) url of an image that should be used as the avatar for this robot. profile_url: (optional) url of a webpage with more information about this robot. """ self._handlers = {} self._name = name self._verification_token = None self._st = None self._waveservice = waveservice.WaveService() self._profile_handler = None self._image_url = image_url self._profile_url = profile_url self._capability_hash = 0 self._consumer_key = None self._http_post = None
def setup_oauth( self, consumer_key, consumer_secret, server_rpc_base='https://www-opensocial.googleusercontent.com/api/rpc' ): """Configure this robot to use the oauth'd json rpc. Args: consumer_key: consumer key received from the verification process. consumer_secret: secret received from the verification process. server_rpc_base: url of the rpc gateway to use. Specify None for default. For wave preview, http://gmodules.com/api/rpc should be used. For wave sandbox, http://sandbox.gmodules.com/api/rpc should be used. """ self._consumer_key = consumer_key self._waveservice = waveservice.WaveService( consumer_key='google.com:' + consumer_key, consumer_secret=consumer_secret, server_rpc_base=server_rpc_base, http_post=self._http_post)
def setUp(self): self.waveservice = waveservice.WaveService()