Ejemplo n.º 1
0
    def RetrieveAuthorizationToken(self, req, level):
        from tapiriik.services import Service
        tokenKey = req.GET["oauth_token"]

        redis_key = "dropbox:oauth:%s" % tokenKey
        token = redis.get(redis_key)
        assert token
        token = pickle.loads(token)
        redis.delete(redis_key)

        full = level == "full"
        if full:
            sess = session.DropboxSession(DROPBOX_FULL_APP_KEY,
                                          DROPBOX_FULL_APP_SECRET, "dropbox")
        else:
            sess = session.DropboxSession(DROPBOX_APP_KEY, DROPBOX_APP_SECRET,
                                          "app_folder")

        accessToken = sess.obtain_access_token(token)

        uid = int(req.GET["uid"])  # duh!
        return (uid, {
            "Key": accessToken.key,
            "Secret": accessToken.secret,
            "Full": full
        })
Ejemplo n.º 2
0
 def RetrieveAuthorizationToken(self, req, level):
     redis_token_key = "endomondo:oauth:%s" % req.GET["oauth_token"]
     secret = redis.get(redis_token_key)
     assert secret
     redis.delete(redis_token_key)
     oauthSession = self._oauthSession(resource_owner_secret=secret)
     oauthSession.parse_authorization_response(req.get_full_path())
     tokens = oauthSession.fetch_access_token("https://api.endomondo.com/oauth/access_token")
     userInfo = oauthSession.get("https://api.endomondo.com/api/1/user")
     userInfo = userInfo.json()
     return (userInfo["id"], {"Token": tokens["oauth_token"], "Secret": tokens["oauth_token_secret"]})
Ejemplo n.º 3
0
 def RetrieveAuthorizationToken(self, req, level):
     redis_token_key = "endomondo:oauth:%s" % req.GET["oauth_token"]
     secret = redis.get(redis_token_key)
     assert secret
     redis.delete(redis_token_key)
     oauthSession = self._oauthSession(resource_owner_secret=secret)
     oauthSession.parse_authorization_response(req.get_full_path())
     tokens = oauthSession.fetch_access_token("https://api.endomondo.com/oauth/access_token")
     userInfo = oauthSession.get("https://api.endomondo.com/api/1/user")
     userInfo = userInfo.json()
     return (userInfo["id"], {"Token": tokens["oauth_token"], "Secret": tokens["oauth_token_secret"]})
Ejemplo n.º 4
0
	def Get(self, pk, freshen=False):
		res = redis.get(self._cacheKey % pk)
		if res:
			try:
				res = pickle.loads(res)
			except pickle.UnpicklingError:
				redis.delete(self._cacheKey % pk)
				res = None
			else:
				if self._autorefresh or freshen:
					redis.expire(self._cacheKey % pk, self._lifetime)
			return res
Ejemplo n.º 5
0
 def Get(self, pk, freshen=False):
     res = redis.get(self._cacheKey % pk)
     if res:
         try:
             res = pickle.loads(res)
         except pickle.UnpicklingError:
             redis.delete(self._cacheKey % pk)
             res = None
         else:
             if self._autorefresh or freshen:
                 redis.expire(self._cacheKey % pk, self._lifetime)
         return res
Ejemplo n.º 6
0
    def RetrieveAuthorizationToken(self, req, level):
        from tapiriik.services import Service
        tokenKey = req.GET["oauth_token"]

        redis_key = "dropbox:oauth:%s" % tokenKey
        token = redis.get(redis_key)
        assert token
        token = pickle.loads(token)
        redis.delete(redis_key)

        full = level == "full"
        if full:
            sess = session.DropboxSession(DROPBOX_FULL_APP_KEY, DROPBOX_FULL_APP_SECRET, "dropbox")
        else:
            sess = session.DropboxSession(DROPBOX_APP_KEY, DROPBOX_APP_SECRET, "app_folder")

        accessToken = sess.obtain_access_token(token)

        uid = int(req.GET["uid"])  # duh!
        return (uid, {"Key": accessToken.key, "Secret": accessToken.secret, "Full": full})
Ejemplo n.º 7
0
 def Delete(self, pk):
     redis.delete(self._cacheKey % pk)
Ejemplo n.º 8
0
 def Delete(self, pk):
     redis.delete(self._cacheKey % pk)