Exemplo n.º 1
0
 def revoke(self, jrequest, jresponse):
     assert isinstance(jrequest, JsonRpcRequest)
     assert isinstance(jresponse, JsonRpcResponse)
     jresponse.setResultValue("gaesession", get_current_session())
     googleAuthSession = GoogleAuthSession()
     googleAuthSession.revoke()
     jresponse.setResultValue("googleAuthSession", googleAuthSession)
Exemplo n.º 2
0
 def revoke(self, jrequest, jresponse):
     assert isinstance(jrequest, JsonRpcRequest)
     assert isinstance(jresponse, JsonRpcResponse)
     jresponse.setResultValue("gaesession", get_current_session())
     googleAuthSession = GoogleAuthSession()
     googleAuthSession.revoke()
     jresponse.setResultValue("googleAuthSession", googleAuthSession)
Exemplo n.º 3
0
    def GET(self, jrequest, jresponse):
        assert isinstance(jrequest, JsonRpcRequest)
        assert isinstance(jresponse, JsonRpcResponse)
        jresponse.setId()
        assert jresponse.getId()
        debug("GET called with id=%s" % jresponse.getId())
        jresponse.setResultValue("gaesession", get_current_session())
        #odenkiSession = OdenkiSession()
        #jresponse.setResultValue("odenkiSession", odenkiSession)
        googleAuthSession = GoogleAuthSession()
        debug("googleAuthSession has keys %s" % googleAuthSession.keys())
        jresponse.setResultValue("googleAuthSession", googleAuthSession)

        if googleAuthSession.getAccessToken():
            debug("access token %s already exists" %
                  googleAuthSession.getAccessToken())
            debug("googleAuthSesson has keys %s" % googleAuthSession.keys())
            return

        if googleAuthSession.getNonAuthorizedRequestToken():
            assert googleAuthSession.getNonAuthorizedRequestToken(
            ).auth_state == REQUEST_TOKEN
            assert isinstance(googleAuthSession.getNonAuthorizedRequestToken(),
                              OAuthHmacToken)
            debug("Extracting authorized request token from callback URL = " +
                  self.request.url)
            authorized_request_token = AuthorizeRequestToken(
                googleAuthSession.getNonAuthorizedRequestToken(),
                self.request.url)
            if authorized_request_token.token is None:
                googleAuthSession.revoke()
                assert not googleAuthSession._getToken()
                error_message = "Can't extract authorized request token from the URL %s" % self.request.url
                debug(error_message)
                assert jresponse.getId()
                jresponse.setError(JsonRpcError.SERVER_ERROR_RESERVED_MIN,
                                   error_message)
                return
            assert authorized_request_token.token
            assert authorized_request_token.auth_state == AUTHORIZED_REQUEST_TOKEN
            googleAuthSession.setAuthorizedRequestToken(
                authorized_request_token)
            debug("%s, %s" %
                  (googleAuthSession.getAuthorizedRequestToken().token,
                   authorized_request_token.token))
            assert googleAuthSession.getAuthorizedRequestToken(
            ).token == authorized_request_token.token

        if googleAuthSession.getAuthorizedRequestToken():
            assert isinstance(googleAuthSession.getAuthorizedRequestToken(),
                              OAuthHmacToken)
            assert googleAuthSession.getAuthorizedRequestToken(
            ).auth_state == AUTHORIZED_REQUEST_TOKEN
            docs_client = DocsClient()
            try:
                access_token = docs_client.GetAccessToken(
                    googleAuthSession.getAuthorizedRequestToken())
            except Exception, e:
                error_message = "failed to exchange authorized request token to access token, %s" % e
                debug(error_message)
                googleAuthSession.revoke()
                jresponse.setError(JsonRpcError.SERVER_ERROR_RESERVED_MIN,
                                   error_message)
                return
            assert isinstance(access_token, OAuthHmacToken)
            assert access_token.auth_state == ACCESS_TOKEN
            googleAuthSession.setAccessToken(access_token)
            assert googleAuthSession.getAccessToken(
            ).token is access_token.token
            debug("access token = %s" % googleAuthSession.getAccessToken)
            debug(
                "after exchanging authorized request token with access token, googleAuthSession has keys %s"
                % googleAuthSession.keys())
            return
Exemplo n.º 4
0
    def GET(self, jrequest, jresponse):
        assert isinstance(jrequest, JsonRpcRequest)
        assert isinstance(jresponse, JsonRpcResponse)
        jresponse.setId()
        assert jresponse.getId()
        debug("GET called with id=%s" % jresponse.getId())
        jresponse.setResultValue("gaesession", get_current_session())
        #odenkiSession = OdenkiSession()
        #jresponse.setResultValue("odenkiSession", odenkiSession)
        googleAuthSession = GoogleAuthSession()
        debug("googleAuthSession has keys %s" %googleAuthSession.keys())
        jresponse.setResultValue("googleAuthSession", googleAuthSession)
        
        if googleAuthSession.getAccessToken():
            debug("access token %s already exists" % googleAuthSession.getAccessToken())
            debug("googleAuthSesson has keys %s" % googleAuthSession.keys())
            return
        
        if googleAuthSession.getNonAuthorizedRequestToken():
            assert googleAuthSession.getNonAuthorizedRequestToken().auth_state == REQUEST_TOKEN
            assert isinstance(googleAuthSession.getNonAuthorizedRequestToken(), OAuthHmacToken)
            debug("Extracting authorized request token from callback URL = " + self.request.url)
            authorized_request_token = AuthorizeRequestToken(googleAuthSession.getNonAuthorizedRequestToken(),
                                                             self.request.url)
            if authorized_request_token.token is None:
                googleAuthSession.revoke()
                assert not googleAuthSession._getToken()
                error_message = "Can't extract authorized request token from the URL %s" % self.request.url
                debug(error_message)
                assert jresponse.getId()
                jresponse.setError(JsonRpcError.SERVER_ERROR_RESERVED_MIN, error_message)
                return
            assert authorized_request_token.token
            assert authorized_request_token.auth_state == AUTHORIZED_REQUEST_TOKEN
            googleAuthSession.setAuthorizedRequestToken(authorized_request_token)
            debug("%s, %s" % (googleAuthSession.getAuthorizedRequestToken().token, authorized_request_token.token))
            assert googleAuthSession.getAuthorizedRequestToken().token == authorized_request_token.token

        if googleAuthSession.getAuthorizedRequestToken():
            assert isinstance(googleAuthSession.getAuthorizedRequestToken(), OAuthHmacToken)
            assert googleAuthSession.getAuthorizedRequestToken().auth_state == AUTHORIZED_REQUEST_TOKEN
            docs_client = DocsClient()
            try:
                access_token = docs_client.GetAccessToken(googleAuthSession.getAuthorizedRequestToken())
            except Exception, e:
                error_message = "failed to exchange authorized request token to access token, %s" % e
                debug(error_message)
                googleAuthSession.revoke()
                jresponse.setError(JsonRpcError.SERVER_ERROR_RESERVED_MIN, error_message)
                return
            assert isinstance(access_token, OAuthHmacToken)
            assert access_token.auth_state == ACCESS_TOKEN
            googleAuthSession.setAccessToken(access_token)
            assert googleAuthSession.getAccessToken().token is access_token.token
            debug("access token = %s" % googleAuthSession.getAccessToken)
            debug("after exchanging authorized request token with access token, googleAuthSession has keys %s" % googleAuthSession.keys())
            return