{"library":"saml2-js","title":"SAML 2.0 Node.js Helpers","description":"saml2-js is a Node.js module that simplifies the implementation of the SAML 2.0 protocol, specifically for acting as a Service Provider (SP). It abstracts away complexities, allowing applications to integrate with Identity Providers (IdPs) for authentication and authorization. The library currently does not support acting as an Identity Provider. As of version 4.0.4, the project is in maintenance mode, focusing primarily on addressing bug reports and security issues rather than feature development. There is no stated regular release cadence, with updates being driven by critical fixes. Key differentiators include its focus solely on SP functionality and a clear set of configuration options for managing SAML requests and responses. It offers constructors for `ServiceProvider` and `IdentityProvider` objects, with options for managing entity IDs, cryptographic keys, assertion endpoints, and various SAML-specific behaviors like `force_authn` and `nameid_format`.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install saml2-js"],"cli":null},"imports":["const saml2 = require('saml2-js');","const { ServiceProvider } = saml2;","const { IdentityProvider } = saml2;"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const saml2 = require('saml2-js');\nconst fs = require('fs');\nconst path = require('path');\n\n// In a real application, these would be loaded securely (e.g., from environment variables).\n// For demonstration, using dummy values and assuming keys/certs exist.\nconst spPrivateKey = process.env.SP_PRIVATE_KEY ?? '-----BEGIN RSA PRIVATE KEY-----\\n...your_private_key...\\n-----END RSA PRIVATE KEY-----';\nconst spCertificate = process.env.SP_CERTIFICATE ?? '-----BEGIN CERTIFICATE-----\\n...your_certificate...\\n-----END CERTIFICATE-----';\nconst idpCertificate = process.env.IDP_CERTIFICATE ?? '-----BEGIN CERTIFICATE-----\\n...idp_certificate...\\n-----END CERTIFICATE-----';\n\n// Service Provider (SP) options\nconst spOptions = {\n  entity_id: \"https://sp.example.com/metadata\",\n  private_key: spPrivateKey,\n  certificate: spCertificate,\n  assert_endpoint: \"https://sp.example.com/sso/assert\"\n};\n\n// Identity Provider (IdP) options (minimal for login request)\nconst idpOptions = {\n  entity_id: \"https://idp.example.com/saml/metadata\",\n  sso_login_url: \"https://idp.example.com/saml/sso\",\n  certificates: [idpCertificate]\n};\n\n// Instantiate SP and IdP\nconst sp = new saml2.ServiceProvider(spOptions);\nconst idp = new saml2.IdentityProvider(idpOptions);\n\n// Generate a SAML login request URL (for SP-initiated SSO)\nsp.create_login_request_url(idp, {}, (err, loginUrl, requestId) => {\n  if (err) {\n    console.error(\"Error creating login request URL:\", err);\n    return;\n  }\n  console.log(\"SAML Login Request URL:\\n\", loginUrl);\n  console.log(\"Request ID:\", requestId);\n  // In a web application, you would redirect the user to this loginUrl.\n  // e.g., res.redirect(loginUrl);\n});\n\n// Example of generating SP metadata (to provide to the IdP)\nsp.create_metadata((err, metadata) => {\n  if (err) {\n    console.error(\"Error creating SP metadata:\", err);\n    return;\n  }\n  console.log(\"\\nService Provider Metadata:\\n\", metadata);\n});","lang":"javascript","description":"This quickstart demonstrates how to configure a Service Provider and Identity Provider, generate a SAML login request URL for SP-initiated SSO, and generate SP metadata for IdP configuration.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}