lmsaml authoring skill

lmsaml is a pure-Go single-binary SAML 2.0 Identity Provider (IdP), Service Provider (SP), REST API server, and LMScript host built on crewjam/saml and lmcode-go. It serves standard SAML 2.0 SSO/SLO and metadata endpoints, signs and verifies XML assertions with RSA-SHA256 and Exclusive C14N, and executes compiled _lmcode_ programs.

Purpose

Use lmsaml to launch an ephemeral or standalone SAML 2.0 IdP and SP for identity integration testing, provision users and SP metadata over REST or LMScript, issue cryptographically signed SAML 2.0 assertions, verify XML signatures and audience/time conditions, and expose standard lmcode_std_v3 REST and CLI interfaces.

When to use it

Choose lmsaml when testing SAML 2.0 Single Sign-On, Single Logout, SP-initiated AuthnRequest redirects, XML-DSig signature verification, or SAML attribute extraction. Pair lmsaml with lmconn saml or lmcurl for external HTTP/XML contract tests, lmldap when testing LDAPv3 directory binds and searches, or lmmock when mocking OAuth2, OIDC, and LLM APIs.

Install

Install the lmctl toolchain with npm install -g @lmctl-ai/lmctl@latest and build or download the zero-dependency lmsaml executable (CGO_ENABLED=0). When an LMScript program declares cli="lmsaml" and install="github:lmctl-ai/lmsaml@latest", the runtime validates and runs bytecode against the embedded lmsaml schema and 226-signature lmcode_std_v3 standard catalog.

lmscript --version
lmsaml --version
lmsaml --lmcode-schema --json
lmsaml --lmcode-signatures

Commands

lmsaml runs as a turnkey SAML 2.0 IdP/SP and REST HTTP server or as an _lmcode_ bytecode host, and interoperates directly with curl, lmcurl, and lmconn saml.

# Host schema, signatures, and bytecode execution
lmsaml --version
lmsaml --lmcode-schema --json
lmsaml --lmcode-signatures
lmsaml --host-signatures
lmsaml --lmcode build/program.dslb
lmsaml --dry-run --lmcode build/program.dslb

# Start SAML 2.0 IdP, SP, and REST API server
lmsaml --host 127.0.0.1 --port 8080 --rest-port 8081 --admin-user admin --admin-password admin-secret --require-auth

# Query SAML 2.0 metadata and SP-initiated SSO redirect
curl -s http://127.0.0.1:8080/idp/metadata
curl -s http://127.0.0.1:8080/sp/metadata
curl -s -D - -o /dev/null http://127.0.0.1:8080/sp/hello

# REST user provisioning, authentication, and signed assertion issuance/verification
curl -s http://127.0.0.1:8081/ping
curl -s -X PUT http://127.0.0.1:8081/users/alice -H "Content-Type: application/json" -d '{"password":"alice-pw","email":"alice@example.com","common_name":"Alice Smith","groups":["eng","security"]}'
curl -s -X POST http://127.0.0.1:8081/authn -H "Content-Type: application/json" -d '{"username":"alice","password":"alice-pw"}'
curl -s -X POST http://127.0.0.1:8081/assertion -H "Content-Type: application/json" -d '{"user":"alice"}'
curl -s -X POST http://127.0.0.1:8081/verify -H "Content-Type: application/json" -d '{"saml_response_b64":"..."}'

# Companion lmconn saml client commands
lmconn saml ping --port 8080
lmconn saml metadata --port 8080
lmconn saml user-add --port 8080 --user bob --email bob@example.com --password bob-pw
lmconn saml assertion --port 8080 --user bob
lmconn saml verify --port 8080 --response "$SAML_RESPONSE_B64"

Inputs and outputs

In server mode, lmsaml serves XML metadata (application/samlmetadata+xml) on /idp/metadata, /metadata, and /sp/metadata, HTML/redirect SSO flows on /idp/sso and /sp/hello, and JSON responses on /ping, /users, /services, /authn, /assertion, and /verify. In _lmcode_ mode, lmsaml exposes context saml: Saml, Batch, and print(string) alongside the 226 standard lmcode_std_v3 signatures. When SAML_REST_URL, SAML_REST_PORT, or SAML_PORT is set in the environment, context saml methods target the running server over HTTP; otherwise they operate against an isolated in-process SamlEngine and emit a terminal SDK invocation frame on stdout.

Safety rules

Follow these cryptographic and operational boundaries when authoring lmsaml workflows:

Worked examples

The first example provisions users, executes a multi-operation Batch pipeline, issues an RSA-SHA256 signed SAML 2.0 assertion, and verifies both valid and tampered payloads in LMScript:

p = _lmcode_ cli="lmsaml" install="github:lmctl-ai/lmsaml@latest";
let b = saml.batch();
b.ping()
 .add_user("carol", "{\"email\":\"carol@example.com\",\"password\":\"carol-pass\",\"common_name\":\"Carol Danvers\",\"groups\":[\"admins\"]}")
 .get_user("carol");
let batch_out = json_parse(b.exec());
assert_eq(batch_out.at(0).as_string(), "PONG");

assert_eq(saml.authenticate("carol", "carol-pass"), true);
assert_eq(saml.authenticate("carol", "wrong-pass"), false);

let issued = json_parse(saml.issue_assertion("carol", ""));
let xml = issued.get("xml").as_string();
let check_ok = json_parse(saml.verify_assertion(xml));
assert_eq(check_ok.get("valid").as_bool(), true);
assert_eq(check_ok.get("subject").as_string(), "carol@example.com");

let tampered = str_replace(xml, "carol@example.com", "mallory@example.com");
let check_bad = json_parse(saml.verify_assertion(tampered));
assert_eq(check_bad.get("valid").as_bool(), false);
lmcode_return_put("subject", check_ok.get("subject").as_string());
end _lmcode_
res = run_lmcode(p);
require(res.ok, json_stringify(res));

The second example combines context saml with the standard lmcode_std_v3 CliOption, CliCommand, and RestGet interfaces:

p = _lmcode_ cli="lmsaml" install="github:lmctl-ai/lmsaml@latest";
@"--org"
fn opt_org(x: RestExchange) -> void implements CliOption {
  x.set("org", x.query("org"));
}

@"enroll"
fn cmd_enroll(x: RestExchange) -> void implements CliCommand {
  let u = x.query("user");
  saml.add_user(u, "{\"email\":\"" + u + "@example.com\",\"password\":\"pw123\"}");
  let issued = json_parse(saml.issue_assertion(u, ""));
  let verified = json_parse(saml.verify_assertion(issued.get("saml_response_b64").as_string()));
  x.send(x.get("org") + ":" + u + ":valid=" + str(verified.get("valid").as_bool()));
}

@"/sso-user/:name"
fn get_sso_user(x: RestExchange) -> void implements RestGet {
  x.json(saml.get_user(x.param("name")));
}

rest_config("session", "global");
assert_eq(rest_cli(str_split("--org=acme enroll --user=grace", " ")), "acme:grace:valid=true");
assert(str_contains(rest_cli(str_split("/sso-user/grace", " ")), "grace@example.com"));
end _lmcode_

Errors and exit codes

lmsaml returns deterministic exit codes across server startup and _lmcode_ bytecode execution:

How to verify

Verify the lmsaml binary by checking its version, embedded schema JSON, canonical signature table, and the full SAML 2.0 integration test suite:

lmsaml --version
lmsaml --lmcode-schema --json > /tmp/lmsaml-schema.json
lmsaml --lmcode-signatures > /tmp/lmsaml-sigs.txt

In a source checkout, run ./test.sh to build the pure-Go binary, run all unit tests across the SAML 2.0 IdP/SP and XML encryption packages, and execute tests/integration-test.sh across SAML protocol endpoints, REST APIs, XML signature tampering checks, lmconn saml, lmcurl, and _lmcode_ Batch/REST/CLI scripts.