{"id":13806016,"url":"https://github.com/mozilla-services/pyramid_multiauth","last_synced_at":"2025-06-23T10:36:12.774Z","repository":{"id":55049714,"uuid":"2618039","full_name":"mozilla-services/pyramid_multiauth","owner":"mozilla-services","description":"stacked authentication policies for pyramid","archived":false,"fork":false,"pushed_at":"2024-09-12T10:12:41.000Z","size":84,"stargazers_count":41,"open_issues_count":2,"forks_count":8,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-06-02T18:09:02.838Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mozilla-services.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.txt","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-10-21T04:06:46.000Z","updated_at":"2024-09-12T10:12:42.000Z","dependencies_parsed_at":"2024-06-18T18:36:00.979Z","dependency_job_id":"1bd75de2-446b-4b0a-a37d-91622df13b65","html_url":"https://github.com/mozilla-services/pyramid_multiauth","commit_stats":{"total_commits":83,"total_committers":12,"mean_commits":6.916666666666667,"dds":0.6265060240963856,"last_synced_commit":"b02ba4e94c8ba592b899d5460c46246b638353aa"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/mozilla-services/pyramid_multiauth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozilla-services%2Fpyramid_multiauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozilla-services%2Fpyramid_multiauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozilla-services%2Fpyramid_multiauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozilla-services%2Fpyramid_multiauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mozilla-services","download_url":"https://codeload.github.com/mozilla-services/pyramid_multiauth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozilla-services%2Fpyramid_multiauth/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261462738,"owners_count":23162024,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T01:01:07.193Z","updated_at":"2025-06-23T10:36:07.754Z","avatar_url":"https://github.com/mozilla-services.png","language":"Python","funding_links":[],"categories":["Authorization"],"sub_categories":[],"readme":"=================\npyramid_multiauth\n=================\n\n|pypi| |ci| |coverage|\n\n.. |pypi| image:: https://img.shields.io/pypi/v/pyramid_multiauth.svg\n    :target: https://pypi.python.org/pypi/pyramid_multiauth\n\n.. |ci| image:: https://github.com/mozilla-services/pyramid_multiauth/actions/workflows/test.yml/badge.svg\n    :target: https://github.com/mozilla-services/pyramid_multiauth/actions\n\n.. |coverage| image:: https://coveralls.io/repos/github/mozilla-services/pyramid_multiauth/badge.svg?branch=main\n    :target: https://coveralls.io/github/mozilla-services/pyramid_multiauth?branch=main\n\nAn authentication policy for Pyramid that proxies to a stack of other\nauthentication policies.\n\n\nOverview\n========\n\nMultiAuthenticationPolicy is a Pyramid authentication policy that proxies to\na stack of *other* IAuthenticationPolicy objects, to provide a combined auth\nsolution from individual pieces.  Simply pass it a list of policies that\nshould be tried in order::\n\n\n    policies = [\n        IPAuthenticationPolicy(\"127.0.*.*\", principals=[\"local\"])\n        IPAuthenticationPolicy(\"192.168.*.*\", principals=[\"trusted\"])\n    ]\n    authn_policy = MultiAuthenticationPolicy(policies)\n    config.set_authentication_policy(authn_policy)\n\nThis example uses the pyramid_ipauth module to assign effective principals\nbased on originating IP address of the request.  It combines two such\npolicies so that requests originating from \"127.0.*.*\" will have principal\n\"local\" while requests originating from \"192.168.*.*\" will have principal\n\"trusted\".\n\nIn general, the results from the stacked authentication policies are combined\nas follows:\n\n    * authenticated_userid:    return userid from first successful policy\n    * unauthenticated_userid:  return userid from first successful policy\n    * effective_principals:    return union of principals from all policies\n    * remember:                return headers from all policies\n    * forget:                  return headers from all policies\n\n\nDeployment Settings\n===================\n\nIt is also possible to specify the authentication policies as part of your\npaste deployment settings.  Consider the following example::\n\n    [app:pyramidapp]\n    use = egg:mypyramidapp\n\n    multiauth.policies = ipauth1 ipauth2 pyramid_browserid\n\n    multiauth.policy.ipauth1.use = pyramid_ipauth.IPAuthentictionPolicy\n    multiauth.policy.ipauth1.ipaddrs = 127.0.*.*\n    multiauth.policy.ipauth1.principals = local\n\n    multiauth.policy.ipauth2.use = pyramid_ipauth.IPAuthentictionPolicy\n    multiauth.policy.ipauth2.ipaddrs = 192.168.*.*\n    multiauth.policy.ipauth2.principals = trusted\n\nTo configure authentication from these settings, simply include the multiauth\nmodule into your configurator::\n\n    config.include(\"pyramid_multiauth\")\n\nIn this example you would get a MultiAuthenticationPolicy with three stacked\nauth policies.  The first two, ipauth1 and ipauth2, are defined as the name of\nof a callable along with a set of keyword arguments.  The third is defined as\nthe name of a module, pyramid_browserid, which will be processed via the\nstandard config.include() mechanism.\n\nThe end result would be a system that authenticates users via BrowserID, and\nassigns additional principal identifiers based on the originating IP address\nof the request.\n\nIf necessary, the *group finder function* and the *authorization policy* can\nalso be specified from configuration::\n\n    [app:pyramidapp]\n    use = egg:mypyramidapp\n\n    multiauth.authorization_policy = mypyramidapp.acl.Custom\n    multiauth.groupfinder  = mypyramidapp.acl.groupfinder\n\n    ...\n\n\nMultiAuthPolicySelected Event\n=============================\n\nAn event is triggered when one of the multiple policies configured is selected.\n\n::\n\n    from pyramid_multiauth import MultiAuthPolicySelected\n\n\n    # Track policy used, for prefixing user_id and for logging.\n    def on_policy_selected(event):\n        print(\"%s (%s) authenticated %s for request %s\" % (event.policy_name,\n                                                           event.policy,\n                                                           event.userid,\n                                                           event.request))\n\n    config.add_subscriber(on_policy_selected, MultiAuthPolicySelected)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmozilla-services%2Fpyramid_multiauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmozilla-services%2Fpyramid_multiauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmozilla-services%2Fpyramid_multiauth/lists"}