A sample application demonstrating how to implement an AI agent with fine-grained authorization controls when accessing sensitive user data.
SmartHR Assistant is an intelligent document management system that:
-
Provides secure access to HR documents based on complex authorization rules:
- Salary information (viewable only by HR and the specific employee)
- Performance reviews (viewable by employee, their manager, and HR)
- Employee information (viewable by HR and the specific employee)
- Team documents (viewable by team members only)
- Company policies (public to all employees)
-
Offers AI-powered capabilities:
- Answers questions about policies and procedures
- Generates document summaries
- Assists with document search
- Salary information
- Performance reviews
- Employee personal and public information
- Team documents
- Team members
- Company policies
- Company documents
- Full access to their own records
- Limited access to other employees' public information
- Full access to public company documents
- Full access to their teams documents
Employee Level +
- Full access to their team members information
- Full access to performance reviews of their team
Manager Level +
- Full access to all employee information
- Full access to all team information
- Full access to all performance reviews
- Full access to all data
- Convert to Express App and add a Chat UI for the application
- Integrate Auth0 and get the user information from Auth0
- Add tool calling agent
- Add SQL DB for realtime data
- Add Async auth example
- Install the dependencies
npm install
-
Create a
.env
file using the format below:# OpenAI OPENAI_API_KEY=xx-xxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx # Okta FGA FGA_STORE_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxx FGA_CLIENT_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxx FGA_CLIENT_SECRET=xxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx # Required only for non-US regions FGA_API_URL=https://api.xxx.fga.dev FGA_API_AUDIENCE=https://api.xxx.fga.dev/
Use this page for instructions on how to find your OpenAI API key. Once you have your key, update the .env
file accordingly.
-
Create a client
Navigate to Settings and in the Authorized Clients section click + Create Client button. On the new page give your client a name and mark all three client permissions then click Create.
-
Copy the information on the modal and update your
.env
file with the values you now have forFGA_STORE_ID
,FGA_CLIENT_ID
, andFGA_CLIENT_SECRET
. -
Run the
npm run fga-init
script to initialize the FGA store with the model and tuples.
npm start
This application is built with TypeScript, Node.js, LlamaIndex, and OpenFGA.
All data will be in PDF and markdown files and will be loaded into an in-memory vector store on application startup.