<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/build-a-secure-rag-system-with-microsoft-agent-framework-and-auth0-hu7skfzuj" -->

---
title: Build a Secure RAG System with Microsoft Agent Framework...
description: A step-by-step tutorial shows how to build a RAG-based expense report agent using Microsoft Agent Framework in .NET, storing embeddings with...
canonical: https://daily.dev/posts/build-a-secure-rag-system-with-microsoft-agent-framework-and-auth0-hu7skfzuj
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Build a Secure RAG System with Microsoft Agent Framework and Auth0 | daily.dev
og:description: A step-by-step tutorial shows how to build a RAG-based expense report agent using Microsoft Agent Framework in .NET, storing embeddings with...
og:url: https://daily.dev/posts/build-a-secure-rag-system-with-microsoft-agent-framework-and-auth0-hu7skfzuj
og:image: https://api.daily.dev/og/posts/HU7sKfzuJ.png
og:image:alt: Build a Secure RAG System with Microsoft Agent Framework and Auth0
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Build a Secure RAG System with Microsoft Agent Framework and Auth0

**[Auth0](https://daily.dev/sources/auth0)** · 15 min read · 4 upvotes · 0 comments

## Summary

A step-by-step tutorial shows how to build a RAG-based expense report agent using Microsoft Agent Framework in .NET, storing embeddings with CommunityToolkit.VectorData.InMemory and OpenAI's text-embedding-3-small model. It then secures the retrieval pipeline with Auth0 Fine-Grained Authorization (FGA), fetching a manager's authorized expense IDs before running the vector search so unauthorized records never reach the LLM. The tutorial walks through setting up the FGA store, defining an authorization model, writing permission tuples, and wiring an FgaService into the agent's tools and Blazor chat component, demonstrating that different managers see only their own direct reports' expenses.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://auth0.com/blog/building-secure-ai-agents-microsoft-agent-framework-auth0-part-2-rag-filtering>

## Questions this post answers

### How do you prevent an LLM from seeing unauthorized data in a RAG system?

Filter permissions before the vector search runs, not after. Query the authorization system (such as Auth0 FGA) for the list of object IDs the current user can read, then pass that allow-list as a filter into the vector search itself, so the LLM only ever receives context the user is permitted to see. Checking permissions on already-retrieved results is a common mistake because the LLM has already seen the leaked context by then.

_Developers securing agentic RAG pipelines can find implementation patterns like this on daily.dev._

### How do I add a filtered vector search to Microsoft Agent Framework using Microsoft.Extensions.VectorData?

Use the CommunityToolkit.VectorData.InMemory provider (or a persistent one like Azure AI Search or pgvector) with Microsoft.Extensions.VectorData, generate embeddings via the OpenAI SDK's EmbeddingClient with a model like text-embedding-3-small at 1536 dimensions, and pass a VectorSearchOptions.Filter lambda such as authorizedIds.Contains(r.Id) into the SearchAsync call to restrict results to an allow-list.

_Teams building agent tools with vector search filtering can track patterns like this via daily.dev._

## Similar posts on daily.dev

- [Building a RAG in ASP.NET Core](https://daily.dev/posts/building-a-rag-in-asp-net-core-mokd7eosh) · Telerik · 1 upvotes · 0 comments
- [Building Secure AI Agents with Microsoft Agent Framework and Auth0: Human-in-the-Loop Approval](https://daily.dev/posts/building-secure-ai-agents-with-microsoft-agent-framework-and-auth0-human-in-the-loop-approval-ajzmal9kz) · Auth0 · 2 upvotes · 0 comments
- [How to Use Build5Nines.SharpVector with Microsoft Agent Framework for Local RAG in C\#](https://daily.dev/posts/how-to-use-build5nines-sharpvector-with-microsoft-agent-framework-for-local-rag-in-c--2hqedzzy3) · Build5Nines · 0 upvotes · 0 comments
- [RAG Chat App with Your Own Data \(Python\)](https://daily.dev/posts/rag-chat-app-with-your-own-data-python--xrozadkve) · Medium · 0 upvotes · 0 comments

---

Tags: [#c#](https://daily.dev/tags/c#), [#rag](https://daily.dev/tags/rag), [#vector-search](https://daily.dev/tags/vector-search), [#auth0](https://daily.dev/tags/auth0)

[View this post on daily.dev](https://daily.dev/posts/build-a-secure-rag-system-with-microsoft-agent-framework-and-auth0-hu7skfzuj)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Build a Secure RAG System with Microsoft Agent Framework and Auth0","url":"https://daily.dev/posts/build-a-secure-rag-system-with-microsoft-agent-framework-and-auth0-hu7skfzuj","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/build-a-secure-rag-system-with-microsoft-agent-framework-and-auth0-hu7skfzuj"},"datePublished":"2026-08-12T18:08:55.236Z","dateModified":"2026-09-14T06:54:01.008Z","description":"A step-by-step tutorial shows how to build a RAG-based expense report agent using Microsoft Agent Framework in .NET, storing embeddings with...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2c989f2b7410fe9383530b474c5ee769?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2c989f2b7410fe9383530b474c5ee769?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Auth0","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Auth0","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/6510ffa7350449618fbacdddae663b82","url":"https://daily.dev/sources/auth0"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/build-a-secure-rag-system-with-microsoft-agent-framework-and-auth0-hu7skfzuj","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":4},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"c#,rag,vector-search,auth0","timeRequired":"PT15M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Auth0","item":"https://daily.dev/sources/auth0"},{"@type":"ListItem","position":3,"name":"Build a Secure RAG System with Microsoft Agent Framework and Auth0"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/build-a-secure-rag-system-with-microsoft-agent-framework-and-auth0-hu7skfzuj#faq","mainEntity":[{"@type":"Question","name":"How do you prevent an LLM from seeing unauthorized data in a RAG system?","acceptedAnswer":{"@type":"Answer","text":"Filter permissions before the vector search runs, not after. Query the authorization system (such as Auth0 FGA) for the list of object IDs the current user can read, then pass that allow-list as a filter into the vector search itself, so the LLM only ever receives context the user is permitted to see. Checking permissions on already-retrieved results is a common mistake because the LLM has already seen the leaked context by then. Developers securing agentic RAG pipelines can find implementation patterns like this on daily.dev."}},{"@type":"Question","name":"How do I add a filtered vector search to Microsoft Agent Framework using Microsoft.Extensions.VectorData?","acceptedAnswer":{"@type":"Answer","text":"Use the CommunityToolkit.VectorData.InMemory provider (or a persistent one like Azure AI Search or pgvector) with Microsoft.Extensions.VectorData, generate embeddings via the OpenAI SDK's EmbeddingClient with a model like text-embedding-3-small at 1536 dimensions, and pass a VectorSearchOptions.Filter lambda such as authorizedIds.Contains(r.Id) into the SearchAsync call to restrict results to an allow-list. Teams building agent tools with vector search filtering can track patterns like this via daily.dev."}}]}
```

