コード例 #1
0
 def loadCredentials(self, userId):
     db = mongo()
     account = db.accounts.find_one({'user': userId, 'name': 'google'})
     if account is not None:
         jsonCredentials = account['jsonCredentials']
         return OAuth2Credentials.from_json(jsonCredentials)
     else:
         return False
コード例 #2
0
    def getCredentialsAndSave(self, code, userId):
        flow = self.getOAuthFlow()
        credentials = flow.step2_exchange(code)
        jsonCredentials = credentials.to_json()

        # Remove the old key (if there is one)
        # and add the new
        db = mongo()
        db.accounts.remove({'user': userId, 'name': 'google'})
        db.accounts.insert({
            'user': userId,
            'name': 'google',
            'jsonCredentials': jsonCredentials
        })
コード例 #3
0
    def performRequest(self):
        service = self.getOAuthService()

        # Retrieve required information from database
        db = mongo()
        account = db.accounts.find_one({'name': 'fitbit'})
        if account is not None:
            access_token = account['access_token']
            access_token_secret = account['access_token_secret']
        else:
            return False

        # Perform the request
        request = service.get_authenticated_session(access_token, access_token_secret, True)
        response = request.get('http://api.fitbit.com/1/user/-/profile.json')
        return response.content
コード例 #4
0
    def getCredentialsAndSave(self, code):
        flow = self.getOAuthFlow()
        credentials = flow.step2_exchange(code)
        jsonCredentials = credentials.to_json()

        # Find the user email that this account is associated with
        jsonCredentials = json.loads(jsonCredentials)
        userEmail = jsonCredentials['id_token']['email']

        # Remove the old key (if there is one)
        # and add the new
        db = mongo()
        db.users.remove({'email': userEmail})
        userId = db.users.insert({
            'email': userEmail,
            'jsonCredentials': jsonCredentials
        })

        # Return the user email so the session can be created
        return userEmail, userId
コード例 #5
0
    def getAccessKey(self, request_token, request_secret, oauth_verifier, userId):
        service = self.getOAuthService()
        response = service.get_access_token(method='GET',
            request_token=request_token,
            request_token_secret=request_secret,
            data={'oauth_verifier': oauth_verifier})
        data = response.content

        # Remove the old key (if there is one)
        # and add the new
        db = mongo()
        db.accounts.remove({'user': userId, 'name': 'fitbit'})
        db.accounts.insert({
            'user': userId,
            'name': 'fitbit',
            'access_token': data['oauth_token'],
            'access_token_secret': data['oauth_token_secret']
        })

        return True