Skip to content

MBXSystems/simple_saml

Repository files navigation

SimpleSaml

Build Status Module Version Hex Docs Total Download License Last Updated

This library is a helper for adding SAML service provider functionality without relying on xmerl and thus being vulnerable to atom exhaustion. It does so by using the simple_xml, which in turn uses saxy to generate a string based DOM reprsentation.

Usage

SAML Response

# Parse a SAML response.
{:ok, {root, %Assertion{} = assertion}} = SimpleSaml.parse_response(saml_response)

# Identify the IDP based on the audience within the asserion and obtain the associated parameters: issuer (e.g. "http://www.okta.com/exka5ha6bknY6Okd85d7"), audience (i.e. a fix string your application provided to the IDP), and the SAML certificate of the IDP

# SAML certificates are typically stored in PEM or Der format.  Here's an example of how to obtain the public key using the X509 library:
# Assume cert_pem contains the string contents of the certificate pem file
{:ok, cert} = X509.Certificate.from_pem(cert_pem)
public_key = X509.Certificate.public_key(cert)

# Use the public key to verify and validate
:ok = SimpleSaml.verify_and_validate_response(root, assertion, public_key)

# Validate that assertion.issuer, assertion.recipient values match your expected values for the IDP

# At this point, you're ready to use the assertion.name_id claim within your application to
# authenticate the user.

Installation

The package can be installed, via Hex, by adding simple_saml to your list of dependencies in mix.exs:

def deps do
  [
    {:simple_saml, "~> 1.0.0"}
  ]
end

Contributing

We welcome merge requests for fixing issues or expanding functionality.

Clone and compile with:

git clone https://github.com/MBXSystems/simple_saml.git
cd simple_saml
mix deps.get
mix compile

Verify that tests and linting pass with your changes.

mix test
mix lint

All code changes should be accompanied with unit tests.

License

MIT License

Copyright (c) 2023 AHEAD, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A helper for adding SAML service provider functionality without relying on xmerl.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published