Example #1
0
def test_adds_auth_endpoint():
    app = Flask(__name__)
    app.config["SECRET_KEY"] = "super-secret"
    app.config["JWT_AUTH_URL_RULE"] = "/auth"
    app.config["JWT_AUTH_ENDPOINT"] = "jwt_auth"
    flask_jwt.JWT(app)
    rules = [str(r) for r in app.url_map._rules]
    assert "/auth" in rules
Example #2
0
    "port": 5000,
    "secret_key": "SECRET_KEY",
}

if len(sys.argv) >= 2:
    if not os.path.isfile(sys.argv[1]):
        print(sys.argv[1], "cannot be found")
        sys.exit(0)
    with open(sys.argv[1], "r") as stream:
        config.update(yaml.load(stream))

Base = declarative_base()

app = Flask(__name__, static_folder="web")
app.config["SECRET_KEY"] = config["secret_key"]
app.config["JWT_AUTH_URL_RULE"] = "/auth"
api = Api(app, prefix="/api/v1")


def authenticate(username, password):
    user = db_session.query(User).filter(User.email == username).scalar()
    if user and verify_password(password, user.password):
        db_session.query(User).filter(User.email == username).update({User.last_login: datetime.datetime.now()})
        db_session.commit()
        return user


def identity(payload):
    return db_session.query(User).filter(User.id == payload["identity"]).scalar()