Enterprise SSO with SAML
Connect the identity provider of a company by SAML, and send its people there by their email domain.
What it shows
- You add a SAML connection in the portal, with the entity ID, the sign-in address and the certificate of the identity provider.
- You give the connection an email domain. A person who types an address of that domain on the sign-in page goes to the identity provider.
- A person with no account signs in, and LumoAuth creates the account from the name and the email address of the assertion.
- A person who has an account with a password is refused. An administrator links the account with the CLI, and the next sign-in works.
The recipe uses a sample identity provider in a container. The steps are the same for Okta, Microsoft Entra ID and other providers.
Before you start
- Check that your plan includes enterprise SSO in the plans matrix.
- Docker, for the sample identity provider. It listens on
http://localhost:8080. The browser of the person makes the redirect to the identity provider, so a local address works for a test. - The lumo CLI and
jq, and an API key with the scopesadmin:users:readandadmin:users:write. - An account with a password for
sam.rivera@northwind.example.com. The setup script of One organization for each customer creates it.
| Variable | Value |
|---|---|
LUMOAUTH_URL | The address of LumoAuth: https://app.lumoauth.dev, or https://eu.app.lumoauth.dev for the EU region. |
LUMOAUTH_ORG_ID | Your organization, for example acme-corp. |
LUMOAUTH_API_KEY | An API key with the scopes admin:users:read and admin:users:write. |
SAML_IDP_ID | The number of the SAML connection. It is in the address of its edit page: /portal/saml-idps/7/edit. |
USER_EMAIL | Optional. The account to link. The default is sam.rivera@northwind.example.com. |
Start the sample identity provider, and print its certificate and the fingerprint of the certificate:
docker compose -f b2b/saml-sso/idp/compose.yaml up -d
docker compose -f b2b/saml-sso/idp/compose.yaml exec saml-idp cat /var/www/simplesamlphp/cert/server.crt > idp.crt
openssl x509 -in idp.crt -noout -fingerprint -sha256
Then add the connection in the portal:
- Open Settings, Integrations, and the section Enterprise SSO (SAML). Click Add SAML IdP.
- Display name:
Northwind Labs SSO. - Entity ID (issuer):
http://localhost:8080/simplesaml/saml2/idp/metadata.php. - SSO URL:
http://localhost:8080/simplesaml/saml2/idp/SSOService.php. - X.509 certificate (PEM): the text of
idp.crt. Certificate fingerprint (SHA-256): the value thatopensslprinted. - Allowed email domains:
northwind.example.com. Leave Just-in-time provisioning on. - In the box Login page, turn on Send people with these email domains here.
- Click Add identity provider.
A real identity provider has a metadata address. Paste it under Import from IdP metadata and click Fetch from metadata URL: the form fills itself. The identity provider needs the metadata of LumoAuth in return. The section shows the address, and the button Copy SP metadata URL copies it.
Code
The first three files are the sample identity provider. The script links an account that exists.
Run each command from the recipes folder of the examples repository. Set the folder up once for your language. Every version below was run against a LumoAuth organization. The portal steps and both sign-ins were followed with the sample identity provider of this folder. Importing from a metadata address was not checked: it needs a public https address.
- lumo CLI
# A sample SAML identity provider (SimpleSAMLphp) for tests on your machine.
# It signs with a key that everybody can download. Never use it for real people.
#
# docker compose -f b2b/saml-sso/idp/compose.yaml up -d
services:
saml-idp:
image: kenchan0130/simplesamlphp
ports:
- "8080:8080"
environment:
# The service provider is your LumoAuth organization.
SIMPLESAMLPHP_SP_ENTITY_ID: ${LUMOAUTH_URL:-https://app.lumoauth.dev}/orgs/${LUMOAUTH_ORG_ID}/saml/sp/metadata
SIMPLESAMLPHP_SP_ASSERTION_CONSUMER_SERVICE: ${LUMOAUTH_URL:-https://app.lumoauth.dev}/orgs/${LUMOAUTH_ORG_ID}/saml/sp/acs
volumes:
- ./authsources.php:/var/www/simplesamlphp/config/authsources.php:ro
- ./saml20-idp-hosted.php:/var/www/simplesamlphp/metadata/saml20-idp-hosted.php:ro
<?php
// The people of the sample identity provider. Both have the password "password".
$config = [
'admin' => ['core:AdminPassword'],
'example-userpass' => [
'exampleauth:UserPass',
// Maya has no account in LumoAuth. The first sign-in creates it.
'maya:password' => [
'email' => 'maya.chen@northwind.example.com',
'firstName' => 'Maya',
'lastName' => 'Chen',
],
// Sam has an account with a password. An administrator links it.
'sam:password' => [
'email' => 'sam.rivera@northwind.example.com',
'firstName' => 'Sam',
'lastName' => 'Rivera',
],
],
];
<?php
// The sample identity provider sends the email address as the NameID, so that
// a person has the same NameID at every sign-in.
$metadata['__DYNAMIC:1__'] = [
'host' => '__DEFAULT__',
'privatekey' => 'server.pem',
'certificate' => 'server.crt',
'auth' => 'example-userpass',
'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
'authproc' => [
3 => [
'class' => 'saml:AttributeNameID',
'attribute' => 'email',
'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
],
],
];
#!/bin/sh
# Link an account that has a password to a SAML connection, with the lumo CLI.
# After the link, the person signs in through the identity provider.
#
# sh b2b/saml-sso/cli/link.sh
set -eu
USER_EMAIL="${USER_EMAIL:-sam.rivera@northwind.example.com}"
# The CLI reads its own three variables. With them it needs no `lumo login`.
export LUMO_BASE_URL="$LUMOAUTH_URL" LUMO_ORG="$LUMOAUTH_ORG_ID" LUMO_API_KEY="$LUMOAUTH_API_KEY"
# Prints one line for each link of the account.
links() {
lumo users identities list "$USER_EMAIL" --output json \
| jq -r --arg when "$1" '.data.bindings | if length == 0 then "\($when): no link" else .[] | "\($when): \(.type), \(.idp_name), NameID \(.name_id)" end'
}
links "before"
# The NameID is the value that the identity provider sends for this person.
# The sample identity provider sends the email address. The link signs the
# person out everywhere and sends them an email.
lumo users identities link "$USER_EMAIL" --saml-idp "$SAML_IDP_ID" --name-id "$USER_EMAIL" > /dev/null
links "after"
sh b2b/saml-sso/cli/link.sh
Check the result
Open the sign-in page of your organization, type maya.chen@northwind.example.com and continue. The browser goes to the sample identity provider, and no password field of LumoAuth appears. Sign in there as maya with the password password. LumoAuth creates the account with the name Maya Chen.
Now do the same as sam with the address sam.rivera@northwind.example.com. LumoAuth refuses: "An account with this email address already exists and is not linked to this identity provider." The account has a password, so LumoAuth does not link it by itself. Run the script:
before: no link
after: saml, Northwind Labs SSO, NameID sam.rivera@northwind.example.com
Sign in as sam again: it works. lumo users identities list maya.chen@northwind.example.com shows the link of the account that LumoAuth created.
Limits
- The mapping of attributes is fixed. LumoAuth reads the email address, the first name, the last name and the display name. The portal has no editor for the mapping.
- A SAML connection gives no roles and reads no groups. A new account starts without roles. Give roles in the portal, through the Admin API or through SCIM groups.
- The certificate must hold an RSA key. LumoAuth refuses signatures that were made with SHA-1.
- A metadata address must be a public
httpsaddress. - A link signs the person out everywhere, and sends them an email.
- The sample identity provider signs with a key that everybody can download. Remove the connection after the test.