flask-security

Hiding fields in Flask-Admin depending on logged in user?

南楼画角 提交于 2019-12-01 01:21:16
I have Users and Roles in my Flask app thanks to Flask-Security. For some roles I would like to hide certain fields in the forms created by Flask-Admin. I know about customizing ModelViews with eg. form_create_rules = ('title', 'file') but while instantiating a ModelView there isn't access to the current request so current_user.has_role(USER_ROLE) can't be called. Is there any other way to achieve this? pjcunningham One way of achieving this is to create multiple view classes and register these view classes against their appropriate roles. See this answer on how to register roles to views.

Testing Flask login and authentication?

强颜欢笑 提交于 2019-11-30 12:04:50
问题 I'm developing a Flask application and using Flask-security for user authentication (which in turn uses Flask-login underneath). I have a route which requires authentication, /user . I'm trying to write a unit test which tests that, for an authenticated user, this returns the appropriate response. In my unittest I'm creating a user and logging as that user like so: from unittest import TestCase from app import app, db from models import User from flask_security.utils import login_user class

Using OpenID/Keycloak with Superset

扶醉桌前 提交于 2019-11-30 10:32:11
I want to use keycloak to authenticate my users in our Superset environment. Superset is using flask-openid, as implemented in flask-security: http://flask-appbuilder.readthedocs.io/en/latest/_modules/flask_appbuilder/security/manager.html https://pythonhosted.org/Flask-OpenID/ To enable a different user authentication than the regular one (database), you need to override the AUTH_TYPE parameter in your superset_config.py file. You will also need to provide a reference to your openid-connect realm and enable user registration. As I understand, it should look something like this: from flask

flask-security encrypt_password('mypassword') varies every time when i reload the page

只愿长相守 提交于 2019-11-29 17:28:16
I've already configured SECURITY_PASSWORD_SALT and use "bcrypt". But every time i reload the page print encrypt_password('mypassword') will print different values, so i can't verify user input password via verify_password(form.password.data, user.password) . But I can login from flask-security built-in login view Here is code to demonstrate the strange behavior of encrypt_password : from flask import Flask, render_template from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.security import Security, SQLAlchemyUserDatastore, \ UserMixin, RoleMixin, login_required from flask.ext.security

Using OpenID/Keycloak with Superset

瘦欲@ 提交于 2019-11-29 16:27:27
问题 I want to use keycloak to authenticate my users in our Superset environment. Superset is using flask-openid, as implemented in flask-security: http://flask-appbuilder.readthedocs.io/en/latest/_modules/flask_appbuilder/security/manager.html https://pythonhosted.org/Flask-OpenID/ To enable a different user authentication than the regular one (database), you need to override the AUTH_TYPE parameter in your superset_config.py file. You will also need to provide a reference to your openid-connect