Exemple #1
0
    def init_app(self, app):
        """Initialize the extension for a Flask application.

        This is only necessary if the application was not provided in the
        constructor, e.g. because there is more than one application or you
        are using an application factory.

        :param app: The flask application
        """
        if 'multipass' in app.extensions:
            raise RuntimeError('Flask application already initialized')
        state = app.extensions['multipass'] = _MultipassState(self, app)
        # TODO: write docs for the config (see flask-cache for a pretty example)
        app.config.setdefault('MULTIPASS_AUTH_PROVIDERS', {})
        app.config.setdefault('MULTIPASS_IDENTITY_PROVIDERS', {})
        app.config.setdefault('MULTIPASS_PROVIDER_MAP', {})
        app.config.setdefault('MULTIPASS_IDENTITY_INFO_KEYS', None)
        app.config.setdefault('MULTIPASS_LOGIN_SELECTOR_TEMPLATE', None)
        app.config.setdefault('MULTIPASS_LOGIN_FORM_TEMPLATE', None)
        app.config.setdefault('MULTIPASS_LOGIN_ENDPOINT', 'login')
        app.config.setdefault('MULTIPASS_LOGIN_URLS', ('/login/', '/login/<provider>'))
        app.config.setdefault('MULTIPASS_SUCCESS_ENDPOINT', 'index')
        app.config.setdefault('MULTIPASS_FAILURE_MESSAGE', 'Authentication failed: {error}')
        app.config.setdefault('MULTIPASS_FAILURE_CATEGORY', 'error')
        app.config.setdefault('MULTIPASS_ALL_MATCHING_IDENTITIES', False)
        app.config.setdefault('MULTIPASS_REQUIRE_IDENTITY', True)
        with app.app_context():
            self._create_login_rule()
            state.auth_providers = ImmutableDict(self._create_providers('AUTH', AuthProvider))
            state.identity_providers = ImmutableDict(self._create_providers('IDENTITY', IdentityProvider))
            state.provider_map = ImmutableDict(get_canonical_provider_map(current_app.config['MULTIPASS_PROVIDER_MAP']))
            validate_provider_map(state)
Exemple #2
0
    def init_app(self, app):
        """Initialize the extension for a Flask application.

        This is only necessary if the application was not provided in the
        constructor, e.g. because there is more than one application or you
        are using an application factory.

        :param app: The flask application
        """
        if 'multipass' in app.extensions:
            raise RuntimeError('Flask application already initialized')
        state = app.extensions['multipass'] = _MultipassState(self, app)
        # TODO: write docs for the config (see flask-cache for a pretty example)
        app.config.setdefault('MULTIPASS_AUTH_PROVIDERS', {})
        app.config.setdefault('MULTIPASS_IDENTITY_PROVIDERS', {})
        app.config.setdefault('MULTIPASS_PROVIDER_MAP', {})
        app.config.setdefault('MULTIPASS_IDENTITY_INFO_KEYS', None)
        app.config.setdefault('MULTIPASS_LOGIN_SELECTOR_TEMPLATE', None)
        app.config.setdefault('MULTIPASS_LOGIN_FORM_TEMPLATE', None)
        app.config.setdefault('MULTIPASS_LOGIN_ENDPOINT', 'login')
        app.config.setdefault('MULTIPASS_LOGIN_URLS', ('/login/', '/login/<provider>'))
        app.config.setdefault('MULTIPASS_SUCCESS_ENDPOINT', 'index')
        app.config.setdefault('MULTIPASS_FAILURE_MESSAGE', 'Authentication failed: {error}')
        app.config.setdefault('MULTIPASS_FAILURE_CATEGORY', 'error')
        app.config.setdefault('MULTIPASS_ALL_MATCHING_IDENTITIES', False)
        app.config.setdefault('MULTIPASS_REQUIRE_IDENTITY', True)
        with app.app_context():
            self._create_login_rule()
            state.auth_providers = ImmutableDict(self._create_providers('AUTH', AuthProvider))
            state.identity_providers = ImmutableDict(self._create_providers('IDENTITY', IdentityProvider))
            state.provider_map = ImmutableDict(get_canonical_provider_map(current_app.config['MULTIPASS_PROVIDER_MAP']))
            validate_provider_map(state)
def test_get_canonical_provider_map(config_map, canonical_map):
    assert get_canonical_provider_map(config_map) == canonical_map
Exemple #4
0
def test_get_canonical_provider_map(config_map, canonical_map):
    assert get_canonical_provider_map(config_map) == canonical_map