Python flask_principal.Principal() Examples
The following are 7
code examples of flask_principal.Principal().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask_principal
, or try the search function
.
Example #1
Source File: core.py From flask-security with MIT License | 5 votes |
def _get_principal(app): p = Principal(app, use_sessions=False) p.identity_loader(_identity_loader) return p
Example #2
Source File: __init__.py From flaskapp with MIT License | 5 votes |
def on_identity_loaded(sender, identity): """Method for Flask Principal identity load listener """ # set the identity user object identity.user = current_user if current_user.is_authenticated: # add UserNeed to identity identity.provides.add(UserNeed(current_user.id))
Example #3
Source File: engine.py From Flask-Blogging with MIT License | 5 votes |
def init_app(self, app, storage=None, cache=None, file_upload=None): """ Initialize the engine. :param app: The app to use :type app: Object :param storage: The blog storage instance that implements the :type storage: Object :param cache: (Optional) A Flask-Cache object to enable caching :type cache: Object ``Storage`` class interface. """ self.app = app self.config = self.app.config self.storage = storage or self.storage self.file_upload = file_upload or self.file_upload self.cache = cache or self.cache self._register_plugins(self.app, self.config) from .views import create_blueprint blog_app = create_blueprint(__name__, self) # external urls blueprint_created.send(self.app, engine=self, blueprint=blog_app) self.app.register_blueprint( blog_app, url_prefix=self.config.get("BLOGGING_URL_PREFIX")) self.app.extensions["FLASK_BLOGGING_ENGINE"] = self # duplicate self.app.extensions["blogging"] = self self.principal = Principal(self.app) engine_initialised.send(self.app, engine=self) if self.config.get("BLOGGING_ALLOW_FILEUPLOAD", True): self.ffu = self.file_upload or FlaskFileUpload(app)
Example #4
Source File: security.py From flask-unchained with MIT License | 5 votes |
def _get_principal(self, app: FlaskUnchained) -> Principal: """ Get an initialized instance of Flask Principal's. :class:~flask_principal.Principal`. """ principal = Principal(app, use_sessions=False) principal.identity_loader(self._identity_loader) return principal
Example #5
Source File: security.py From flask-unchained with MIT License | 5 votes |
def _identity_loader(self) -> Union[Identity, None]: """ Identity loading function to be passed to be assigned to the Principal instance returned by :meth:`_get_principal`. """ if not isinstance(current_user._get_current_object(), AnonymousUser): return Identity(current_user.id)
Example #6
Source File: test_v2_tuf.py From quay with Apache License 2.0 | 5 votes |
def app_with_principal(): app = flask.Flask(__name__) app.config.from_object(testconfig.TestConfig()) principal = Principal(app) return app, principal
Example #7
Source File: __init__.py From flaskapp with MIT License | 4 votes |
def create_app(extra_config=None): """Create Flask app for Flaskapp """ app = Flask('flaskapp', template_folder='templates', static_folder='static') app.config.from_object('config') app.config.update(**(extra_config or {})) app.before_request(before_request) # import static file manifest js = pkg_resources.resource_string('flaskapp', '/static/rev-manifest.json') app.config['static_manifest'] = json.loads(js.decode('utf-8')) # configure jinja2 app.jinja_env.globals.update({'h': template_helpers}) # add Flask-WTForms CSRF Protection CSRFProtect(app) # init Flask-SQLAlchemy db.init_app(app) # init Flask-Principal Principal(app) identity_loaded.connect(on_identity_loaded, app) # init Flask-Login lm.init_app(app) lm.login_view = 'auth.login' lm.user_loader(load_user) # init Flask-Mail mail.init_app(app) # register blueprints app.register_blueprint(content.bp) app.register_blueprint(auth.bp, url_prefix='/auth') return app # =============================== # Helper methods # ===============================