How egg-/danal works
1. Overall shape
- This repository is a small Node.js library for integrating with the Danal UAS identity/authentication flow.
- It is not a full app; it exposes reusable modules that your own server mounts into an HTTP framework such as Express.
2. Primary purpose
- The library orchestrates a multi-step authentication handshake:
- create a UAS request,
- redirect the user to the external Danal flow,
- receive the callback or cancel response,
- confirm the result server-to-server.
- The README’s example shows that the consumer app owns the HTTP routes and persistence, while danal handles protocol logic.
3. Main exported surface
- index.js is the package entry point and likely re-exports the main classes/modules from lib/.
- The two core abstractions exposed in the README are:
- UAS for request/redirect/receive/confirm behavior,
- API for shaping request payloads and defaults.
4. UAS workflow boundary
- lib/uas.js is the central subsystem.
- It appears to encapsulate the end-to-end UAS lifecycle and provides middleware-style helpers used by the host server:
- request(token, cb) to initiate a transaction,
- redirect() to send the user into the external auth step,
- receive() to parse callback/cancel responses,
- confirm(...) to finalize the authentication and retrieve identity data.
- This is the main boundary between your app and the Danal service.
5. HTTP integration model
- The library is designed to be embedded into an HTTP server, not to run one itself.
- The README example shows:
- a GET route that prepares UAS data and then calls uas.redirect(),
- a POST callback route that runs uas.receive() and then uas.confirm(),
- a POST cancel route that only receives and returns the request context.
- The host app keeps control of routing, response formatting, and user/session updates.
6. Payload and configuration shaping
- lib/api.js likely defines the request/response field model and supports merging default values into UAS payloads.
- The README’s use of danal.API.defaults(...) suggests this module is responsible for assembling the final request object with:
- cancel URI,
- CI logo URLs,
- optional user profile fields such as carrier, phone number, birth year, and passvalue.
- This is a data-munging layer between app config and external API requirements.
7. Endpoint and naming utilities
- lib/endpoint.js and lib/names.js are supporting modules that likely centralize:
- service endpoint URLs,
- field names / canonical parameter keys,
- possibly mappings between request and response formats.
- These are important because they keep protocol constants out of the application layer and reduce drift if the vendor API changes.
8. Browser handoff helper
- lib/redirect.html indicates there is a browser-side redirect or form-post helper involved in the flow.
- In architecture terms, this is the seam where the server-generated UAS request is handed off to the user’s browser for navigation to the external authentication provider.
9. Data flow through the system
- The host app builds a token object, passes it to UAS.request(), receives a transaction payload, enriches it with defaults via API.defaults(), and stores it in res.locals.
- The browser is then redirected out to the Danal service.
- On callback, the incoming request is parsed, then the app calls confirm() using the stored transaction id to retrieve verified identity attributes.
10. External dependency boundary
- The only major external integration implied here is the Danal UAS service.
- The library abstracts away the vendor-specific request/confirmation details, but the surrounding app still needs to provide:
- client_id, client_secret, and redirect_uri,
- optional consumer-facing UI/logo URLs,
- the local callback and cancel endpoints.
11. Testing and build
- test/index.js suggests the repo includes automated tests for the exported behavior.
- Gruntfile.coffee indicates Grunt is used for task automation, likely linting, testing, or packaging.
- package.json defines the Node runtime dependency boundary and package metadata.
12. How to draw the architecture
- A useful diagram would show:
- your app/server on the left,
- danal as an embedded library in the middle,
- Danal/UAS external service on the right,
- the browser/user as the actor that is redirected between them.
- The most important arrows are:
- app → UAS.request() → payload assembly,
- app/browser → redirect() → external UAS,
- external UAS → callback/cancel routes → receive(),
- app → confirm() → verified identity result.
Main entry points: index.js Entry point · uas.js UAS · api.js API · test/index.js Tests
Components 16
Host app
Application embedding the library and owning routes, session state, and persistence.
- Consumer app · Owns routes, session state, and persistence; mounts the library into an HTTP framework.
danal package
Reusable Node.js library that implements the UAS protocol flow.
- Entry point · Package entry that exposes the library surface.
index.js - UAS · Central lifecycle object for request, redirect, receive, and confirm steps.
lib/uas.js - API · Builds request payloads and merges default values for the protocol.
lib/api.js - Endpoints · Centralizes vendor endpoint URLs and related protocol targets.
lib/endpoint.js - Names · Defines canonical parameter names and protocol field mappings.
lib/names.js - Redirect page · HTML helper used to hand off the prepared request to the browser.
lib/redirect.html - Request · Creates the UAS transaction payload from the consumer token and config.
- Redirect · Sends the user agent into the external Danal flow.
- Receive · Parses callback or cancel responses from the vendor flow.
- Confirm · Performs server-to-server confirmation to obtain identity data.
- Identity data · Verified authentication outcome returned to the host app.
- Tests · Automated checks for the exported behavior.
test/index.js - Grunt · Task automation for testing, linting, or packaging.
Gruntfile.coffee
External actors
Browser and vendor service involved in the authentication handshake.
- Browser · Carries the user through the redirect-based authentication step.
- Danal UAS · External identity/authentication service that receives redirects and returns verified results.
Connections 20
- Consumer app → Entry point: imports · The host app consumes the package entry to access the library API.
- Entry point → UAS: exports · Entry point exposes the central UAS workflow object.
- Entry point → API: exports · Entry point exposes payload-shaping helpers.
- UAS → Request: starts · Initiates a transaction from the consumer token.
- Request → API: builds with · Uses API defaults and field shaping to form the outbound payload.
- API → Endpoints: targets · Resolves vendor service endpoints used by the request flow.
- API → Names: maps fields · Normalizes protocol parameter names.
- Request → Consumer app: returns payload · Provides the assembled transaction data back to the host app.
- Consumer app → Redirect: calls · The host app triggers the redirect after storing request state.
- Redirect → Browser: sends user · Moves the user agent into the external authentication flow.
- Browser → Danal UAS: auth flow · The browser interacts with the vendor-hosted UAS experience.
- Danal UAS → Receive: callback/cancel · Vendor returns control to the application callback or cancel route.
- Consumer app → Receive: parses via · The host app invokes receive handling on incoming responses.
- Receive → UAS: updates · Receive step feeds parsed response context back into the workflow.
- Consumer app → Confirm: calls · The host app confirms the transaction after receiving the callback.
- Confirm → Danal UAS: verifies with · Performs server-to-server confirmation against the vendor.
- Confirm → Identity data: yields · Produces verified identity attributes for the host app.
- UAS → Redirect page: renders · Uses the redirect helper for browser handoff when needed.
- Tests → Entry point: covers · Automated tests exercise the exported package behavior.
- Grunt → Tests: runs · Task automation likely orchestrates the test suite.