def grant_access_token(): secret_key = settings_get("SECRET_KEY") _token = security.create_signed_value( secret_key, "client_id", "porter") value = security.decode_signed_value( secret_key, "client_id", _token, settings_get("signature_expiration")) return _token
def init_users(): import redis params = dict( host=settings_get("REDIS_HOST"), port=settings_get("REDIS_PORT"), db=settings_get("REDIS_DB")) r = redis.StrictRedis(**params) users = { "porter": {} } r.set("users", json.dumps(users))
def test_current_user(): _access_token = get_access_token() _secret_key = get_secret_key() if not _access_token or not _secret_key: return None expiration = settings_get("signature_expiration") args = (_secret_key, "user_session", _access_token, expiration) current_user = decode_signed_value(*args) _redis = get_redis() users_cached = json.loads(_redis.get("users")) if not users_cached or current_user not in users_cached.keys(): return None return current_user
def get_redis(): conn = redis.StrictRedis(host=settings_get("REDIS_HOST"), port=settings_get("REDIS_PORT"), db=settings_get("REDIS_DB")) return conn
def get_secret_key(): secret = settings_get("secret_key") return secret
def settings_get(self, name, default=None): return settings_get(name, default)