public TwitterAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, TwitterAuthenticationOptions options) : base(next, options) { this._logger = AppBuilderLoggerExtensions.CreateLogger <TwitterAuthenticationMiddleware>(app); if (string.IsNullOrWhiteSpace(Options.ConsumerSecret)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Microsoft.Owin.Resources.Exception_OptionMustBeProvided:{0}", new object[] { "ConsumerSecret" })); } if (string.IsNullOrWhiteSpace(Options.ConsumerKey)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Microsoft.Owin.Resources.Exception_OptionMustBeProvided:{0}", new object[] { "ConsumerKey" })); } if (Options.Provider == null) { Options.Provider = new TwitterAuthenticationProvider(); } if (Options.StateDataFormat == null) { IDataProtector protector = AppBuilderExtensions.CreateDataProtector(app, new string[] { typeof(TwitterAuthenticationMiddleware).FullName, Options.AuthenticationType, "v1" }); Options.StateDataFormat = new SecureDataFormat <RequestToken>(Serializers.RequestToken, protector, TextEncodings.Base64Url); } if (string.IsNullOrEmpty(Options.SignInAsAuthenticationType)) { Options.SignInAsAuthenticationType = AppBuilderSecurityExtensions.GetDefaultSignInAsAuthenticationType(app); } this._httpClient = new HttpClient(ResolveHttpMessageHandler(Options)); this._httpClient.Timeout = Options.BackchannelTimeout; this._httpClient.MaxResponseContentBufferSize = 0xa00000L; this._httpClient.DefaultRequestHeaders.Accept.ParseAdd("*/*"); this._httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("Microsoft Owin Twitter middleware"); this._httpClient.DefaultRequestHeaders.ExpectContinue = false; }
public void ConfigureAuth(IAppBuilder app) { AppBuilderExtensions.CreatePerOwinContext <ApplicationDbContext>(app, (Func <M0>) new Func <ApplicationDbContext>(ApplicationDbContext.Create)); AppBuilderExtensions.CreatePerOwinContext <ApplicationUserManager>(app, (Func <IdentityFactoryOptions <M0>, IOwinContext, M0>) new Func <IdentityFactoryOptions <ApplicationUserManager>, IOwinContext, ApplicationUserManager>(ApplicationUserManager.Create)); AppBuilderExtensions.CreatePerOwinContext <ApplicationSignInManager>(app, (Func <IdentityFactoryOptions <M0>, IOwinContext, M0>) new Func <IdentityFactoryOptions <ApplicationSignInManager>, IOwinContext, ApplicationSignInManager>(ApplicationSignInManager.Create)); IAppBuilder iappBuilder = app; CookieAuthenticationOptions authenticationOptions1 = new CookieAuthenticationOptions(); ((AuthenticationOptions)authenticationOptions1).set_AuthenticationType("ApplicationCookie"); authenticationOptions1.set_LoginPath(new PathString("/Account/Login")); CookieAuthenticationOptions authenticationOptions2 = authenticationOptions1; CookieAuthenticationProvider authenticationProvider1 = new CookieAuthenticationProvider(); authenticationProvider1.set_OnValidateIdentity(SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>(TimeSpan.FromMinutes(30.0), (Func <M0, M1, Task <ClaimsIdentity> >)((manager, user) => user.GenerateUserIdentityAsync((UserManager <ApplicationUser>)manager)))); CookieAuthenticationProvider authenticationProvider2 = authenticationProvider1; authenticationOptions2.set_Provider((ICookieAuthenticationProvider)authenticationProvider2); CookieAuthenticationOptions authenticationOptions3 = authenticationOptions1; CookieAuthenticationExtensions.UseCookieAuthentication(iappBuilder, authenticationOptions3); AppBuilderExtensions.UseExternalSignInCookie(app, "ExternalCookie"); AppBuilderExtensions.UseTwoFactorSignInCookie(app, "TwoFactorCookie", TimeSpan.FromMinutes(5.0)); AppBuilderExtensions.UseTwoFactorRememberBrowserCookie(app, "TwoFactorRememberBrowser"); }