← Back to Official Package Registry
Tier 4: FinTech, GraphQL, CDP & SSO • SAML 2.0, OIDC JWKS & SCIM 2.0v1.0.0 • 69 KB • Ed25519 Verified

ldap_saml@1.0.0

Enterprise B2B SAML 2.0 SP AuthnRequest & signed Assertion verifier, OIDC JWKS keyset matcher, and SCIM 2.0 /Users & /Groups provisioning.

use [ldap_saml]use [ldap_saml/scim]
veko pkg add ldap_saml@1.0.0
Run in Browser PlaygroundDownload 1.0.0.vkpRaw demo.vk

ldap_saml

Pure-Veko Enterprise Single Sign-On (SSO): OASIS SAML 2.0 Service Provider (AuthnRequest, EntityDescriptor, W3C XML-DSig verification over Ed25519 / ECDSA P-256 / RSA-PSS), OpenID Connect Discovery & JWKS, and RFC 7643 / RFC 7644 SCIM 2.0 Directory Provisioning (ldap_saml, ldap_saml/scim).

Overview

ldap_saml equips Veko services with enterprise identity federation and automated user lifecycle provisioning:

  • ldap_saml (SAML 2.0 & OIDC / JWKS):
  • SAML 2.0 Service Provider (SP): build-authn-request (generates OASIS samlp:AuthnRequest XML, compresses via raw RFC 1951 DEFLATE, Base64-encodes, and builds the HTTP-Redirect URL), build-sp-metadata (md:EntityDescriptor XML), sign-test-saml-response (in-memory signed IdP fixture generator), and verify-saml-response.
  • Two-Stage W3C XML-DSig & XSW Hardening: verify-saml-response enforces single-Assertion XML Signature Wrapping (XSW) defense, constant-time SHA-256 DigestValue verification over the enveloped-signature-stripped <saml:Assertion>, cryptographic SignatureValue verification over <ds:SignedInfo> (Ed25519, ECDSA P-256, RSA-PSS SHA-256), InResponseTo + seen_ids replay prevention, NotBefore/NotOnOrAfter window checks, and AudienceRestriction.
  • OIDC Discovery & JWKS: build-oidc-configuration, jwk-from-ed25519 (RFC 8037 OKP), jwk-from-p256 (RFC 7517 EC), select-jwk-by-kid, and validate-id-token-claims (iss, aud, exp, nbf, nonce).
  • ldap_saml/scim (RFC 7643 / RFC 7644 SCIM 2.0):
  • Core User, Group, ListResponse, and Error (application/scim+json) schema codecs.
  • Recursive-descent SCIM 2.0 filter parser and evaluator supporting dotted/multi-valued paths (emails.value co "@acme.io", userName eq "ada@acme.io"), eq, ne, co, sw, ew, pr, gt, ge, lt, le, and, or, not, and ( ... ).
  • RFC 7644 PatchOp engine (add, replace, remove, pathless Okta/Entra object replacement, and filtered multi-valued removal) plus ScimDirectory mountable directly on web/App (/scim/v2/Users, /scim/v2/Groups).

Installation

powershell
veko pkg add ldap_saml@1.0.0

Import the modules in .vk source files:

rebol
use [
    sso  = ldap_saml
    scim = ldap_saml/scim
]

Architecture & Security Model

SAML 2.0 Assertion Verification Pipeline

  1. Base64-decode SAMLResponse and validate <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>.
  2. Locate <saml:Assertion> and reject payloads containing multiple Assertion elements (XML Signature Wrapping defense).
  3. Verify <ds:Reference URI="#<AssertionID>">, strip <ds:Signature>, compute SHA-256 over the canonical <saml:Assertion>, and compare in constant time (bits/ct-eq?) against <ds:DigestValue>.
  4. Verify <ds:SignatureValue> over <ds:SignedInfo> using crypto/x25519 (Ed25519) or crypto/sig (ECDSA P-256 / RSA-PSS).
  5. Enforce Issuer == sp.idp_entity_id, Audience == sp.entity_id, InResponseTo, seen_ids replay cache, and NotBefore <= now < NotOnOrAfter (with sp.clock_skew_sec).

Complete API Reference

ldap_saml

  • Structs: SpConfig, AuthnRequestBundle, SamlPrincipal
  • SAML 2.0 Functions:
  • build-authn-request [sp SpConfig, request_id str, issue_instant str /relay-state relay str = ''] AuthnRequestBundle
  • inflate-authn-request [deflated_b64 str] str
  • build-sp-metadata [sp SpConfig] str
  • verify-saml-response [sp SpConfig, saml_response_b64 str /expected-req-id req_id str = '' /now-sec now i64 = -1 /seen-ids cache any = .none] SamlPrincipal
  • sign-test-saml-response [idp_entity_id str, sp_entity_id str, acs_url str, in_response_to str, name_id str, not_before str, not_on_or_after str, attributes map, alg str, signing_key bytes ...] str
  • OIDC & JWKS Functions:
  • build-oidc-configuration [issuer str] map
  • jwk-from-ed25519 [kid str, pubkey32 bytes] map
  • jwk-from-p256 [kid str, pubkey65 bytes] map
  • select-jwk-by-kid [jwks map, kid str] map
  • validate-id-token-claims [claims map, expected_iss str, expected_aud str, expected_nonce str /now-sec now i64 = -1 /leeway skew i64 = 30] enum

ldap_saml/scim

  • Constants: SCHEMA-USER, SCHEMA-GROUP, SCHEMA-LIST, SCHEMA-PATCH, SCHEMA-ERROR, SCIM-CONTENT-TYPE
  • Functions:
  • normalize-user [raw map, id str, base_url str /created ts str = ''] map
  • normalize-group [raw map, id str, base_url str /created ts str = ''] map
  • encode-list-response [resources block, total_results i64, start_index i64, items_per_page i64] map
  • encode-scim-error [status i64, detail str /scim-type stype str = ''] map
  • parse-scim-filter [expr str] map / eval-scim-filter [ast map, resource map] bool / matches-scim-filter? [expr str, resource map] bool
  • apply-patch-op [resource map, patch_body map] map
  • new-directory [/base-url url str = ... /bearer-token tok str = ''] ScimDirectory
  • mount-directory [mut app web/App, dir ScimDirectory /prefix pfx str = '/scim/v2'] enum

Idiomatic Veko Example

rebol
use [scim = ldap_saml/scim, web]

mut app = web/new-app
dir = scim/new-directory/bearer-token 'okta-scim-bearer-secret'
_ = scim/mount-directory mut app dir

// Evaluate SCIM 2.0 filter directly against a User resource
matched = scim/matches-scim-filter? 'active eq true and emails.value co "@acme.io"' {
    userName = 'ada@acme.io'
    active   = true
    emails   = [{ value = 'ada@acme.io', primary = true }]
}
println matched // true
packages/ldap_saml/examples/demo.vkSelf-contained runnable example & assertion suite
Raw .vk
// packages/ldap_saml/examples/demo.vk
// Self-contained verification suite & runnable example for `ldap_saml` and `ldap_saml/scim`.

use [
	sso  = ldap_saml
	scim = ldap_saml/scim
	web
	url  = codec/url
	hex  = codec/hex
	x25  = crypto/x25519
	sig  = crypto/sig
]

assert-true = fn [cond bool, label str] enum [
	if not cond [
		println (str/join ['[FAIL] ' label] '')
		os/exit 1
	]
	println (str/join ['[PASS] ' label] '')
	.ok
]

// --- 1. SAML 2.0 `AuthnRequest` (DEFLATE + Base64 + HTTP-Redirect) & SP Metadata XML ---
idp_seed = bytes/from-str 'okta-idp-ed25519-signing-seed-32'
idp_pub  = x25/ed25519-pubkey idp_seed

sp = sso/SpConfig {
	entity_id      = 'https://app.acme.io/saml/metadata'
	acs_url        = 'https://app.acme.io/saml/acs'
	slo_url        = 'https://app.acme.io/saml/slo'
	idp_entity_id  = 'http://www.okta.com/exk99acme'
	idp_sso_url    = 'https://acme.okta.com/app/sso/saml'
	idp_alg        = 'ed25519'
	idp_pubkey     = idp_pub
	clock_skew_sec = 30
}

authn = sso/build-authn-request/relay-state sp '_req_8842' '2026-12-05T02:00:00Z' '/dashboard'
parsed_redir = url/parse authn.redirect_url
q_params = url/parse-query parsed_redir.query
inflated_xml = sso/inflate-authn-request (map/get q_params 'SAMLRequest')
meta_xml = sso/build-sp-metadata sp

authn_ok_1 = inflated_xml == authn.xml and (map/get q_params 'RelayState') == '/dashboard'
authn_ok_2 = (str/contains? meta_xml 'SPSSODescriptor') and (str/contains? meta_xml 'https://app.acme.io/saml/acs')
_ = assert-true (authn_ok_1 and authn_ok_2) 'SAML 2.0 AuthnRequest (DEFLATE + Base64 HTTP-Redirect) and SP EntityDescriptor XML'

// --- 2. SAML 2.0 Response Sign & Verify (Ed25519 + ECDSA P-256) & Security Rejections ---
saml_b64 = sso/sign-test-saml-response/assertion-id 'http://www.okta.com/exk99acme' 'https://app.acme.io/saml/metadata' 'https://app.acme.io/saml/acs' '_req_8842' 'ada@acme.io' '2026-12-05T02:00:00Z' '2026-12-05T02:10:00Z' {
	email     = 'ada@acme.io'
	firstName = 'Ada'
	groups    = ['eng-leads' 'sre-prod']
} 'ed25519' idp_seed '_assert_1001'

// Valid verification at 2026-12-05T02:03:00Z (unix 1796436180)
now_valid = 1796436180
mut replay_cache = {}
principal = sso/verify-saml-response/expected-req-id/now-sec/seen-ids sp saml_b64 '_req_8842' now_valid replay_cache
map/set mut replay_cache principal.assertion_id true

// Also verify ECDSA P-256 IdP XML-DSig path!
p256_priv = bytes/fill 32 0x2a
p256_pub  = sig/ecdsa-p256-pubkey p256_priv
sp_p256   = sp \ struct/with { idp_alg = 'p256', idp_pubkey = p256_pub }
saml_p256 = sso/sign-test-saml-response 'http://www.okta.com/exk99acme' 'https://app.acme.io/saml/metadata' 'https://app.acme.io/saml/acs' '_req_8842' 'grace@acme.io' '2026-12-05T02:00:00Z' '2026-12-05T02:10:00Z' { groups = ['security'] } 'p256' p256_priv
prin_p256 = sso/verify-saml-response/expected-req-id/now-sec sp_p256 saml_p256 '_req_8842' now_valid

saml_ok = principal.name_id == 'ada@acme.io' and principal.first_name == 'Ada' and principal.groups == ['eng-leads' 'sre-prod'] and prin_p256.name_id == 'grace@acme.io'
_ = assert-true saml_ok 'SAML 2.0 XML-DSig verification (Ed25519 & ECDSA P-256) extracting NameID and multi-valued groups'

// Security negative tests:
// (a) Tampered XML attribute value inside Base64 SAMLResponse (privilege escalation attempt)
raw_xml = bytes/to-str (hex/b64-decode saml_b64)
tampered_xml = str/join (str/split raw_xml 'ada@acme.io') 'admin@acme.io'
tampered_b64 = hex/b64-encode (bytes/from-str tampered_xml)
rej_tamper = err? (sso/verify-saml-response/now-sec/or sp tampered_b64 now_valid [e -> e])

// (b) Wrong AudienceRestriction
wrong_aud_b64 = sso/sign-test-saml-response 'http://www.okta.com/exk99acme' 'https://other-sp.evil.io/saml' 'https://app.acme.io/saml/acs' '_req_8842' 'ada@acme.io' '2026-12-05T02:00:00Z' '2026-12-05T02:10:00Z' {} 'ed25519' idp_seed
rej_aud = err? (sso/verify-saml-response/now-sec/or sp wrong_aud_b64 now_valid [e -> e])

// (c) Expired NotOnOrAfter (1 hour later: 1796439780)
rej_exp = err? (sso/verify-saml-response/now-sec/or sp saml_b64 1796439780 [e -> e])

// (d) Replayed Assertion ID against `replay_cache`
rej_replay = err? (sso/verify-saml-response/now-sec/seen-ids/or sp saml_b64 now_valid replay_cache [e -> e])

_ = assert-true (rej_tamper and rej_aud and rej_exp and rej_replay) 'SAML 2.0 rejects tampered XML, wrong Audience, expired NotOnOrAfter, and replayed Assertion ID'

// --- 3. OIDC Discovery, JWKS `kid` Lookup & ID-Token Claims Validation ---
oidc_cfg = sso/build-oidc-configuration 'https://id.acme.io'
jwk_ed = sso/jwk-from-ed25519 'key-ed-2026' idp_pub
jwk_ec = sso/jwk-from-p256 'key-p256-2026' p256_pub
jwks_doc = { keys = [jwk_ed jwk_ec] }

picked_jwk = sso/select-jwk-by-kid jwks_doc 'key-p256-2026'
missing_jwk = err? (sso/select-jwk-by-kid/or jwks_doc 'unknown-kid' [e -> e])

claims_ok = sso/validate-id-token-claims/now-sec {
	iss   = 'https://id.acme.io'
	aud   = ['client-web-01' 'client-cli']
	sub   = 'usr-ada'
	exp   = 1796436900
	nonce = 'n-7741'
} 'https://id.acme.io' 'client-web-01' 'n-7741' 1796436180

claims_bad_nonce = err? (sso/validate-id-token-claims/now-sec/or {
	iss   = 'https://id.acme.io'
	aud   = 'client-web-01'
	exp   = 1796436900
	nonce = 'wrong-nonce'
} 'https://id.acme.io' 'client-web-01' 'n-7741' 1796436180 [e -> e])

oidc_ok = (map/get oidc_cfg 'jwks_uri') == 'https://id.acme.io/.well-known/jwks.json' and (map/get picked_jwk 'crv') == 'P-256' and missing_jwk and claims_ok == .ok and claims_bad_nonce
_ = assert-true oidc_ok 'OIDC Discovery metadata, JWKS Ed25519/P-256 kid selection, and ID-token claims validation'

// --- 4. SCIM 2.0 Provisioning Lifecycle on `web/App` (Create -> Filter -> `PatchOp` Deactivate) ---
mut app = web/new-app
dir = scim/new-directory/base-url/bearer-token 'https://app.acme.io/scim/v2' 'scim-secret-tok-99'
_ = scim/mount-directory mut app dir

auth_hdrs = {
	'Authorization' = 'Bearer scim-secret-tok-99'
	'Content-Type'  = 'application/scim+json'
}

// 4a. Unauthenticated request rejected with 401
r_unauth = web/handle-request app (web/Request {
	method  = 'GET'
	path    = '/scim/v2/Users'
	target  = '/scim/v2/Users'
	query   = {}
	params  = {}
	headers = {}
	body    = bytes/with-cap 0
})

// 4b. Provision two users (Ada @ acme.io and Contractor @ ext.org)
create_ada_body = json/encode {
	schemas     = [(scim/SCHEMA-USER)]
	userName    = 'ada@acme.io'
	displayName = 'Ada Lovelace'
	active      = true
	name        = { givenName = 'Ada', familyName = 'Lovelace' }
	emails      = [{ value = 'ada@acme.io', type = 'work', primary = true }]
}
r_create_ada = web/handle-request app (web/Request {
	method  = 'POST'
	path    = '/scim/v2/Users'
	target  = '/scim/v2/Users'
	query   = {}
	params  = {}
	headers = auth_hdrs
	body    = bytes/from-str create_ada_body
})
ada_created = json/decode (bytes/to-str r_create_ada.body)
ada_id = str/append '' (map/get ada_created 'id')

create_ext_body = json/encode {
	schemas  = [(scim/SCHEMA-USER)]
	userName = 'bob@partner.org'
	active   = true
	emails   = [{ value = 'bob@partner.org', type = 'work', primary = true }]
}
_ = web/handle-request app (web/Request {
	method  = 'POST'
	path    = '/scim/v2/Users'
	target  = '/scim/v2/Users'
	query   = {}
	params  = {}
	headers = auth_hdrs
	body    = bytes/from-str create_ext_body
})

// 4c. Query `/scim/v2/Users` with compound RFC 7644 filter: `active eq true and emails.value co "@acme.io"`
r_flt_before = web/handle-request app (web/Request {
	method  = 'GET'
	path    = '/scim/v2/Users'
	target  = '/scim/v2/Users'
	query   = { 'filter' = 'active eq true and emails.value co "@acme.io"' }
	params  = {}
	headers = auth_hdrs
	body    = bytes/with-cap 0
})
list_before = json/decode (bytes/to-str r_flt_before.body)

// 4d. Instant Okta/Entra-style `PatchOp` deprovisioning (`active = false`) + title update!
patch_body = json/encode {
	schemas    = [(scim/SCHEMA-PATCH)]
	Operations = [
		{ op = 'Replace', value = { active = false } }
		{ op = 'replace', path = 'title', value = 'Alumni Fellow' }
	]
}
user_path = str/append '/scim/v2/Users/' ada_id
r_patch = web/handle-request app (web/Request {
	method  = 'PATCH'
	path    = user_path
	target  = user_path
	query   = {}
	params  = {}
	headers = auth_hdrs
	body    = bytes/from-str patch_body
})
ada_patched = json/decode (bytes/to-str r_patch.body)

// 4e. Re-run active filter -> 0 active @acme.io users! And `userName eq "ada@acme.io"` returns deactivated Ada!
r_flt_after = web/handle-request app (web/Request {
	method  = 'GET'
	path    = '/scim/v2/Users'
	target  = '/scim/v2/Users'
	query   = { 'filter' = 'active eq true and emails.value co "@acme.io"' }
	params  = {}
	headers = auth_hdrs
	body    = bytes/with-cap 0
})
list_after = json/decode (bytes/to-str r_flt_after.body)

r_flt_eq = web/handle-request app (web/Request {
	method  = 'GET'
	path    = '/scim/v2/Users'
	target  = '/scim/v2/Users'
	query   = { 'filter' = 'userName eq "ada@acme.io"' }
	params  = {}
	headers = auth_hdrs
	body    = bytes/with-cap 0
})
list_eq = json/decode (bytes/to-str r_flt_eq.body)

scim_ok_1 = r_unauth.status == 401 and r_create_ada.status == 201 and ada_id == 'usr-1'
scim_ok_2 = (map/get list_before 'totalResults') == 1 and r_patch.status == 200 and (map/get ada_patched 'active') == false and (map/get ada_patched 'title') == 'Alumni Fellow'
scim_ok_3 = (map/get list_after 'totalResults') == 0 and (map/get list_eq 'totalResults') == 1
_ = assert-true (scim_ok_1 and scim_ok_2 and scim_ok_3) 'SCIM 2.0 web/App User create, RFC 7644 filter evaluation, and PatchOp instant deprovisioning'

println 'ldap_saml: all verification checks passed'
Cryptographic Provenance

Ed25519 Signature & Merkle Integrity

Registry URL: https://veko-lang.org/pkg/ldap_saml/1.0.0.vkp
Archive SHA-256: 8fe1e062e9ed10e8033be62a80146c60ef3a50e059782f24abdc93104e977864
Merkle Root: 22fecd5a8e834c3c7ec194d7b81251a0b85ec7b4064d2b0d470111bd7a0baab6
Signer Trust Key: ed25519:27406074d8681da1d4e6420f5d887cac15c313334c249ac047ba9d4e2df72b70
Embedded VKP1 Manifest

manifest.json

{"name":"ldap_saml","version":"1.0.0","tier":4.0,"tier_label":"Tier 4: FinTech, GraphQL, CDP & SSO","category":"SAML 2.0, OIDC JWKS & SCIM 2.0","description":"Enterprise B2B SAML 2.0 SP AuthnRequest & signed Assertion verifier, OIDC JWKS keyset matcher, and SCIM 2.0 /Users & /Groups provisioning.","modules":["ldap_saml","ldap_saml/scim"],"homepage":"https://veko-lang.org/packages/ldap_saml"}
Bundle Entry PathSizeLeaf SHA-256 Digest
README.md5 KBb39b109f8c6afdb9acfe474499648422160e95ddd4810ac2fd6f7b45da5f095a
examples/demo.vk9 KB1cb1fdb243ff9eb54a4b7070908559564ed473e568e8009b84b98e7f824e3a79
mod.vk27 KB7571672e8387c1963d8d4799d67db15660ce509e5559cf3eb659185f86828e53
scim.vk25 KB956ecf74699943c969970abd96d0feea8ef1b1261d6e643cfb1f301c19898800