Skip to main content

smolsaml

PyPI - Version PyPI - Python Version Codecov


A very minimal SAML 2.0 SP implementation for modern Python versions.

Support

This library is not meant to be a full-featured SAML 2.0 implementation, but to provide a minimal, robust implementation without too many dependencies.

It has successfully been tested against:

  • Google Workspace SAML
  • Keycloak 12.0.4
  • Okta
  • Microsoft Azure AD
    • Please note that when using the federationmetadata.xml URL for metadata, you will need to specify your app's appid in the URL in order for Azure to supply the correct key material needed to validate the signature. IOW, https://login.microsoftonline.com/TENANTID/federationmetadata/2007-06/federationmetadata.xml?appid=APPID. Eliding the appid parameter will make things not work.

Installation

The package is available on PyPI.

pip install smolsaml

In addition, you will need the xmlsec (aka xmlsec1) utility, as to avoid a dependency on lxml and python-xmlsec (which can be a pain to install and may conflict with one another due to libxml version requirements).

  • On Debian/Ubuntu, this can be installed with apt install xmlsec1.
  • On macOS, this can be installed with brew install libxmlsec1.

Usage

We'll go ahead and assume you've chosen to use some sort of web framework (the library doesn't care).

The steps to authenticate a user are:

  • Construct an SPConfiguration that describes your application. The values need to match what you've configured in your IdP, and naturally the ACS URL will need to be hooked up somehow in your web framework.
  • Construct an IDPConfiguration; the easiest way to do this is IDPConfiguration.from_metadata_xml. (You'll need to have fetched the metadata yourself, the library doesn't care how you do that.)
  • Call initiate_login; you'll get a Redirect object, which describes where you'll want to whisk the user off to.
  • The user will authenticate with the IdP, and then be redirected back to your ACS URL.
  • In your ACS endpoint, read the SAMLResponse POST parameter. Call process_saml_response with it, and your configuration objects. This will raise an exception if the data is not valid. If it is valid, you'll get a SAMLResponse object back, which contains the user's attributes. It probably will be a good idea to try to disallow multiple SAMLResponses with the same ID; that sounds like a replay attack.

Unsupported features, known bugs, etc.

  • 👉 This library hasn't been tested against any IdPs other than the ones listed above. If you have a different IdP and it works, please let me know!
  • 👉 This library doesn't support practically any optional SAML 2.0 feature.
  • 👉 Not all claims that should probably be checked are currently checked.
  • Authentication request signing is currently not supported. However, happily, most IdPs don't require it.

License

smolsaml is distributed under the terms of the MIT license.

Release files for smolsaml 0.0.5

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

Source distribution (sdist)

Source distribution for smolsaml 0.0.5
File Size Uploaded
smolsaml-0.0.5.tar.gz 13.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for smolsaml 0.0.5
File Interpreter ABI Platform
smolsaml-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 30.9 kB

Release files / smolsaml-0.0.5.tar.gz

Download URL smolsaml-0.0.5.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1ffbc02616805491acc8b5dcba1dd46f55a16fcf9c937c826c20e7a3b126373b
BLAKE2b-256 checksum
How to use checksums
7970df6203f4f6a50ee39ffded7fceed7edea0017759af16860b279bc851d6e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / smolsaml-0.0.5-py3-none-any.whl

Download URL smolsaml-0.0.5-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9ca3fd7e1b34582fd18fc4245e35d67e5bbfef374a277c6b521de11e4f7df79
BLAKE2b-256 checksum
How to use checksums
30d0f8edfa644660204f3f25f59bec5006b469fca1daf00b86754e6b0ea6922e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

1 release file

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