Class BowireImpersonation
- Namespace
- Kuestenlogik.Bowire.Auth
- Assembly
- Kuestenlogik.Bowire.dll
An administrator looking at somebody else's workbench (#98).
public static class BowireImpersonation
- Inheritance
-
BowireImpersonation
- Inherited Members
Remarks
Why a cookie rather than a signed token. The workbench has some
seventy direct fetch call sites and no central wrapper, so a header
would mean touching all of them or patching global fetch — and a
tool whose purpose is sending requests to other people's services is the
last place to add a header to every outbound call by default. A cookie
rides along on same-origin requests and needs no client change at all.
Why that is not a weaker choice. The cookie is a parameter, never an authority. On every request the server re-derives the real caller from their token and re-asks the directory whether they administer the install; the cookie only says whose slot to open. Forging it therefore buys nothing unless you are already an administrator — a stronger property than a signed token, which is only as good as its key and as the moment it was minted. An administrator who is demoted stops impersonating on their very next request, without anything having to expire.
Fields
CookieName
The cookie that names whose slot to open.
public const string CookieName = "bowire.act-as"
Field Value
Remarks
Deliberately not __Host- prefixed. That prefix requires the
Secure attribute, and an embedded host reachable over plain HTTP on an
internal network would then fail to set the cookie at all — silently,
with impersonation appearing to do nothing. The prefix would buy
protection against a sibling host writing the value, and the value is
re-authorised against the caller's own token on every request anyway,
so there is nothing to gain by writing it.
EndpointPath
The route that starts and ends a session, relative to the workbench's base path.
public const string EndpointPath = "/api/impersonation"
Field Value
Remarks
Named here because two places have to agree about it: the endpoint that
maps it, and the middleware that must not record a request to
it. Ending a session is already written to the log as end, and
recording the DELETE as well puts the same event in twice, in two
vocabularies.
Properties
Current
The impersonation in force on this execution context, or null
when the caller is acting as themselves.
public static BowireImpersonationScope? Current { get; }
Property Value
Methods
Enter(string, string)
Act as actingAs until the returned scope is disposed.
public static IDisposable Enter(string actor, string actingAs)
Parameters
Returns
Remarks
Restores the previous value rather than clearing it, for the same reason Enter(string) does: a nested scope is legitimate, and clearing would silently drop the outer one for the rest of the request.