Skip to main content

pypi travis

An authentication policy for Pyramid that automagically selects the correct policy to use for a specific request, given a list of authentication policies

Overview

SelectableAuthenticationPolicy is a Pyramid authentication policy that selects another provided IAuthenticationPolicy object, to provide a different auth policy based on the specific request. Simply pass it a list of policies that should be tried in order, and register the ‘selected_policy’ request method that will select and cache the correct policy to use:

policies = [
    IPAuthenticationPolicy("127.0.*.*", principals=["local"])
    IPAuthenticationPolicy("192.168.*.*", principals=["trusted"])
]
set_selectable_authentication_policy(config, policies)

This example uses the pyramid_ipauth module to assign effective principals based on originating IP address of the request. It combines two such policies so that requests originating from “127.0.*.*” will have principal “local” while requests originating from “192.168.*.*” will have principal “trusted”.

You can use the create_selectable_authentication_policy factory to just create the SelectableAuthenticationPolicy instance without setting it:

policies = [
    IPAuthenticationPolicy("127.0.*.*", principals=["local"])
    IPAuthenticationPolicy("192.168.*.*", principals=["trusted"])
]
policy = create_selectable_authentication_policy(config, policies)
policy.add_policy(IPAuthenticationPolicy("10.0.*.*", principals=["not-so-trusted"]))
config.set_authentication_policy(policy)

You can also just use config.include() to include the policy, and then add the subpolicies with the registered add_selectauth_policy directive on config:

config.include('pyramid_selectauth')
config.add_selectauth_policy(IPAuthenticationPolicy("127.0.*.*", principals=["local"]))
config.add_selectauth_policy(IPAuthenticationPolicy("192.168.*.*", principals=["trusted"]))

Policy selection method

The default selection method will call unauthenticated_userid on the provided policies in order, and select the first one that does not return None.

You can change the selection method by extending the SelectableAuthenticationPolicy and overriding the select_policy method with your logic to select the correct policy for the current request, and then specifying your class in the factories:

class MyPolicy(SelectableAuthenticationPolicy):
    def select_policy(self, request):
        return self._policies[0]  # Always uses the first policy (very useful!)


policies = [
    IPAuthenticationPolicy("127.0.*.*", principals=["local"])
    IPAuthenticationPolicy("192.168.*.*", principals=["trusted"])
]
policy = create_selectable_authentication_policy(config, policies, _class=MyPolicy)
config.set_authentication_policy(policy)

Deployment Settings

It is also possible to specify the authentication policies as part of your paste deployment settings. Consider the following example:

[app:pyramidapp]
use = egg:mypyramidapp

selectauth.policy_class = mypyramidapp.policies.MySelectAuthPolicy
selectauth.policies = mypyramidapp.policies.ipauthpolicyfactory mypyramidapp.policies.mypolicyfactory

To configure authentication from these settings, simply include the multiauth module into your configurator:

config.include("pyramid_selectauth")

1.0.1 - 2018-09-24

  • Refactored policy methods using proxy_method decorator.

1.0.0 - 2018-09-23

  • Production-ready release.

0.0.4 - 2018-09-21

  • Initial release.

Release files for pyramid-selectauth 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyramid-selectauth 1.0.1
File Size Uploaded
pyramid_selectauth-1.0.1.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyramid-selectauth 1.0.1
File Interpreter ABI Platform
pyramid_selectauth-1.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size:20.4 kB

Release files / pyramid_selectauth-1.0.1.tar.gz

Download URL pyramid_selectauth-1.0.1.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
69211a9c53637dffcb20cfd6836644c09b467e9b1b9eae63fcba22dc3d1dd4b4
BLAKE2b-256 checksum
How to use checksums
c00c74d186cc1c58f00d49c68a06d93e787f6c17a0bb97d073b4b32b1eb65acc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

Release files / pyramid_selectauth-1.0.1-py2.py3-none-any.whl

Download URL pyramid_selectauth-1.0.1-py2.py3-none-any.whl
Size 7.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5be9c56be90ceebf2de6825586fa54c0693aa2d7d52613f4731710146bf7d058
BLAKE2b-256 checksum
How to use checksums
70a686993a23a2f22e07ed11ccb3f782d0f3f0c11cec6f2517abb8e8c3809467
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page