{"id":114657,"plugin_id":"plugin_asdk_app_6aee0b8e3a488191a3de75aad5b8bd87","kind":"skill","collection_source":"plugin_package","comparison_source":null,"observed_at":"2026-11-25T07:29:43.869Z","digest":"9a1ab8e2bef29c9905f7f35ce9bc46595256bc1993aa16ab871aef1944169212","against":null,"payload":{"description":"Decide between SDK signing and a hand-rolled HMAC, and resolve a rejected Learnosity signature by mapping the reported error code to the one signed input that differs — domain, timestamp, key/secret pairing, or request bytes.","included_files":[],"name":"generate-and-troubleshoot-request-signatures","skill_md_contents":"---\nname: generate-and-troubleshoot-request-signatures\ndescription: Decide between SDK signing and a hand-rolled HMAC, and resolve a rejected Learnosity signature by mapping the reported error code to the one signed input that differs — domain, timestamp, key/secret pairing, or request bytes.\n---\n\n# Generate and Troubleshoot Request Signatures\n\n**Goal:** Decide between SDK signing and a hand-rolled HMAC, then resolve a\nrejected signature by identifying which signed input differs between the signer\nand Learnosity.\n\n**APIs:** `author-api`, `items-api`, `reports-api`, `data-api`\n\n## When to use this skill\n\n- Adding the server-side signing step to a new integration.\n- An integration that signs correctly on a development host is rejected once\n  deployed.\n- A `4100x` error code appears in the browser console or in a Data API\n  response body.\n- Credentials are being rotated, or content is moving between consumers and\n  each side needs its own signature.\n- Reviewing signing code for secret exposure.\n\n## Core principle\n\nLearnosity recomputes the signature from the request it received and its own\ncopy of the secret. A rejection means one input differed between the two\ncomputations; it rarely means the algorithm is wrong.\n\n| Signed input | Set by | Differs when |\n| --- | --- | --- |\n| `consumer_key` | the provisioned key set | a key from another environment or another consumer is used |\n| `domain` | the signer, explicitly or by SDK default | a default such as `localhost` survives onto a deployed host, or the request reaches Learnosity from a different origin |\n| `timestamp` | the signing host's clock | the clock is not UTC, or a signed init object is replayed after the window closes |\n| `user_id` | the application | the value is edited after signing |\n| `expires`, when present | the signer | it is added to the security packet after signing |\n| the `request` object | the serializer | the JSON is re-encoded between signing and sending |\n\nTwo consequences carry most of the debugging:\n\n- `consumer_secret` is the HMAC key. It is never an element of the pre-hash\n  string and never leaves the server, so a wrong or mispaired secret reports\n  the same \"signatures do not match\" as a mistyped domain.\n- No input is validated for sense before hashing. A well-formed but wrong\n  value fails at verification, not at signing, which is why signing code that\n  \"looks right\" is the normal case in a signature bug.\n\n## Preconditions\n\n- A matched `consumer_key` / `consumer_secret` from the same credential set. A\n  consumer may hold several sets.\n- The host the request originates from is allowlisted against that consumer in\n  Learnosity Console. Allowlist and key changes can take up to 30 minutes to\n  take effect, so a correct configuration can be rejected inside that window.\n- The signing host's clock is UTC-accurate.\n- The secret is readable server-side only.\n- An official SDK for the server language, or Learnosity Support engaged if\n  none exists — see **install-and-set-up-the-sdk**.\n\n## Choosing an approach\n\n| Approach | Use when | Cost |\n| --- | --- | --- |\n| SDK `Init(service, security, secret, request[, action])`, then `generate()` | the server language is one of the six with an official SDK | none worth avoiding: the SDK owns element order, timestamp generation and serialization |\n| Hand-rolled HMAC-SHA256 | no SDK exists for the language | you own element order, JSON serialization and future signature versions permanently. Contact Learnosity Support before committing to it |\n\nPrefer the SDK, including for the Data API, where the same `Init` call takes\nthe `action` as its last argument.\n\n## Worked example\n\nOne credential set, two environments, two services. Only `domain` and the\nregenerated `timestamp` change between environments, and the Data API packet\ncarries no `user_id`.\n\n```yaml\n# Browser-facing service (items-api), staging\nsecurity:\n  consumer_key: YOUR_CONSUMER_KEY\n  domain: staging.your-domain.com   # the origin the browser loads from\n  timestamp: \"20260923-1030\"        # UTC, YYYYMMDD-HHMM, SDK-generated\n  user_id: 11111111-2222-3333-4444-aaaaaaaaaaaa\n  expires: \"20260923-1230\"          # optional, and signed: set before signing\n# signature added by Init('items', security, CONSUMER_SECRET, request)\n\n# Same credential set, production: only the domain differs\nsecurity:\n  consumer_key: YOUR_CONSUMER_KEY\n  domain: www.your-domain.com\n  timestamp: \"20260923-1030\"\n  user_id: 11111111-2222-3333-4444-aaaaaaaaaaaa\n\n# Server-to-server (data-api): no user_id in the packet\nsecurity:\n  consumer_key: YOUR_CONSUMER_KEY\n  domain: www.your-domain.com\n  timestamp: \"20260923-1030\"\n# signature added by Init('data', security, CONSUMER_SECRET, request, 'get')\n```\n\nA signature is not portable across those packets. Re-sign per environment, per\nservice and per request.\n\n## Implementation\n\n- Set `domain` explicitly in every environment rather than relying on an SDK\n  default. The PHP reference documents a `localhost` default, and a default is\n  what carries a development value into production unnoticed.\n- Let the SDK generate `timestamp`. It must be UTC in `YYYYMMDD-HHMM`; a\n  local-time clock yields a well-formed value outside the accepted window.\n- The timestamp window and session validity are separate limits. The timestamp\n  must sit within three hours of current UTC, while a signed session's default\n  validity is 168 hours, so a cached init object fails on its timestamp long\n  before `expires` is reached.\n- `expires` is hashed with the rest of the packet. Add it before calling the\n  SDK; adding it to the returned object invalidates the signature.\n- Serialize the `request` object once and send those exact bytes. A framework\n  that re-encodes JSON on the way out — different key order, different\n  escaping — changes the hash without changing any value.\n- Derive `security.user_id` and the request's learner id from one variable.\n  Only the security copy is signed, so a divergence between them is not caught\n  by verification.\n- Keep the secret out of the pre-hash string, out of the served payload, and\n  out of version control.\n\n## Failure modes\n\n### Reported as an error code\n\n| Condition | Result |\n| --- | --- |\n| `41000` | Missing security parameters: a field this service requires is absent from the packet |\n| `41001` | Invalid parameter length: a key or secret altered in length by environment or config handling |\n| `41002` | Not a valid consumer: the key is unrecognized — another environment's key, or a newly created set still propagating |\n| `41003` | Signatures do not match: a signed input differs from what was sent, or the secret belongs to a different key |\n| `41004` | Timestamp outside the accepted window relative to current UTC |\n| `41005` | Invalid domain: the signed domain is not allowlisted, or does not match the origin the request arrived from |\n| `41006` | `expires` is not a GMT `YYYYMMDD-HHMM` value |\n| `41007` | The request arrived after its `expires` |\n| `40002` / `40003` | Consumer or organization access, not signing: the signature verified and authorization failed |\n\nThe Data API returns these in the response body alongside an HTTP status;\nbrowser-facing APIs log them to the JavaScript console.\n\n### Reported weakly or not at all\n\n| Condition | Result |\n| --- | --- |\n| Secret read with surrounding whitespace or quotes from an env file or shell | `41003` while every visible value is correct |\n| Request re-encoded after signing by framework middleware | `41003` that survives every credential check, because the credentials are not the fault |\n| One signature generated and reused across users or requests | works until the timestamp window closes, then fails for everyone at once |\n| Allowlist or key change not yet propagated | the same configuration starts working later with no code change; an immediate retry looks like a hard failure |\n| Secret serialized into the init object sent to the browser | no error at all — the integration works, and only inspecting what is served detects it |\n| `user_id` carrying PII or exceeding 50 characters | verification is unaffected: this is a data constraint, so it surfaces elsewhere or not at all |\n\n## Diagnostics\n\nConfirm the cause before changing configuration — several of these report the\nsame `41003`.\n\n1. **Correct on the development host, rejected once deployed** → the signed\n   `domain`. Compare the `domain` in the served init object against the\n   browser's own host, then confirm that host is allowlisted for the consumer.\n2. **`41003` with credentials known to be correct** → compare the pre-hash\n   string. Log it server-side at signing time and compare its request segment\n   with the JSON the page actually received. A difference there is a\n   serialization fault; no difference points back at the secret.\n3. **`41002` immediately after generating a key set** → propagation. Re-test\n   after 30 minutes before changing anything else.\n4. **`41004` on a page that worked minutes earlier** → a cached or reused init\n   object, or a clock that is not UTC. Compare the signed timestamp against\n   `date -u +%Y%m%d-%H%M` on the signing host.\n5. **Data API rejected while browser APIs pass on the same credentials** →\n   packet shape and origin. The Data API packet takes no `user_id`, and a\n   request sent from a browser must be signed with the browser's domain.\n6. **Rejected for some learners only** → the `user_id` those sessions carry;\n   an empty or oversized value is the input that varies between them.\n7. **Everything verifies and the concern is exposure** → search the served\n   payload for the secret. A leaked secret raises no error.\n\n## Runtime checks\n\n| Question | Check |\n| --- | --- |\n| Which error did the API actually raise? | `LearnosityItems.errors` in the browser console; the response body for a Data API call |\n| Is the signature well formed and on the current version? | it begins `$02$` and is 68 characters long |\n| Is the signed domain the browser's domain? | compare `security.domain` in the served init object with `window.location.hostname` |\n| Is the signing clock UTC-accurate? | `date -u +%Y%m%d-%H%M` on the signing host against the signed `timestamp` |\n| Did the request bytes change after signing? | hash the serialized request at signing time and again in the rendered response, then compare |\n| Is the secret reaching the client? | search the served HTML and JSON for `consumer_secret` and for the secret's leading characters |\n| Which fields does this service's packet require? | the SDK's `REFERENCE.md` for the language in use |\n\n## Reference lookups\n\n| Topic | `source` | `article_id` |\n| --- | --- | --- |\n| Signature components, pre-hash string construction, hash generation, `$02$` prefix | `help_site` | `360000754738` |\n| Full security error table, including `41005`–`41007` and the 40xxx access codes | `help_site` | `16458061457565` |\n| Items API error codes and the browser-side error list | `help_site` | `16458090530845` |\n| Data API error codes mapped to HTTP response codes, and the browser-domain rule | `help_site` | `16458089770653` |\n| Domain allowlisting, key sets per consumer, propagation delay | `help_site` | `360001767178` |\n| `expires` semantics and default session validity | `help_site` | `360000755378` |\n| `user_id` constraints | `help_site` | `16560472198045` |\n\n## Further reading\n\n| Topic | `source` | `article_id` |\n| --- | --- | --- |\n| `Init()` arguments and security defaults, PHP | `github` | `8814326499369822536` |\n| `Init()` arguments and security defaults, Node.js | `github` | `10790999250645865205` |\n| `Init()` arguments and security defaults, Python | `github` | `8178786445494155368` |\n| `Init()` arguments and security defaults, Java | `github` | `10051180954462946798` |\n| `Init()` arguments and security defaults, Ruby | `github` | `9144409672829329245` |\n| `Init()` arguments and security defaults, ASP.NET | `github` | `16317273184219915862` |\n| Signing a Data API request sent from the browser | `help_site` | `360000755758` |\n| PII definition applying to `user_id` | `help_site` | `360002309578` |\n\n## Related skills\n\n- **install-and-set-up-the-sdk** — installing and configuring the SDK that\n  signs.\n- **content-migration** — signing `get` against a source bank and `set`\n  against a destination with two separate credential sets.\n- **golden-path-author-items-reports** — where the signed init object is\n  consumed by Author, Items and Reports.\n"},"changes":[],"summary":"First saved snapshot. No earlier version is available for comparison.","summary_kind":"deterministic","summary_metadata":{}}