コード例 #1
0
 def __init__(self):
     self.logger = logging.getLogger('dbox')
     db = dbprovider.DB()
     self.api_client = None
     if TEST:
         access_token = TEST_TOKEN
     else:
         access_token = db.get_provider_token('dropbox')
     if access_token is None:
         flow = client.DropboxOAuth2FlowNoRedirect(CLIENT_ID, CLIENT_SECRET)
         authorize_url = flow.start()
         sys.stdout.write(
             "0. Make sure you are logged in at  your account.\n")
         sys.stdout.write("1. Go to: " + authorize_url + "\n")
         sys.stdout.write(
             "2. Click \"Allow\" (you might have to log in first).\n")
         sys.stdout.write("3. Copy the authorization code.\n")
         code = raw_input("Enter the authorization code here: ").strip()
         try:
             access_token, user_id = flow.finish(code)
             db.set_provider_token('dropbox', access_token)
             self.logger.info('Successful login with user %s' %
                              str(user_id))
         except rest.ErrorResponse, e:
             self.logger.error('Error: %s\n' % str(e))
コード例 #2
0
def getAccessToken():
    access_token = None
    #Get the session_id (uuid). Create one if there is none yet.
    sessionId = ADDON.getSetting('session_id').decode("utf-8")
    if sessionId == '':
         sessionId = str(uuid.uuid1())
         ADDON.setSetting('session_id', sessionId)
    #Try to get a access_code
    key, secret = decode_key(APP_KEY).split('|')
    flow = client.DropboxOAuth2FlowNoRedirect(key, secret)
    authorize_url = flow.start()
    oauth = DbmcOauth2()
    result, accesscode, pin = oauth.getAccessCode(sessionId, authorize_url)
    if result != SUCCES:
        log_error('Failed to get the PIN/accesscode: %s'%result)
        dialog = xbmcgui.Dialog()
        dialog.ok(ADDON_NAME, LANGUAGE_STRING(30200), '%s'%result)
    elif accesscode == '':
        #No accesscode yet, so direct to web=page with PIN
        log('No accesscode, goto web-page with PIN: %s'%pin)
        dialog = xbmcgui.Dialog()
        dialog.ok(ADDON_NAME, LANGUAGE_STRING(30002), LANGUAGE_STRING(30003), LANGUAGE_STRING(30001) + pin )
    else:
        #Accesscode present, so try to get the access token now
        log_debug('Accesscode recieved: %s. Getting access token...'%accesscode)
        #start the flow process (getting the auth-code
        try:
            access_token, user_id = flow.finish(accesscode)
            log('Access token received')
        except rest.ErrorResponse, e:
            log_error('Failed getting the access token: %s'%str(e))
            dialog = xbmcgui.Dialog()
            dialog.ok(ADDON_NAME, LANGUAGE_STRING(30201), str(e), LANGUAGE_STRING(30202))
        finally:
コード例 #3
0
    def do_login(cls):
        """
        Log in to a Dropbox account

        Parameters: n/a
        Returns: n/a
        """
        try:
            key_file = open(cls.APPKEY_FILE, "r")
        except IOError:
            print "No app_key.txt. Exiting."
            sys.exit()
        keys = key_file.readlines()
        app_key = keys[0].strip()
        app_secret = keys[1].strip()
        flow = client.DropboxOAuth2FlowNoRedirect(app_key, app_secret)
        authorize_url = flow.start()
        sys.stdout.write("1. Go to: " + authorize_url + "\n")
        sys.stdout.write("2. Click \"Allow\" "
                         "(you might have to log in first).\n")
        sys.stdout.write("3. Copy the authorization code.\n")
        code = raw_input("Enter the authorization code here: ").strip()

        try:
            access_token, user_id = flow.finish(code)
        except rest.ErrorResponse, e:
            sys.stdout.write('Error: %s\n' % str(e))
            return
コード例 #4
0
    def __init__(self, app_key, app_secret, store, prefix = "/"):
        self.app_key = app_key
        self.app_secret = app_secret
        self.path_prefix = prefix
        self.cursor = None
        self.db = store

        self.api_client = None
        try:
            serialized_token = open(self.TOKEN_FILE).read()
            if serialized_token.startswith('oauth2:'):
                access_token = serialized_token[len('oauth2:'):]
                self.api_client = client.DropboxClient(access_token)
                print("Loaded OAuth 2 access token.")
            else:
                print("Malformed access token in %r." % (self.TOKEN_FILE,))
        except IOError:
            sys.stdout.write("An access token file could not be loaded.\n")
            flow = client.DropboxOAuth2FlowNoRedirect(self.app_key, self.app_secret)
            authorize_url = flow.start()
            sys.stdout.write("1. Go to: " + authorize_url + "\n")
            sys.stdout.write("2. Click \"Allow\" (you might have to log in first).\n")
            sys.stdout.write("3. Copy the authorization code.\n")
            code = raw_input("Enter the authorization code here: ").strip()

            try:
                access_token, user_id = flow.finish(code)
            except rest.ErrorResponse, e:
                self.stdout.write('Error: %s\n' % str(e))
                return

            with open(self.TOKEN_FILE, 'w') as f:
                f.write('oauth2:' + access_token)
            self.api_client = client.DropboxClient(access_token)
コード例 #5
0
def do_login(app_key, app_secret, code):
    flow = client.DropboxOAuth2FlowNoRedirect(app_key, app_secret)
    flow.start()
    try:
        token, _ = flow.finish(code.strip())
        return token
    except Exception as e:
        print "Error login: ", e
コード例 #6
0
    def start_connection(self):
        """
        Initialize Dropbox connection
        """
        self.flow = client.DropboxOAuth2FlowNoRedirect(APP_KEY, APP_SECRET)

        # Have the user sign in and authorize this token
        authorize_url = self.flow.start()
        return authorize_url
コード例 #7
0
    def do_login(self):
        """log in to a Dropbox account"""
        flow = client.DropboxOAuth2FlowNoRedirect(self.app_key, self.app_secret)
        authorize_url = flow.start()
        sys.stdout.write("1. Go to: " + authorize_url + "\n")
        sys.stdout.write("2. Click \"Allow\" (you might have to log in first).\n")
        sys.stdout.write("3. Copy the authorization code.\n")
        code = raw_input("Enter the authorization code here: ").strip()

        try:
            access_token, user_id = flow.finish(code)
        except rest.ErrorResponse, e:
            self.stdout.write('Error: %s\n' % str(e))
            return
コード例 #8
0
def get_new_dropbox_tokens():
    """Helps the user auth this app with Dropbox, and stores the tokens in a file"""

    flow = client.DropboxOAuth2FlowNoRedirect(DROPBOX_KEY, DROPBOX_SECRET)
    authorize_url = flow.start()

    print "Looks like you haven't allowed this app to access your Dropbox account yet!"
    print "1. Visit " + authorize_url
    print "2. Click \"Allow\" (you might have to log in first)"
    print "3. Copy the authorization code"

    code = raw_input("Enter authorization code here: ").strip()
    access_token, user_id = flow.finish(code)

    token_file = open(DROPBOX_TOKEN_FILE, 'w')
    token_file.write(access_token)
    token_file.close()
コード例 #9
0
def auth():
    if not config.is_useable():
        warn()
        return
    from dropbox import client
    flow = client.DropboxOAuth2FlowNoRedirect(config.app_key,
                                              config.app_secret)
    authorize_url = flow.start()

    print('1. Go to: ' + authorize_url)
    print('2. Click "Allow" (you might have to log in first)')
    print('3. Copy the authorization code.')

    code = input('Enter the authorization code here: ').strip()

    access_token, user_id = flow.finish(code)

    config.token = (access_token, user_id)
コード例 #10
0
class DropView(BrowserView):
    """ Dropbox view Bok.
    """
    
    app_key = ''
    app_secret = ''
    
    flow = client.DropboxOAuth2FlowNoRedirect(app_key, app_secret)
    #authorize_url = flow.start()

    # Have the user sign in and authorize this token
    #authorize_url = flow.start()
    #print '1. Go to: ' + authorize_url
    #print '2. Click "Allow" (you might have to log in first)'
    #print '3. Copy the authorization code.'
    #code = raw_input("Enter the authorization code here: ").strip()

    template = ViewPageTemplateFile('book.pt')

    def __call__(self):
        import pdb; pdb.set_trace()
        metadata = DropboxClient.metadata('/bok')
        files = [content['path'].split('/')[-1] for content in metadata['contents']]
        return self.template(self.context)
コード例 #11
0
def get_auth_url():
    flow = client.DropboxOAuth2FlowNoRedirect(
        config.APP_KEY, config.APP_SECRET)
    return flow.start()