Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions authorization-for-rag/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Authorization for RAG with Okta FGA
## Authorization for RAG with Auth0 FGA

Authorization for RAG ensure that users can only access documents they are permitted to view. By enforcing strict access controls during the document retrieval process, it prevents unauthorized data exposure and maintains data security. For more information, refer to the [documentation](https://demo.auth0.ai/docs/authorization-for-rag).

Expand All @@ -19,40 +19,44 @@ Below is a high-level workflow:

### Examples

Explore the following examples demonstrating the integration of **Okta FGA** with **LangChain** and **LlamaIndex** retrievers:
Explore the following examples demonstrating the integration of **Auth0 FGA** with **LangChain** and **LlamaIndex** retrievers:

- **LangChain with FGARetriever (JavaScript):**
An implementation showcasing how to wrap a LangChain retriever with FGARetriever to enforce authorization checks during document retrieval.
[View Example](https://github.com/oktadev/auth0-ai-samples/tree/main/authorization-for-rag/lanchain-js)
[View Example](https://github.com/auth0-samples/auth0-ai-samples/tree/main/authorization-for-rag/lanchain-js)

- **LangChain with FGARetriever (Python):**
A Python implementation demonstrating authorization-aware document retrieval using LangChain and FGARetriever.
[View Example](https://github.com/oktadev/auth0-ai-samples/tree/main/authorization-for-rag/langchain-python)
[View Example](https://github.com/auth0-samples/auth0-ai-samples/tree/main/authorization-for-rag/langchain-python)

- **LangGraph with FGARetriever (Python):**
Shows how to integrate FGARetriever with LangGraph for authorized document retrieval in Python applications.
[View Example](https://github.com/oktadev/auth0-ai-samples/tree/main/authorization-for-rag/langgraph-python)
[View Example](https://github.com/auth0-samples/auth0-ai-samples/tree/main/authorization-for-rag/langgraph-python)

- **LangChain4j with FGARetriever (Java):**
A Java implementation demonstrating authorization-aware document retrieval using LangChain4j and FGARetriever.
[View Example](https://github.com/oktadev/auth0-ai-samples/tree/main/authorization-for-rag/langchain4j-java)
[View Example](https://github.com/auth0-samples/auth0-ai-samples/tree/main/authorization-for-rag/langchain4j-java)

- **LangGraph Agentic with FGARetriever (JavaScript):**
Shows how to integrate FGARetriever with LangGraph's agentic framework for authorized document retrieval in JavaScript.
[View Example](https://github.com/oktadev/auth0-ai-samples/tree/main/authorization-for-rag/langgraph-agentic-js)
[View Example](https://github.com/auth0-samples/auth0-ai-samples/tree/main/authorization-for-rag/langgraph-agentic-js)

- **LangGraph StateGraph with FGARetriever (JavaScript):**
Demonstrates using FGARetriever with LangGraph's state graph approach for authorized retrieval in JavaScript.
[View Example](https://github.com/oktadev/auth0-ai-samples/tree/main/authorization-for-rag/langgraph-stategraph-js)
[View Example](https://github.com/auth0-samples/auth0-ai-samples/tree/main/authorization-for-rag/langgraph-stategraph-js)

- **LlamaIndex with FGARetriever (JavaScript):**
An implementation showing how to use FGARetriever with LlamaIndex for authorized document retrieval in JavaScript.
[View Example](https://github.com/oktadev/auth0-ai-samples/tree/main/authorization-for-rag/llamaindex-js)
[View Example](https://github.com/auth0-samples/auth0-ai-samples/tree/main/authorization-for-rag/llamaindex-js)

- **LlamaIndex Agentic with FGARetriever (JavaScript):**
Shows how to combine FGARetriever with LlamaIndex's agentic capabilities for authorized retrieval in JavaScript.
[View Example](https://github.com/oktadev/auth0-ai-samples/tree/main/authorization-for-rag/llamaindex-agentic-js)
[View Example](https://github.com/auth0-samples/auth0-ai-samples/tree/main/authorization-for-rag/llamaindex-agentic-js)

- **OpenAI with FGARetriever (JavaScript):**
A direct implementation using OpenAI's APIs with FGARetriever for authorized document retrieval in JavaScript.
[View Example](https://github.com/oktadev/auth0-ai-samples/tree/main/authorization-for-rag/openai-fga-js)
[View Example](https://github.com/auth0-samples/auth0-ai-samples/tree/main/authorization-for-rag/openai-fga-js)

- **Vercel AI with FGAFilter (JavaScript):**
A direct implementation using Vercel AI SDk with FGAFilter for authorized document retrieval in JavaScript.
[View Example](https://github.com/auth0-samples/auth0-ai-samples/tree/main/authorization-for-rag/vercel-ai-js)
2 changes: 1 addition & 1 deletion authorization-for-rag/langchain-js/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
OPENAI_API_KEY=<your-openai-api-key>


# Okta FGA
# Auth0 FGA
FGA_STORE_ID=<your-fga-store-id>
FGA_CLIENT_ID=<your-fga-store-client-id>
FGA_CLIENT_SECRET=<your-fga-store-client-secret>
Expand Down
10 changes: 5 additions & 5 deletions authorization-for-rag/langchain-js/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# LangChain Retrievers + Okta FGA
# LangChain Retrievers + Auth0 FGA

This example demonstrates how to combine [LangChain](https://js.langchain.com/docs/tutorials/) with robust authorization controls for RAG workflows. Using [Okta FGA](https://docs.fga.dev/), it ensures that users can only access documents they are authorized to view. The example retrieves relevant documents, enforces access permissions, and generates responses based only on authorized data, maintaining strict data security and preventing unauthorized access.
This example demonstrates how to combine [LangChain](https://js.langchain.com/docs/tutorials/) with robust authorization controls for RAG workflows. Using [Auth0 FGA](https://docs.fga.dev/), it ensures that users can only access documents they are authorized to view. The example retrieves relevant documents, enforces access permissions, and generates responses based only on authorized data, maintaining strict data security and preventing unauthorized access.

## Getting Started

### Prerequisites

- An Okta FGA account, you can create one [here](https://dashboard.fga.dev).
- An Auth0 FGA account, you can create one [here](https://dashboard.fga.dev).
- An OpenAI account and API key create one [here](https://platform.openai.com).

### Setup
Expand All @@ -17,7 +17,7 @@ This example demonstrates how to combine [LangChain](https://js.langchain.com/do
# OpenAI
OPENAI_API_KEY=xx-xxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx

# Okta FGA
# Auth0 FGA
FGA_STORE_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxx
FGA_CLIENT_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxx
FGA_CLIENT_SECRET=xxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx
Expand All @@ -30,7 +30,7 @@ This example demonstrates how to combine [LangChain](https://js.langchain.com/do

[Use this page for instructions on how to find your OpenAI API key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key). Once you have your key, update the `.env` file accordingly.

#### Configure Okta FGA
#### Configure Auth0 FGA

1. **Create a client**

Expand Down
13 changes: 6 additions & 7 deletions authorization-for-rag/langchain-js/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
/**
* LangChain Example: Retrievers with Okta FGA (Fine-Grained Authorization)
* LangChain Example: Retrievers with Auth0 FGA (Fine-Grained Authorization)
*/
import "dotenv/config";

import { MemoryVectorStore } from "langchain/vectorstores/memory";
import { OpenAIEmbeddings } from "@langchain/openai";
// Once published to NPM, this will become `import { FGARetriever } from "@auth0/ai-langchain";`
import { FGARetriever } from "auth0-ai-js/packages/ai-langchain/src";
import { FGARetriever } from "@auth0/ai-langchain/RAG";
import { RetrievalChain } from "./helpers/langchain";
import { readDocuments } from "./helpers/read-documents";

/**
* Demonstrates the usage of the Okta FGA (Fine-Grained Authorization)
* Demonstrates the usage of the Auth0 FGA (Fine-Grained Authorization)
* with a vector store index to query documents with permission checks.
*
* The FGARetriever checks if the user has the "viewer" relation to the document
* based on predefined tuples in Okta FGA.
* based on predefined tuples in Auth0 FGA.
*
* Example:
* - A tuple {user: "user:*", relation: "viewer", object: "doc:public-doc"} allows all users to view "public-doc".
Expand All @@ -25,7 +24,7 @@ import { readDocuments } from "./helpers/read-documents";
*/
async function main() {
console.info(
"\n..:: Langchain Example: Retrievers with Okta FGA (Fine-Grained Authorization)\n\n"
"\n..:: Langchain Example: Retrievers with Auth0 FGA (Fine-Grained Authorization)\n\n"
);

// UserID
Expand Down Expand Up @@ -59,7 +58,7 @@ async function main() {
console.info(answer);

/**
* If we add the following tuple to the Okta FGA:
* If we add the following tuple to the Auth0 FGA:
*
* { user: "user:user1", relation: "viewer", object: "doc:private-doc" }
*
Expand Down
Loading