コード例 #1
0
ファイル: dsktp_api_check.py プロジェクト: faizan-k/Sync-App
    def put_file(self, widget, data):

        #An object of the Authenticator class from oAuth authentication of our App
        config = auth.Authenticator.load_config("testing.ini")

        dba = auth.Authenticator(config)
        access_token = oauth.OAuthToken('k280uqm85ltjhop', 'bvsi4uto9muxmis')

        print access_token

        #An object of Client is created
        db_client = client.DropboxClient(config['server'],
                                         config['content_server'],
                                         config['port'], dba, access_token)
        root = config['root']

        # Writes the data entered in the text box to the file
        print "Send button is clicked..."
        text = self.entry.get_text()

        # This location of file is to be taken from the user's laptop
        # A script which finds the location of the Dropbox folder
        # needs to be run
        myfile = open('ourfile.txt', 'w')

        myfile.truncate()
        myfile.write(text)
        myfile.close()

        f = open("ourfile.txt")
        resp = db_client.put_file(root, "/", f)
        #assert resp

        assert_equal(resp.status, 200)
コード例 #2
0
    def authorisation(self, widget, data):
       
        print "Send button is clicked..."

        # creates a dict which stores key and secret
	config = auth.Authenticator.load_config("testing.ini")
        
        for key in ['server', 'port', 'consumer_key', 'consumer_secret', 'verifier']:
            print config[key]
 
	dba = auth.Authenticator(config)
        
        # gets temporary token
	req_token = dba.obtain_request_token()	
        print req_token
        
        # directs user to get user permission
        authorize_url = dba.build_authorize_url(req_token, callback="http://localhost/")       
        assert "localhost" in authorize_url, "Should have the return address in it."

          # authorize_url = dba.build_authorize_url(req_token)
          # login_and_authorize(authorize_url, config)
       
        print "Goto this Url: ", authorize_url

        # Request token obtained after permission is used to get access token
        req_token.key = raw_input("Enter the token you got:")
        access_token = dba.obtain_access_token(req_token, config['verifier'])
 
        assert access_token
        assert dba.oauth_request
        assert access_token.key != req_token.key
        
        print access_token
コード例 #3
0
 def get(self):
     dba = auth.Authenticator(config)
     req_token = dba.obtain_request_token()
     base64_token = urllib.quote(base64.b64encode(req_token.to_string()))
     self.redirect(
         dba.build_authorize_url(req_token,
                                 callback="http://%s/callback/%s" %
                                 (self.request.host, base64_token)))
コード例 #4
0
def authenticated_client(profile):
    import settings
    from dropbox import auth
    from dropbox.client import DropboxClient
    from oauth import oauth

    dba = auth.Authenticator(settings.DROPBOX_CONFIG)

    access_token = oauth.OAuthToken(key=profile.db_access_token_key,
                                    secret=profile.db_access_token_secret)

    client = DropboxClient(settings.DROPBOX_CONFIG['server'],
                           settings.DROPBOX_CONFIG['content_server'],
                           settings.DROPBOX_CONFIG['port'], dba, access_token)

    return client
コード例 #5
0
    def ask(self):
        self.dialogAskPassword('passwd',
                               'Enter password for user "%s"' % self.itemname)

        if self.state == 1:
            config = q.config.getConfig('dropbox')
            if not config:
                q.errorconditionhandler.raiseError(
                    "dropbox.cfg does not exists  ")
            if 'auth' not in config:
                q.errorconditionhandler.raiseError(
                    "dropbox.cfg does not include auth section  ")
            config = config['auth']
            config = q.config.getConfig('dropbox')['auth']
            dba = auth.Authenticator(config)
            access_token = dba.obtain_trusted_access_token(
                self.itemname, self.params["passwd"])
            self.params["key"] = access_token.key
            self.params["secret"] = access_token.secret
コード例 #6
0
    def get(self):

        user = DropboxUser.get_current(self)

        if user:
            token = OAuthToken(user.oauth_token, user.oauth_token_secret)
            dba = auth.Authenticator(config)
            db_client = client.DropboxClient(config['server'],
                                             config['content_server'],
                                             config['port'], dba, token)

            dirinfo = json.loads(db_client.metadata('dropbox', '').body)

            if 'contents' in dirinfo:
                self.response.out.write(dirinfo['contents'])
            else:
                self.response.out.write('no contents, bro')
        else:
            print "There was no user, bro."
コード例 #7
0
ファイル: dsktp_api_check.py プロジェクト: faizan-k/Sync-App
    def account_info(self, widget, data):

        # An object of the Authenticator class from oAuth authentication of our App
        config = auth.Authenticator.load_config("testing.ini")

        dba = auth.Authenticator(config)
        access_token = oauth.OAuthToken('k280uqm85ltjhop', 'bvsi4uto9muxmis')

        print access_token

        # An object of Client is created
        db_client = client.DropboxClient(config['server'],
                                         config['content_server'],
                                         config['port'], dba, access_token)
        root = config['root']

        # Gets the account info of user
        db_client.file_delete(root, "/tohere")
        resp = db_client.account_info()
        assert resp
        print resp.data
コード例 #8
0
ファイル: dropback.py プロジェクト: zyan0/djblog
 def login(self, options):
     '''获得access token'''
     config = {
         'server': 'api.dropbox.com',
         'content_server': 'api-content.dropbox.com',
         'port': 80,
         'request_token_url':
         'https://api.dropbox.com/0/oauth/request_token',
         'access_token_url': 'https://api.dropbox.com/0/oauth/access_token',
         'authorization_url': 'https://www.dropbox.com/0/oauth/authorize',
         'trusted_access_token_url': 'https://api.dropbox.com/0/token',
         'consumer_key': options['key'],
         'consumer_secret': options['secret'],
     }
     dba = auth.Authenticator(config)
     token = dba.obtain_request_token()
     self.access_token = dba.obtain_trusted_access_token(
         options['email'], options['passwd'])
     self.client = client.DropboxClient(config['server'],
                                        config['content_server'],
                                        config['port'], dba,
                                        self.access_token)
コード例 #9
0
ファイル: Dropbox.py プロジェクト: racktivity/ext-pylabs-core
    def getClient(self, userName):
        """ this method returns instance of dropboxManager which could be used to access different methods dropbox API.
         this method may takes user name , user name must be predefined using q.clinets.dropbox._config 
         it is important to consider the following while using this extension 
        
                -user must configure file  /opt/qbase3/cfg/qconfig/dropbox.cfg  
                -user of this extention  has to be aware  of dropbox terms of use in order to be able to obtain production key  

        @param userName: dropbox user name 
       
        @return:  return DropboxClient instance with permission to access dropbox account of the user generated that client.  
        """
        q.logger.log('initializing drop box client ')

        config = q.config.getConfig('dropbox')
        if not config:
            q.errorconditionhandler.raiseError("dropbox.cfg does not exists  ")
        if 'auth' not in config:
            q.errorconditionhandler.raiseError(
                "dropbox.cfg does not include auth section  ")
        config = config['auth']

        dba = auth.Authenticator(config)

        q.logger.log('initializing drop box client using access token ')
        try:
            userConfig = i.config.clients.dropbox.getConfig(userName)
        except:
            q.errorconditionhandler.raiseError(
                userName + " is not configured user name  ")

        access_token = oauth.OAuthToken(userConfig['key'],
                                        userConfig['secret'])

        dbClient = client.DropboxClient(config['server'],
                                        config['content_server'],
                                        config['port'], dba, access_token)

        return DropboxClient(dbClient, config)
コード例 #10
0
ファイル: handlers.py プロジェクト: wyue/Instadrop
    def get(self):
        from oauth import oauth

        dba = dropbox_auth.Authenticator(settings.DROPBOX_CONFIG)

        token = self.request.get("oauth_token")
        profile = Profile.all().filter("db_oauth_token_key =", token).get()

        if not profile:
            self.redirect("/connect")
            return

        oauth_token = oauth.OAuthToken(key=profile.db_oauth_token_key,
                                       secret=profile.db_oauth_token_secret)

        verifier = settings.DROPBOX_CONFIG['verifier']
        access_token = dba.obtain_access_token(oauth_token, verifier)

        profile.db_access_token_key = access_token.key
        profile.db_access_token_secret = access_token.secret
        profile.put()

        self.redirect("/connect")
コード例 #11
0
ファイル: handlers.py プロジェクト: wyue/Instadrop
    def get(self):
        cookieutil = LilCookies(self, settings.COOKIE_SECRET)
        ig_user_id = cookieutil.get_secure_cookie(name="ig_user_id")

        dba = dropbox_auth.Authenticator(settings.DROPBOX_CONFIG)
        req_token = dba.obtain_request_token()

        profiles = Profile.all()
        profiles.filter("ig_user_id =", ig_user_id)
        profile = profiles.get()

        if not profile:
            self.redirect("/connect")
            return

        profile.db_oauth_token_key = req_token.key
        profile.db_oauth_token_secret = req_token.secret
        profile.put()

        authorize_url = dba.build_authorize_url(
            req_token, callback=settings.DROPBOX_CALLBACK)

        self.redirect(authorize_url)
コード例 #12
0
    def post(self):
        uid = self.request.get('uid')
        if uid is not None:
            taskqueue.add(url='/tasks/poll',
                          params={'uid': uid},
                          countdown=POLL_INTERVAL)
            user = DropboxUser.get_by_uid(uid)
            token = OAuthToken(user.oauth_token, user.oauth_token_secret)
            dba = auth.Authenticator(config)
            db_client = client.DropboxClient(config['server'],
                                             config['content_server'],
                                             config['port'], dba, token)
            account_info = json.loads(db_client.account_info().body)
            size = str(account_info['quota_info']['normal'])

            if user.size != size:
                params = {'changed': 'yeah'}
                urlfetch.fetch(url=user.callback_url,
                               payload=urllib.urlencode(params),
                               method='POST')

            user.size = size
            user.put()
コード例 #13
0
ファイル: dsktp_api_check.py プロジェクト: faizan-k/Sync-App
    def get_file(self, widget, data):

        # An object of the Authenticator class from oAuth authentication of our App
        config = auth.Authenticator.load_config("testing.ini")

        dba = auth.Authenticator(config)
        access_token = oauth.OAuthToken('k280uqm85ltjhop', 'bvsi4uto9muxmis')

        print access_token

        # An object of Client is created
        db_client = client.DropboxClient(config['server'],
                                         config['content_server'],
                                         config['port'], dba, access_token)
        root = config['root']

        # Prints the retrieved file
        resp = db_client.get_file(root, "/ourfile.txt")
        assert_equal(resp.status, 200)
        print resp.read()
        #assert len(resp.read()) > 100

        return db_client
コード例 #14
0
    def get(self, token):
        dba = auth.Authenticator(config)
        req_token = OAuthToken.from_string(
            base64.b64decode(urllib.unquote(token)))
        uid = self.request.get('uid')
        self.response.headers.add_header('Set-Cookie', 'uid=%s; path=/' % uid)

        token = dba.obtain_access_token(req_token, '')

        db_client = client.DropboxClient(config['server'],
                                         config['content_server'],
                                         config['port'], dba, token)
        account = json.loads(db_client.account_info().body)

        user = DropboxUser.get_by_uid(uid)
        user.oauth_token = token.key
        user.oauth_token_secret = token.secret
        user.email = account['email']
        user.put()

        if user.size is None:
            taskqueue.add(url='/tasks/poll', params={'uid': uid})

        self.redirect('/')
コード例 #15
0
 def __init__(self):
     super(dbAuth, self).__init__()
     self.dba = auth.Authenticator(config)
     self.baseToken = self.dba.obtain_request_token()
コード例 #16
0
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from models import DropboxUser
from oauth.oauth import OAuthToken
from simpledav.models import Resource
from simpledav.views import DAVHandler
from urllib import pathname2url
from urlparse import urlparse
from xml.etree import ElementTree as ET
import mimetypes
import os

# load the configuration file and make an authenticator
dropbox_ini_path = os.path.join(os.path.dirname(__file__), 'dropbox.ini')
dropbox_config = auth.Authenticator.load_config(dropbox_ini_path)
dropbox_auth = auth.Authenticator(dropbox_config)

# Either dropbox or sandbox
ROOT = "dropbox"

def site_root():
    scheme = "http" if "Development" in os.environ['SERVER_SOFTWARE'] else "https"
    return scheme + "://" + os.environ['HTTP_HOST']

def dropbox_client(access_token):
    return client.DropboxClient(dropbox_config['server'], dropbox_config['content_server'], 
                                80, dropbox_auth, access_token)

class AuthHandler(webapp.RequestHandler):
    def get(self):
        if self.request.GET.has_key('oauth_token'):