mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
401a552735
* feat: Add DelegatingAgentSessionStore Add helper for decorator pattern for AgentSessionStore * feat: Add UserIdentityScopedSessionStore Add support for using the ASP.Net Core ambient `ClaimsIdentity` User, along with a user-specified claim type to scope the session store based on authenticated identity. * fix: Harden scope mapping * fix: Add UserIdentityScopeSessionStoreOptions to avoid future breaking changes * Split UserIdentityScopedSessionStore into a separate IsolationKeyProvider and IsolationKeyScopedSessionStore * Add GetService<>() capabilities to interrogate AgentSessionStore delegation chain * Harden default for A2A hosting by using an IsolationKeyScopedAgentSessionStore when no store is available. * Pipe isolation through Hosting helper extension methods * Add comment to samples about adding SessionIsolationKeyProvider * Fix isolation key provider nullability semantics * fix A2A defaults * fixup * remove unneeded keyProvider requirement test * Add trust-model XML docs to AgentSessionStore, InMemoryAgentSessionStore, MapAGUI, A2A entry points Agent-Logs-Url: https://github.com/microsoft/agent-framework/sessions/e466c53a-faad-40a8-8b5f-83cf0dce0b1d Co-authored-by: lokitoth <6936551+lokitoth@users.noreply.github.com> * fix: Switch ClaimsBasedIsolationKeyProvider to be Singleton * matches HttpContextAccessor and related MAF services * release: Ensure new project is in the release filter * fixup: Integraitaon tests --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: lokitoth <6936551+lokitoth@users.noreply.github.com>
43 lines
1.8 KiB
C#
43 lines
1.8 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Microsoft.Agents.AI.Hosting;
|
|
|
|
/// <summary>
|
|
/// Extension methods for configuring AI hosting services in an <see cref="IServiceCollection"/>.
|
|
/// </summary>
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Registers a <see cref="SessionIsolationKeyProvider"/> that uses claims from the current user's identity
|
|
/// to generate session isolation keys.
|
|
/// </summary>
|
|
/// <param name="services">The <see cref="IServiceCollection"/> to add services to.</param>
|
|
/// <param name="options"> Optional configuration for the claims-based session isolation key provider.</param>
|
|
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
|
|
/// <remarks>
|
|
/// This method requires <see cref="IHttpContextAccessor"/> to be registered in the service collection.
|
|
/// Ensure that <c>services.AddHttpContextAccessor()</c> has been called before using this method.
|
|
/// </remarks>
|
|
public static IServiceCollection UseClaimsBasedSessionIsolation(
|
|
this IServiceCollection services,
|
|
ClaimsIdentitySessionIsolationKeyProviderOptions? options = null)
|
|
{
|
|
options ??= new();
|
|
ServiceDescriptor descriptor = new(typeof(SessionIsolationKeyProvider), CreateIsolationKeyProvider, ServiceLifetime.Singleton);
|
|
services.Add(descriptor);
|
|
|
|
return services;
|
|
|
|
object CreateIsolationKeyProvider(IServiceProvider serviceProvider)
|
|
{
|
|
IHttpContextAccessor contextAccessor = serviceProvider.GetRequiredService<IHttpContextAccessor>();
|
|
|
|
return new ClaimsIdentitySessionIsolationKeyProvider(contextAccessor, options);
|
|
}
|
|
}
|
|
}
|