// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNet.Identity; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; namespace Microsoft.AspNet.Builder { /// /// Identity extensions for . /// public static class BuilderExtensions { /// /// Enables ASP.NET identity for the current application. /// /// The instance this method extends. /// The instance this method extends. public static IApplicationBuilder UseIdentity(this IApplicationBuilder app) { if (app == null) { throw new ArgumentNullException(nameof(app)); } var marker = app.ApplicationServices.GetService(); if (marker == null) { throw new InvalidOperationException(Resources.MustCallAddIdentity); } var options = app.ApplicationServices.GetRequiredService>().Value; app.UseCookieAuthentication(options.Cookies.ExternalCookie); app.UseCookieAuthentication(options.Cookies.TwoFactorRememberMeCookie); app.UseCookieAuthentication(options.Cookies.TwoFactorUserIdCookie); app.UseCookieAuthentication(options.Cookies.ApplicationCookie); return app; } } }