Authorization
Decide which peers may connect and which operations they may invoke.
Nexus policy controls admission to a session and access to services and resource references. Configure it on the runtime that owns the protected capabilities.
Allow Connections And Calls
This configuration fragment assumes runtimeConfig contains your endpoint and
its model includes a workspace identity field and an adapter-verified
observed.authenticated fact:
app.configure({
...runtimeConfig,
policy: {
canConnect({ remoteIdentity, connection }) {
return (
remoteIdentity.workspace === "drafts" &&
connection.observed.authenticated === true
);
},
canCall({ serviceName, operation }) {
return serviceName === "example:documents" && operation === "APPLY";
},
},
});Both hooks are optional. Without a hook, that operation is allowed. Installed
hooks must return true to allow access; false, a throw, or a rejection denies it.
Connection Admission: canConnect
canConnect receives localIdentity, remoteIdentity, connection facts, and
physical direction ("incoming" or "outgoing"). It runs during handshake
authorization and on later candidate identity updates.
Handshake denial prevents the session from becoming ready. A denied identity
update does not commit the new identity and closes the session. The denial code
is E_AUTH_CONNECT_DENIED.
Some adapters perform authentication or origin checks before Core admission. For those mechanisms, use the adapter documentation. Passing an adapter gate does not bypass an installed Core policy.
Operation Authorization: canCall
canCall receives both identities, connection facts, connectionId, serviceName,
path, and operation. It checks incoming service and resource operations.
Denial returns E_AUTH_CALL_DENIED without invoking the business implementation.
Current proxies produce GET and APPLY operations. The current exported policy
type also includes SET, but remote property assignment is unsupported; expose
a write method instead. This type member is not an available proxy write API.
connectionId is an opaque session identifier for diagnostics and policy. It is
not a target that an application can use to reacquire a connection.
An acquisition where predicate does not replace canCall. Later calls are
authorized independently of how the consumer selected the connection.
Set A Service Policy
app.provide(DocumentToken, documents, {
policy: {
canCall(context) {
return allowWorkspaceCall(context) && allowDocumentOperation(context);
},
},
});The predicates are application policy functions. A service-level canCall
replaces the global call hook for that service. If it is omitted, the global
hook is used. Compose predicates explicitly when both rules must hold; this is
not an implicit AND with global policy.
Refs returned by a service retain the policy snapshot from the invocation that
created them. Re-registering the service does not silently change policy for
existing references. Bootstrap configure({ providers }) descriptors may also
carry service policies.
Choose Trusted Inputs
Peer-declared identity is useful for roles, labels, and selection. For security decisions, use adapter-observed or verified facts according to their documented guarantees. A declared user ID, role, origin, or process ID is not automatically authenticated. See Identity and metadata.
Handle Denial
Connection denial fails acquisition; call denial fails that operation. Safe APIs let the application handle either as a Result. Denial does not ask Nexus to find another provider or retry. See Errors and timeouts.