using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace Yi.Framework.Core.Authentication;

public static class AuthenticationExtensions
{
    public static void RefreshAuthentication(this HttpContext context)
    {
        var currentAuthenticationHandler =
            context.RequestServices.GetRequiredService<IAuthenticationHandlerProvider>();
        if (currentAuthenticationHandler is IRefreshAuthenticationHandlerProvider refreshAuthenticationHandler)
        {
            refreshAuthenticationHandler.RefreshAuthentication();
        }
    }
}