The hand-off gives your server the reader that logged in on the subscription host. The code is ns_handoff. It lives 60 seconds and works 1 time.
- Read the value of the query
ns_handoffon the request. - Call
POST /api/v1/handoffwith the server key and{"code": "<value>"}. - Norspire answers
{"reader": "<token>", "maxAge": <seconds>}. Keep the token as opaque text. - Set the reader cookie to the token with
Max-AgeofmaxAge. Answer HTTP 303 to the same address with nons_handoff.
The 7 middleware rules
A code that stays in the address of a page can give another party the reader on your site. Follow these 7 rules. The demo site and the runnable example in part 12 follow each rule.
- Run the middleware before routing on each
GETrequest withns_handoffin the query on your site origin. Run it on unmatched paths before 404 and on paths served by other apps behind the same origin. - When the query holds more than 1 value of
ns_handoff, read the last value. The real code is last. - Call
POST /api/v1/handoffwith the 1-second budget of part 5. After HTTP 200, set the reader cookie withmaxAge. - After each other answer, after a timeout or a network error, and while the breaker of part 5 is open, set no cookie. While the breaker is open, call no exchange.
- In each case answer HTTP 303 to the same address. Remove each pair whose decoded name is
ns_handoff, and keep each other pair as typed. SendCache-Control: no-store. No page renders withns_handoffin its address. - A
HEADrequest withns_handoffcalls no exchange and gets the same HTTP 303. - The breaker counts the server checks only. An exchange does not count in its window.
Your server sets the reader cookie. The embed reads no cookie and sets no cookie. If a CDN sits in front of your server, send each request with ns_handoff in the query to your server. Do not cache the 303. Do not cache a page with a Set-Cookie header.
- 1ReaderSelects
Log inon the page. The link opens the subscription host. - 2Subscription hostThe reader logs in. Norspire redirects with HTTP 303 and
ns_handoff=<code>. - 3Site serverCalls
POST /api/v1/handoffwith the code and the server key. - 4Site serverSets the reader cookie and redirects with HTTP 303 with no
ns_handoff. - 5NorspireEach later server check sends the reader cookie. Norspire identifies the reader.
See also the API reference for POST /api/v1/handoff.