ServiceWorkerAuthorization
Index
Properties
Methods
Properties
readonlyapiUrl
The URL the page registered the worker for, typically the session's whole origin. fetch
adds a token only to API requests under it; see isApiRequest.
Methods
addFetchListener
Answers every fetch that appliesTo with fetch. For a worker that does nothing else; one that also logs or caches calls fetch from its own listener instead.
Returns void
appliesTo
Whether fetch would add a token to
request: it is an API request under apiUrl (isApiRequest) and carries no Authorization header. What the request is for does not matter: a<script src>, a stylesheet, a worker script or an<embed>is authorized like an image is, and keeping uploaded content from being served as any of those is the server's job (ADR 0009).Parameters
request: Request
Returns boolean
fetch
Sends
request, with the token of the page identified byclientIdadded when appliesTo holds and that page has one to lend. Otherwise sends it unchanged.The request body passes through unread, so a request is sent exactly once. There is no retry on a
401: the worker replaces a token before it expires, so a401is a real refusal.Parameters
request: Request
clientId: string
the requesting page, i.e.
FetchEvent.clientId.
Returns Promise<Response>
The service-worker half of
TwinfinitySession.registerServiceWorker: adds the session's token to requests the page could not authenticate itself.