@archon-inc/sdk
Version:
Integrate easily to our government platform using this SDK. More info on https://archon.inc/sdk
29 lines (28 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = determineAccess;
const Archon_js_1 = require("../Archon.js");
/**
* Given a user session and a resource, determine if the user has access to the resource with the given intent.
* This function contacts the Archon policy service to determine access. To edit policies or add new ones,
* log into the dashboard and initiate a change.
* @param session The session of the user attempting to access the resource.
* @param resource The resource being accessed, identified by its ARID.
* @param intent The intent with which the user is attempting to access the resource.
* @returns Whether the user has access to the resource with the given intent.
*/
async function determineAccess(session, resource, intent) {
const arid = typeof resource === "string" ? resource : resource.arid;
const response = await Archon_js_1.Archon.request(`/policy/access/${arid}`, "POST", {
sessionId: typeof session === "number" ? session : session.id,
intentName: typeof intent === "string" ? intent : intent.name
});
if (response.status !== 200) {
throw new Error(`Failed to determine access: ${response.data}`);
}
return {
allowed: response.data.allowed,
reason: "",
accessibleVia: response.data.accessibleVia
};
}