Tutorials ASP.NET Core with Agentic AI Tutorial
AI Authorization — Complete Guide
AI Authorization — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of ASP.NET Core with Agentic AI Tutorial on Toolliyo Academy.
On this page
ASP.NET Core with Agentic AI Tutorial · Lesson 54 of 100
AI Authorization
AI basics ✓ → Agents
Agents · 2 — Build · ~10 min · Module 6: AI Security and Observability
What is this?
AI authorization controls which users and agents may invoke models, tools, and memory scopes. AgentNest maps Entra groups to plugin sets and CRM record-level access.
Why should you care?
Hospital resident and attending roles see different patient tools; ERP agents cannot post journals without Finance role.
See it live — copy this example
Paste into an ASP.NET Core 8+ / AgentNest project, then run with dotnet run (set your API keys in user-secrets).
// AgentNest.Security/AiAuthorizationHandler.cs
public sealed class AiToolAuthorizationHandler : AuthorizationHandler<ToolInvocationRequirement, KernelFunction>
{
protected override Task HandleRequirementAsync(
AuthorizationHandlerContext context, ToolInvocationRequirement req, KernelFunction resource)
{
var allowed = context.User.FindAll("tool").Select(c => c.Value).ToHashSet();
if (allowed.Contains(resource.PluginName + "." + resource.Name))
context.Succeed(req);
return Task.CompletedTask;
}
}
What happened?
- AuthorizationHandler checks JWT tool claims against requested KernelFunction.
- CRM users with crm.read only cannot invoke crm.sendEmail.
Practice next
- Emit tool claims from Entra app roles at token issue.
- Register AiToolAuthorizationHandler in Program.cs.
- Wrap auto tool invoke with IAuthorizationService.CheckAsync.
- Add record-level CRM filter inside plugin using user id claim.
- Cache authorization decisions 60s per user/tool.
Remember
Authorize each tool invocation, not just /api/ai routes. Map Entra roles to tool claims for AgentNest plugins. Fail closed when claims missing.
Finance journal guard
Analyst attempts ERP agent journal post without FinanceTools role.
Outcome: Authorization handler blocks gl.post_journal before SQL runs.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!