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 static IAppBuilder RegisterLoggerFactory(this IAppBuilder app, IDependencyResolver resolver) { var owinLoggerFactory = AppBuilderLoggerExtensions.GetLoggerFactory(app); var loggerFactory = new CustomLoggerFactory(resolver, owinLoggerFactory); AppBuilderLoggerExtensions.SetLoggerFactory(app, loggerFactory); return(app); }
/// <summary> /// Initializes a <see cref="T:Taitans.Owin.Security.QQ.QQOAuth2AuthenticationMiddleware" /> /// </summary> /// <param name="next">The next middleware in the OWIN pipeline to invoke</param> /// <param name="app">The OWIN application</param> /// <param name="options">Configuration options for the middleware</param> public QQOAuth2AuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, QQOAuth2AuthenticationOptions options) : base(next, options) { if (string.IsNullOrWhiteSpace(base.Options.ClientId)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "The '{0}' option must be provided.", new object[] { "ClientId" })); } if (string.IsNullOrWhiteSpace(base.Options.ClientSecret)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "The '{0}' option must be provided.", new object[] { "ClientSecret" })); } this._logger = AppBuilderLoggerExtensions.CreateLogger <QQOAuth2AuthenticationMiddleware>(app); if (base.Options.Provider == null) { base.Options.Provider = new QQOAuth2AuthenticationProvider(); } if (base.Options.StateDataFormat == null) { IDataProtector protector = app.CreateDataProtector(new string[] { typeof(QQOAuth2AuthenticationMiddleware).FullName, base.Options.AuthenticationType, "v1" }); base.Options.StateDataFormat = new PropertiesDataFormat(protector); } if (string.IsNullOrEmpty(base.Options.SignInAsAuthenticationType)) { base.Options.SignInAsAuthenticationType = app.GetDefaultSignInAsAuthenticationType(); } this._httpClient = new HttpClient(QQOAuth2AuthenticationMiddleware.ResolveHttpMessageHandler(base.Options)); this._httpClient.Timeout = base.Options.BackchannelTimeout; this._httpClient.MaxResponseContentBufferSize = 10485760L; }
public SinaAuthenticationMiddleware(OwinMiddleware next, IAppBuilder app, SinaAuthenticationOptions options) : base(next, options) { this._logger = AppBuilderLoggerExtensions.CreateLogger <SinaAuthenticationMiddleware>(app); if (options.Provider == null) { options.Provider = new SinaAuthenticationProvider(); } if (this.Options.StateDataFormat == null) { this.Options.StateDataFormat = new PropertiesDataFormat(app.CreateDataProtector(typeof(SinaAuthenticationMiddleware).FullName, this.Options.AuthenticationType, "v1")); } if (string.IsNullOrEmpty(this.Options.SignInAsAuthenticationType)) { this.Options.SignInAsAuthenticationType = AppBuilderSecurityExtensions.GetDefaultSignInAsAuthenticationType(app); } this._httpClient = new HttpClient(ResolveHttpMessageHandler(this.Options)); this._httpClient.MaxResponseContentBufferSize = 10485760L; }
/// <summary> /// Bearer authentication component which is added to an OWIN pipeline. This constructor is not /// called by application code directly, instead it is added by calling the the IAppBuilder UseOAuthBearerAuthentication /// extension method. /// /// </summary> public OAuthBearerAuthenticationMiddlewareExtended(OwinMiddleware next, IAppBuilder app, OAuthBearerAuthenticationOptions options) : base(next, options) { _logger = AppBuilderLoggerExtensions.CreateLogger <OAuthBearerAuthenticationMiddlewareExtended>(app); _challenge = string.IsNullOrWhiteSpace(Options.Challenge) ? (!string.IsNullOrWhiteSpace(Options.Realm) ? "Bearer realm=\"" + this.Options.Realm + "\"" : "Bearer") : this.Options.Challenge; if (Options.Provider == null) { Options.Provider = new OAuthBearerAuthenticationProvider(); } if (Options.AccessTokenFormat == null) { Options.AccessTokenFormat = new TicketDataFormat( Microsoft.Owin.Security.DataProtection.AppBuilderExtensions.CreateDataProtector(app, typeof(OAuthBearerAuthenticationMiddleware).Namespace, "Access_Token", "v1")); } if (Options.AccessTokenProvider != null) { return; } Options.AccessTokenProvider = new AuthenticationTokenProvider(); }