// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Globalization; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Authentication; using Microsoft.AspNet.Authentication.OAuth; using Microsoft.AspNet.DataProtection; using Microsoft.Framework.Logging; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Authentication.Facebook { /// /// An ASP.NET middleware for authenticating users using Facebook. /// public class FacebookAuthenticationMiddleware : OAuthAuthenticationMiddleware { /// /// Initializes a new . /// /// The next middleware in the application pipeline to invoke. /// /// /// Configuration options for the middleware. public FacebookAuthenticationMiddleware( RequestDelegate next, IServiceProvider services, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IOptions externalOptions, IOptions options, ConfigureOptions configureOptions = null) : base(next, services, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions) { if (string.IsNullOrWhiteSpace(Options.AppId)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "AppId")); } if (string.IsNullOrWhiteSpace(Options.AppSecret)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "AppSecret")); } if (Options.Notifications == null) { Options.Notifications = new FacebookAuthenticationNotifications(); } } /// /// Provides the object for processing authentication-related requests. /// /// An configured with the supplied to the constructor. protected override AuthenticationHandler CreateHandler() { return new FacebookAuthenticationHandler(Backchannel, Logger); } } }