Exemplo n.º 1
0
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
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def get_redis():
    conn = redis.StrictRedis(host=settings_get("REDIS_HOST"),
                             port=settings_get("REDIS_PORT"),
                             db=settings_get("REDIS_DB"))
    return conn
Exemplo n.º 5
0
def get_secret_key():
    secret = settings_get("secret_key")
    return secret
Exemplo n.º 6
0
 def settings_get(self, name, default=None):
     return settings_get(name, default)