Example #1
0
    def post(self):
        global service
        global secret
        # Get instance of the AppsService for the given consumer_key (domain)
        service = gdata.apps.service.AppsService(
            source=INIT['APP_NAME'], domain=self.request.get('key'))
        two_legged_oauth = False
        if self.request.get('oauth') == 'two_legged_oauth':
            two_legged_oauth = True
        service.SetOAuthInputParameters(
            signature_method=gdata.auth.OAuthSignatureMethod.HMAC_SHA1,
            consumer_key=self.request.get('key'),
            consumer_secret=self.request.get('secret'),
            two_legged_oauth=two_legged_oauth)

        if two_legged_oauth:
            # Redirect to MainPage if 2-legged OAuth is requested
            self.redirect('/?two_legged_oauth=true')
            return

        request_token = service.FetchOAuthRequestToken(
            scopes=INIT['SCOPES'], oauth_callback=self.request.uri)
        secret = request_token.secret
        service.SetOAuthToken(request_token)
        # Send user to Google authorization page
        google_auth_page_url = service.GenerateOAuthAuthorizationURL()
        self.redirect(google_auth_page_url)
Example #2
0
    def get(self):
        global service
        global secret
        # Extract the OAuth request token from the URL
        oauth_token = gdata.auth.OAuthTokenFromUrl(self.request.uri)
        if oauth_token:
            oauth_token.secret = secret
            oauth_token.oauth_input_params = service.GetOAuthInputParameters()
            service.SetOAuthToken(oauth_token)
            # Exchange the request token for an access token
            oauth_verifier = self.request.get('oauth_verifier',
                                              default_value='')
            access_token = service.UpgradeToOAuthAccessToken(
                oauth_verifier=oauth_verifier)
            # Store access_token to the service token_store for later access
            if access_token:
                service.current_token = access_token
                service.SetOAuthToken(access_token)

        self.redirect('/')