// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Security.Cookies
{
///
/// This default implementation of the ICookieAuthenticationNotifications may be used if the
/// application only needs to override a few of the interface methods. This may be used as a base class
/// or may be instantiated directly.
///
public class CookieAuthenticationNotifications : ICookieAuthenticationNotifications
{
///
/// Create a new instance of the default notifications.
///
public CookieAuthenticationNotifications()
{
OnValidateIdentity = context => Task.FromResult(0);
OnResponseSignIn = context => { };
OnResponseSignOut = context => { };
OnApplyRedirect = DefaultBehavior.ApplyRedirect;
}
///
/// A delegate assigned to this property will be invoked when the related method is called
///
public Func OnValidateIdentity { get; set; }
///
/// A delegate assigned to this property will be invoked when the related method is called
///
public Action OnResponseSignIn { get; set; }
///
/// A delegate assigned to this property will be invoked when the related method is called
///
public Action OnResponseSignOut { get; set; }
///
/// A delegate assigned to this property will be invoked when the related method is called
///
public Action OnApplyRedirect { get; set; }
///
/// Implements the interface method by invoking the related delegate method
///
///
///
public virtual Task ValidateIdentity(CookieValidateIdentityContext context)
{
return OnValidateIdentity.Invoke(context);
}
///
/// Implements the interface method by invoking the related delegate method
///
///
public virtual void ResponseSignIn(CookieResponseSignInContext context)
{
OnResponseSignIn.Invoke(context);
}
///
/// Implements the interface method by invoking the related delegate method
///
///
public virtual void ResponseSignOut(CookieResponseSignOutContext context)
{
OnResponseSignOut.Invoke(context);
}
///
/// Called when a Challenge, SignIn, or SignOut causes a redirect in the cookie middleware
///
/// Contains information about the event
public void ApplyRedirect(CookieApplyRedirectContext context)
{
OnApplyRedirect.Invoke(context);
}
}
}