Example #1
0
 def get_authsub_url(self, entity_id=None, params={'next_url':None, 'service':'docs'}):
     next_url = params.get('next_url')
     service = params.get('service', 'docs')
     source = params.get('source', 'evectors-ermconnector-v1')
     redirect_url=""
     decode = params.get('decode', False)
     if next_url and next_url!="":
         if service !="": #in ('docs', 'youtube'):
             gd_client = gdata.docs.service.DocsService(source=source)
             
             if decode:
                 next=urllib.unquote(next_url)
             else:
                 next=next_url
             
             scopes=list()
             for single_service in service.split(','):
                 scopes=scopes+services_data[single_service]['scopes']
             scopes = list(set(scopes))#services_data[service]['scopes']
             secure = False
             session = True
             redirect_url=gdata.service.GenerateAuthSubRequestUrl(next, scopes, secure=secure, session=session)
         else:
             raise ApiError(None, 3941)            
         return redirect_url
     else:
         raise ApiError(None, 3940)
Example #2
0
    def get_oauth_url(self, entity_id=None, params={'service':'docs'}):
        next_url=params.get('next_url', None)
        decode = params.get('decode', False)
        domain =  params.get('domain', 'default')
        service = params.get('service', 'docs')
        consumer_key = params.get('consumer_key', GOOGLE_OAUTH_CONSUMER_KEY)
        consumer_secret = params.get('consumer_secret', GOOGLE_OAUTH_CONSUMER_SECRET)
        source = params.get('source', 'evectors-ermconnector-v1')

        if next_url and next_url!="":
            if service !="": #in ('docs', 'youtube'):
                if decode:
                    next=urllib.unquote(next_url)
                else:
                    next=next_url
                scopes=list()
                for single_service in service.split(','):
                    scopes=scopes+services_data[single_service]['scopes']
                scopes = list(set(scopes))#services_data[service]['scopes']
                
                client = gdata.docs.client.DocsClient(source=source)
                request_token = client.GetOAuthToken(scopes, 
                                                     next, 
                                                     consumer_key, 
                                                     consumer_secret=consumer_secret)

                redirect_url=request_token.generate_authorization_url(google_apps_domain=domain)
                
                try:
                    query=None
                    pickled=base64.encodestring(pickle.dumps({"token":request_token,
                                                              "next_url":next_url,
                                                              "consumer_key":consumer_key,
                                                              "consumer_secret":consumer_secret,
                                                              "service":service,
                                                              "source":source,
                                                              "scopes":scopes
                                                              }))
                    token=request_token.token
                    
                    self.transaction_start()
                    try:
                        query=QUERY_CREATE_OAUTH_TABLE % (DM_DATABASE_NAME)
                        self.do_query(query)
                    except Exception, err:
                        if not ("already exists" in ("%s" % err)):
                            Logger().error("Error: %s (%s) - %s" % (err, query, Exception))
                            raise Exception, err
                    
                    try:
                        query=QUERY_DELETE_OAUTH_RECORD % (DM_DATABASE_NAME,token, "googleConnector")
                        self.do_query(query)
                    except Exception, err:
                        Logger().error("Error: %s (%s)" % (err, query))
                        raise Exception, err
    
                    
                    query=QUERY_ADD_OAUTH_RECORD % (DM_DATABASE_NAME,
                                              token,
                                              pickled, 
                                              str(datetime.datetime.now()), 
                                              "googleConnector")
                    self.do_query(query)

                    self.transaction_commit()
                except Exception, err:
                    self.transaction_rollback()
                    raise ApiError(None, 3102, "%s (%s): %s - [%s]" % (entity_id, err, query, Exception))