using Microsoft.AspNet.Authentication;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Authentication;
using System.Security.Claims;
namespace OAuth.AspNet.AuthServer
{
///
/// Base class used for certain event contexts
///
public abstract class BaseValidatingTicketContext : BaseValidatingContext where TOptions : AuthenticationOptions
{
///
/// Initializes base class used for certain event contexts
///
protected BaseValidatingTicketContext(HttpContext context, TOptions options, AuthenticationTicket ticket) : base(context, options)
{
Ticket = ticket;
}
///
/// Contains the identity and properties for the application to authenticate. If the Validated method
/// is invoked with an AuthenticationTicket or ClaimsIdentity argument, that new value is assigned to
/// this property in addition to changing IsValidated to true.
///
public AuthenticationTicket Ticket { get; private set; }
///
/// Replaces the ticket information on this context and marks it as as validated by the application.
/// IsValidated becomes true and HasError becomes false as a result of calling.
///
/// Assigned to the Ticket property
/// True if the validation has taken effect.
public bool Validated(AuthenticationTicket ticket)
{
Ticket = ticket;
return Validated();
}
///
/// Alters the ticket information on this context and marks it as as validated by the application.
/// IsValidated becomes true and HasError becomes false as a result of calling.
///
/// Assigned to the Ticket.Identity property
/// True if the validation has taken effect.
public bool Validated(ClaimsPrincipal principal)
{
AuthenticationProperties properties = Ticket != null ? Ticket.Properties : new AuthenticationProperties();
return Validated(new AuthenticationTicket(principal, properties, Options.AuthenticationScheme));
}
}
}