protected AuthenticationMiddleware( [NotNull] RequestDelegate next, [NotNull] IOptions <TOptions> options, [NotNull] ILoggerFactory loggerFactory, [NotNull] IUrlEncoder encoder, ConfigureOptions <TOptions> configureOptions) { if (configureOptions != null) { Options = options.GetNamedOptions(configureOptions.Name); configureOptions.Configure(Options, configureOptions.Name); } else { Options = options.Options; } Logger = loggerFactory.CreateLogger(this.GetType().FullName); UrlEncoder = encoder; if (string.IsNullOrEmpty(Options.ClaimsIssuer)) { // Default to something reasonable Options.ClaimsIssuer = Options.AuthenticationScheme; } _next = next; }
public FarmerEntity(ConfigureOptions option) { EndpointName = "farmer-entity"; Configure(option); InitialiseAttributes(); InitialiseReferences(); }
private void CreateManager(bool compress = false) { ConfigureOptions <SchubertRedisOptions> prop = new ConfigureOptions <SchubertRedisOptions>(op => { op.ConnectionString = "127.0.0.1:6379,abortConnect=false,ssl=false"; //op.ConnectionString = "10.66.126.116:19000,abortConnect = false,ssl = false,password = Setpay123,connectTimeout = 10000,syncTimeout = 120000"; op.GZipCompress = compress; op.SerializerName = RedisSerializerNames.JsonNet; }); IOptions <SchubertRedisOptions> options = new OptionsManager <SchubertRedisOptions>(new OptionsFactory <SchubertRedisOptions>(new IConfigureOptions <SchubertRedisOptions>[] { prop }, new IPostConfigureOptions <SchubertRedisOptions> [0])); var sop = new ConfigureOptions <SchubertOptions>(op => { op.AppSystemName = "testapp"; op.Group = "jcgjz"; }); IOptions <SchubertOptions> schubertOptions = new OptionsManager <SchubertOptions>(new OptionsFactory <SchubertOptions>(new IConfigureOptions <SchubertOptions>[] { sop }, new IPostConfigureOptions <SchubertOptions> [0])); _manager = new RedisCacheManager(schubertOptions, options); }
public CookieAuthenticationMiddleware(RequestDelegate next, IServiceProvider services, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IOptions <CookieAuthenticationOptions> options, ConfigureOptions <CookieAuthenticationOptions> configureOptions) : base(next, services, options, configureOptions) { if (Options.Notifications == null) { Options.Notifications = new CookieAuthenticationNotifications(); } if (String.IsNullOrEmpty(Options.CookieName)) { Options.CookieName = CookieAuthenticationDefaults.CookiePrefix + Options.AuthenticationType; } if (Options.TicketDataFormat == null) { IDataProtector dataProtector = dataProtectionProvider.CreateDataProtector( typeof(CookieAuthenticationMiddleware).FullName, Options.AuthenticationType, "v2"); Options.TicketDataFormat = new TicketDataFormat(dataProtector); } if (Options.CookieManager == null) { Options.CookieManager = new ChunkingCookieManager(); } _logger = loggerFactory.Create(typeof(CookieAuthenticationMiddleware).FullName); }
public BasicAuthenticationMiddleware( RequestDelegate next, IOptions <BasicAuthenticationOptions> options, ConfigureOptions <BasicAuthenticationOptions> configureOptions) : base(next, options, configureOptions) { }
public override int Transform([NotNull] GlobalContext globalContext, [NotNull] ConfigureOptions configureOptions, Ignore Ignore, [NotNull][ItemNotNull] IEnumerable <Dependency> dependencies, [NotNull] List <Dependency> transformedDependencies) { if (!configureOptions.OrderedActions.Any()) { Log.WriteWarning($"No actions configured for {GetType().Name}"); } else { foreach (var d in dependencies) { DependencyAction firstMatchingAction = configureOptions.OrderedActions.FirstOrDefault(a => a.IsMatch(d)); if (firstMatchingAction == null) { Log.WriteWarning("No match in actions for dependency " + d); } else { if (firstMatchingAction.Apply(d)) { transformedDependencies.Add(d); } } } } return(Program.OK_RESULT); }
public CookieAuthenticationMiddleware( [NotNull] RequestDelegate next, [NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] ILoggerFactory loggerFactory, [NotNull] IUrlEncoder urlEncoder, [NotNull] IOptions <CookieAuthenticationOptions> options, ConfigureOptions <CookieAuthenticationOptions> configureOptions) : base(next, options, loggerFactory, urlEncoder, configureOptions) { if (Options.Notifications == null) { Options.Notifications = new CookieAuthenticationNotifications(); } if (String.IsNullOrEmpty(Options.CookieName)) { Options.CookieName = CookieAuthenticationDefaults.CookiePrefix + Options.AuthenticationScheme; } if (Options.TicketDataFormat == null) { var dataProtector = dataProtectionProvider.CreateProtector( typeof(CookieAuthenticationMiddleware).FullName, Options.AuthenticationScheme, "v2"); Options.TicketDataFormat = new TicketDataFormat(dataProtector); } if (Options.CookieManager == null) { Options.CookieManager = new ChunkingCookieManager(urlEncoder); } }
public AdminEntity(ConfigureOptions option) { EndpointName = "admin-entity"; Configure(option); InitialiseAttributes(); InitialiseReferences(); }
/// <summary> /// Initializes a new <see cref="GoogleAuthenticationMiddleware"/>. /// </summary> /// <param name="next">The next middleware in the HTTP pipeline to invoke.</param> /// <param name="services"></param> /// <param name="dataProtectionProvider"></param> /// <param name="loggerFactory"></param> /// <param name="options">Configuration options for the middleware.</param> public GoogleAuthenticationMiddleware( RequestDelegate next, IServiceProvider services, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IOptions <ExternalAuthenticationOptions> externalOptions, IOptions <GoogleAuthenticationOptions> options, ConfigureOptions <GoogleAuthenticationOptions> configureOptions = null) : base(next, services, dataProtectionProvider, loggerFactory, externalOptions, options, configureOptions) { if (Options.Notifications == null) { Options.Notifications = new GoogleAuthenticationNotifications(); } if (Options.Scope.Count == 0) { // Google OAuth 2.0 asks for non-empty scope. If user didn't set it, set default scope to // "openid profile email" to get basic user information. // TODO: Should we just add these by default when we create the Options? Options.Scope.Add("openid"); Options.Scope.Add("profile"); Options.Scope.Add("email"); } }
public MultiTenantFacebookAuthenticationMiddleware( RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, ISiteResolver siteResolver, ISiteRepository siteRepository, IOptions <MultiTenantOptions> multiTenantOptionsAccesor, IUrlEncoder encoder, IOptions <SharedAuthenticationOptions> sharedOptions, IOptions <FacebookAuthenticationOptions> options, ConfigureOptions <FacebookAuthenticationOptions> configureOptions = null) : base(next, dataProtectionProvider, loggerFactory, encoder, siteResolver, multiTenantOptionsAccesor, sharedOptions, options, configureOptions) { //if (string.IsNullOrEmpty(Options.AppId)) //{ // throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(Options.AppId))); //} //if (string.IsNullOrEmpty(Options.AppSecret)) //{ // throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(Options.AppSecret))); //} this.loggerFactory = loggerFactory; this.siteResolver = siteResolver; multiTenantOptions = multiTenantOptionsAccesor.Options; siteRepo = siteRepository; }
static int Configure(ConfigureOptions options) { _logger.LogDebug($"Entering {LoggingHelper.GetMyMethodName()} with scan options {options}"); var _localizationRepository = LoggingHelper.GetLocalizationRepository(options.Language); _logger.LogInformation(_localizationRepository.GetText("INFO00001", options.ToString())); var declareConfigRepository = new DeclareConfigurationRepository(options.JsonFileLocation); foreach (var app in declareConfigRepository.Apps()) { _logger.LogInformation($"Starting build for {app.application_name}"); _dscLogic.MakeItSoPolicy(app, app.policy); if (!_dscLogic.MakeItSoApp(app)) { return(0); } _dscLogic.MakeItSoTeam(app); foreach (var user in app.users) { user.teams = app.application_name; _dscLogic.MakeItSoUser(user, app); } _dscLogic.MakeItSoMitigations(app); _dscLogic.MakeItSoSandboxes(app); _logger.LogInformation($"build complete for {app.application_name}"); } _logger.LogDebug($"Exiting {LoggingHelper.GetMyMethodName()} with value {1}"); return(1); }
public override void Configure(ConfigureOptions option) { switch (option) { case ConfigureOptions.CREATE_ATTRIBUTES_AND_REFERENCES: SetValidEntityAttributes(); SetValidEntityAssociations(); break; case ConfigureOptions.CREATE_ATTRIBUTES_ONLY: SetValidEntityAttributes(); break; case ConfigureOptions.CREATE_REFERENCES_ONLY: SetValidEntityAssociations(); break; case ConfigureOptions.CREATE_INVALID_ATTRIBUTES: SetInvalidEntityAttributes(); break; case ConfigureOptions.CREATE_INVALID_ATTRIBUTES_VALID_REFERENCES: SetInvalidEntityAttributes(); SetValidEntityAssociations(); break; } }
public SessionMiddleware( [NotNull] RequestDelegate next, [NotNull] ILoggerFactory loggerFactory, [NotNull] IEnumerable <ISessionStore> sessionStore, [NotNull] IOptions <SessionOptions> options, [NotNull] ConfigureOptions <SessionOptions> configureOptions) { _next = next; _logger = loggerFactory.Create <SessionMiddleware>(); if (configureOptions != null) { _options = options.GetNamedOptions(configureOptions.Name); configureOptions.Configure(_options); } else { _options = options.Options; } if (_options.Store == null) { _options.Store = sessionStore.FirstOrDefault(); if (_options.Store == null) { throw new ArgumentException("ISessionStore must be specified."); } } _options.Store.Connect(); }
/// <summary> /// Initializes a new <see cref="MicrosoftAccountAuthenticationMiddleware"/>. /// </summary> /// <param name="next">The next middleware in the HTTP pipeline to invoke.</param> /// <param name="dataProtectionProvider"></param> /// <param name="loggerFactory"></param> /// <param name="encoder"></param> /// <param name="sharedOptions"></param> /// <param name="options">Configuration options for the middleware.</param> /// <param name="configureOptions"></param> public MultiTenantMicrosoftAccountAuthenticationMiddleware( RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, ISiteResolver siteResolver, ISiteRepository siteRepository, IOptions <MultiTenantOptions> multiTenantOptionsAccesor, IUrlEncoder encoder, IOptions <SharedAuthenticationOptions> sharedOptions, IOptions <MicrosoftAccountAuthenticationOptions> options, ConfigureOptions <MicrosoftAccountAuthenticationOptions> configureOptions = null) : base( next, dataProtectionProvider, loggerFactory, encoder, siteResolver, multiTenantOptionsAccesor, sharedOptions, options, configureOptions) { if (Options.Scope.Count == 0) { // LiveID requires a scope string, so if the user didn't set one we go for the least possible. // TODO: Should we just add these by default when we create the Options? Options.Scope.Add("wl.basic"); } this.loggerFactory = loggerFactory; this.siteResolver = siteResolver; multiTenantOptions = multiTenantOptionsAccesor.Options; siteRepo = siteRepository; }
protected override ConfigureOptions CreateConfigureOptions(GlobalContext globalContext, string configureOptionsString, bool forceReload) { var options = new ConfigureOptions(); Option.Parse(globalContext, configureOptionsString, RuleFileExtensionOption.Action((args, j) => { options.RuleFileExtension = '.' + Option.ExtractRequiredOptionValue(args, ref j, "missing extension").TrimStart('.'); return(j); }), RuleRootDirectoryOption.Action((args, j) => { options.SearchRootsForRuleFiles.Add(new DirectoryInfo(Option.ExtractRequiredOptionValue(args, ref j, "missing rule-search root directory"))); return(j); }), DefaultRuleFileOption.Action((args, j) => { string fullSourceName = Path.GetFullPath(Option.ExtractRequiredOptionValue(args, ref j, "missing default rules filename")); options.DefaultRuleSet = GetOrReadChildConfiguration(globalContext, () => new StreamReader(fullSourceName), fullSourceName, globalContext.IgnoreCase, "????", forceReload, options.LocalVars); return(j); }), DefaultRulesOption.Action((args, j) => { options.DefaultRuleSet = GetOrReadChildConfiguration(globalContext, () => new StringReader(string.Join(Environment.NewLine, args.Skip(j + 1))), DefaultRulesOption.ShortName, globalContext.IgnoreCase, "????", forceReload: true, localVars: options.LocalVars); // ... and all args are read in, so the next arg index is past every argument. return(int.MaxValue); }) ); return(options); }
/// <summary> /// Initializes a <see cref="TwitterAuthenticationMiddleware"/> /// </summary> /// <param name="next">The next middleware in the HTTP pipeline to invoke</param> /// <param name="dataProtectionProvider"></param> /// <param name="loggerFactory"></param> /// <param name="encoder"></param> /// <param name="sharedOptions"></param> /// <param name="options">Configuration options for the middleware</param> /// <param name="configureOptions"></param> public MultiTenantTwitterAuthenticationMiddleware( RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, ISiteResolver siteResolver, ISiteRepository siteRepository, IOptions<MultiTenantOptions> multiTenantOptionsAccesor, IUrlEncoder encoder, IOptions<SharedAuthenticationOptions> sharedOptions, IOptions<TwitterAuthenticationOptions> options, ConfigureOptions<TwitterAuthenticationOptions> configureOptions = null) : base(next, options, loggerFactory, encoder, configureOptions) { //if (string.IsNullOrEmpty(Options.ConsumerSecret)) //{ // throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(Options.ConsumerSecret))); //} //if (string.IsNullOrEmpty(Options.ConsumerKey)) //{ // throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(Options.ConsumerKey))); //} if (Options.Notifications == null) { Options.Notifications = new TwitterAuthenticationNotifications(); } if (Options.StateDataFormat == null) { var dataProtector = dataProtectionProvider.CreateProtector( typeof(TwitterAuthenticationMiddleware).FullName, Options.AuthenticationScheme, "v1"); Options.StateDataFormat = new SecureDataFormat<RequestToken>( Serializers.RequestToken, dataProtector, TextEncodings.Base64Url); } if (string.IsNullOrEmpty(Options.SignInScheme)) { Options.SignInScheme = sharedOptions.Options.SignInScheme; } if (string.IsNullOrEmpty(Options.SignInScheme)) { //throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "SignInScheme")); throw new ArgumentException("Resources.Exception_OptionMustBeProvided, SignInScheme"); } _httpClient = new HttpClient(ResolveHttpMessageHandler(Options)); _httpClient.Timeout = Options.BackchannelTimeout; _httpClient.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB _httpClient.DefaultRequestHeaders.Accept.ParseAdd("*/*"); _httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("Microsoft ASP.NET Twitter middleware"); _httpClient.DefaultRequestHeaders.ExpectContinue = false; this.loggerFactory = loggerFactory; this.siteResolver = siteResolver; multiTenantOptions = multiTenantOptionsAccesor.Options; siteRepo = siteRepository; }
/// <summary> /// Initializes a new <see cref="OAuthAuthenticationMiddleware"/>. /// </summary> /// <param name="next">The next middleware in the HTTP pipeline to invoke.</param> /// <param name="services"></param> /// <param name="dataProtectionProvider"></param> /// <param name="loggerFactory"></param> /// <param name="options">Configuration options for the middleware.</param> public OAuthAuthenticationMiddleware( RequestDelegate next, IServiceProvider services, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IOptions <ExternalAuthenticationOptions> externalOptions, IOptions <TOptions> options, ConfigureOptions <TOptions> configureOptions = null) : base(next, services, options, configureOptions) { // todo: review error handling if (string.IsNullOrWhiteSpace(Options.AuthenticationType)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "AuthenticationType")); } if (string.IsNullOrWhiteSpace(Options.ClientId)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "ClientId")); } if (string.IsNullOrWhiteSpace(Options.ClientSecret)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "ClientSecret")); } if (string.IsNullOrWhiteSpace(Options.AuthorizationEndpoint)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "AuthorizationEndpoint")); } if (string.IsNullOrWhiteSpace(Options.TokenEndpoint)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "TokenEndpoint")); } Logger = loggerFactory.Create(this.GetType().FullName); if (Options.StateDataFormat == null) { IDataProtector dataProtector = dataProtectionProvider.CreateDataProtector( this.GetType().FullName, Options.AuthenticationType, "v1"); Options.StateDataFormat = new PropertiesDataFormat(dataProtector); } Backchannel = new HttpClient(ResolveHttpMessageHandler(Options)); Backchannel.DefaultRequestHeaders.UserAgent.ParseAdd("Microsoft ASP.NET OAuth middleware"); Backchannel.Timeout = Options.BackchannelTimeout; Backchannel.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB if (string.IsNullOrEmpty(Options.SignInAsAuthenticationType)) { Options.SignInAsAuthenticationType = externalOptions.Options.SignInAsAuthenticationType; } if (string.IsNullOrEmpty(Options.SignInAsAuthenticationType)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, "SignInAsAuthenticationType")); } }
private ClientWebSocket ActivateWebSocket() { ClientWebSocket result = WebSocketFactory(); ConfigureOptions?.Invoke(result.Options); return(result); }
public static ContainerBuilder ConfigureBuilder(string componentName, CashOutSettings settings) { var builder = new ContainerBuilder(); IConfigureOptions <LoggerOptions> configureOptions = new ConfigureOptions <LoggerOptions>(x => { x.ConnectionString = settings.Logger.ConnectionString; x.ErrorTableName = settings.Logger.ErrorTableName; x.InfoTableName = settings.Logger.InfoTableName; x.WarningTableName = settings.Logger.WarningTableName; }); var loggerOptions = new OptionsManager <LoggerOptions>(new List <IConfigureOptions <LoggerOptions> > { configureOptions }); builder.Register(ctx => new SlackNotifier(new AzureQueueExt(settings.SlackQueue.ConnectionString, settings.SlackQueue.Name))).As <ISlackNotifier>().SingleInstance(); builder.Register(ctx => new TableLogger(ctx.Resolve <ISlackNotifier>(), loggerOptions, settings.VerboseLogging)).As <ILog>().SingleInstance(); builder.Register(ctx => new MonitoringRepository(new AzureTableStorage <MonitoringEntity>(settings.Monitoring.ConnectionString, settings.Monitoring.Name, ctx.Resolve <ILog>()))).As <IMonitoringRepository>().SingleInstance(); builder.RegisterType <JsonRpcRawResponseFormatter>().As <IJsonRpcRawResponseFormatter>().SingleInstance(); builder.RegisterType <JsonRpcRequestBuilder>().As <IJsonRpcRequestBuilder>().SingleInstance(); var rawRpcClientOptions = new ConfigureOptions <RpcWalletGeneratorOptions>(x => { x.Endpoint = settings.Rpc.Endpoint; x.Password = settings.Rpc.Password; x.Username = settings.Rpc.Username; }); builder.Register(ctx => new JsonRpcClientRaw(ctx.Resolve <IJsonRpcRequestBuilder>(), ctx.Resolve <ILog>(), new OptionsManager <RpcWalletGeneratorOptions>(new List <IConfigureOptions <RpcWalletGeneratorOptions> >() { rawRpcClientOptions }))).As <IJsonRpcClientRaw>().SingleInstance(); builder.Register(ctx => new JsonRpcClient(ctx.Resolve <IJsonRpcClientRaw>(), ctx.Resolve <IJsonRpcRawResponseFormatter>(), ctx.Resolve <ILog>())).As <IJsonRpcClient>().SingleInstance(); builder.Register(ctx => new CashOutQueueTrigger( componentName, ctx.Resolve <IJsonRpcClient>(), new AzureTableStorage <ExistingCashOutEntity>(settings.ExistingTxes.ConnectionString, settings.ExistingTxes.Name, ctx.Resolve <ILog>()), ctx.Resolve <ILog>(), ctx.Resolve <ISlackNotifier>() )).As <CashOutQueueTrigger>().SingleInstance(); builder.Register <CashOutMonitoringJob>(ctx => new CashOutMonitoringJob( componentName, ctx.Resolve <IMonitoringRepository>(), ctx.Resolve <ILog>() )).As <CashOutMonitoringJob>().SingleInstance(); builder.AddTriggers(pool => pool.AddDefaultConnection(settings.CashOutQueue.ConnectionString)); return(builder); }
protected override ConfigureOptions CreateConfigureOptions([NotNull] GlobalContext globalContext, [CanBeNull] string configureOptionsString, bool forceReload) { var localVars = new ValuesFrame(); var options = new ConfigureOptions(); ProjectionSet orderedProjections = null; _projector = null; Option.Parse(globalContext, configureOptionsString, MatcherStrategyOption.Action((args, j) => { string strategy = Option.ExtractRequiredOptionValue(args, ref j, "missing strategy"); switch (strategy) { case "S": _createProjector = (p, i) => new SimpleProjector(p, name: "default projector"); break; case "PT": _createProjector = (p, i) => new SelfOptimizingPrefixTrieProjector(p, i, 10000, name: "PT projector"); break; case "FL": _createProjector = (p, i) => new SelfOptimizingFirstLetterProjector(p, i, 10000, name: "FL projector"); break; default: Log.WriteWarning($"Unrecognized matcher optimization strategy {strategy} - using default"); break; } return(j); }), ProjectionFileOption.Action((args, j) => { string fullSourceName = Path.GetFullPath(Option.ExtractRequiredOptionValue(args, ref j, "missing projections filename")); orderedProjections = GetOrReadChildConfiguration(globalContext, () => new StreamReader(fullSourceName), fullSourceName, globalContext.IgnoreCase, "????", forceReload, localVars); return(j); }), ProjectionsOption.Action((args, j) => { orderedProjections = GetOrReadChildConfiguration(globalContext, () => new StringReader(string.Join(Environment.NewLine, args.Skip(j + 1))), ProjectionsOption.ShortName, globalContext.IgnoreCase, "????", forceReload: true, localVars: localVars); // ... and all args are read in, so the next arg index is past every argument. return(int.MaxValue); })); if (orderedProjections == null || !orderedProjections.AllProjections.Any()) { Log.WriteWarning("No projections defined"); _projector = new SimpleProjector(new Projection[0], name: "empty"); _allProjectionsForMatchCountLoggingOnly = new Projection[0]; } else { _projector = _createProjector(orderedProjections.AllProjections, globalContext.IgnoreCase); _allProjectionsForMatchCountLoggingOnly = orderedProjections.AllProjections; } return(options); }
//https://github.com/aspnet/Security/blob/dev/src/Microsoft.AspNet.Authentication/AuthenticationMiddleware.cs /// <summary> /// Initializes a new <see cref="OAuthAuthenticationMiddleware"/>. /// </summary> /// <param name="next">The next middleware in the HTTP pipeline to invoke.</param> /// <param name="dataProtectionProvider"></param> /// <param name="loggerFactory"></param> /// <param name="options">Configuration options for the middleware.</param> public MultiTenantOAuthAuthenticationMiddleware( RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IUrlEncoder encoder, ISiteResolver siteResolver, IOptions <MultiTenantOptions> multiTenantOptionsAccesor, IOptions <SharedAuthenticationOptions> sharedOptions, IOptions <TOptions> options, ConfigureOptions <TOptions> configureOptions = null) : base(next, options, loggerFactory, encoder, configureOptions) { //if (string.IsNullOrEmpty(Options.AuthenticationScheme)) //{ // throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(Options.AuthenticationScheme))); //} //if (string.IsNullOrEmpty(Options.ClientId)) //{ // throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(Options.ClientId))); //} //if (string.IsNullOrEmpty(Options.ClientSecret)) //{ // throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(Options.ClientSecret))); //} //if (string.IsNullOrEmpty(Options.AuthorizationEndpoint)) //{ // throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(Options.AuthorizationEndpoint))); //} //if (string.IsNullOrEmpty(Options.TokenEndpoint)) //{ // throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, nameof(Options.TokenEndpoint))); //} if (Options.StateDataFormat == null) { var dataProtector = dataProtectionProvider.CreateProtector( GetType().FullName, Options.AuthenticationScheme, "v1"); Options.StateDataFormat = new PropertiesDataFormat(dataProtector); } Backchannel = new HttpClient(ResolveHttpMessageHandler(Options)); Backchannel.DefaultRequestHeaders.UserAgent.ParseAdd("Microsoft ASP.NET OAuth middleware"); Backchannel.Timeout = Options.BackchannelTimeout; Backchannel.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB if (string.IsNullOrEmpty(Options.SignInScheme)) { Options.SignInScheme = sharedOptions.Options.SignInScheme; } this.loggerFactory = loggerFactory; this.siteResolver = siteResolver; multiTenantOptions = multiTenantOptionsAccesor.Options; }
public static IApplicationBuilder UseVkontakteAuthentication(this IApplicationBuilder app, Action<VkontakteAuthenticationOptions> configureOptions = null, string optionsName = "") { var options = new ConfigureOptions<VkontakteAuthenticationOptions>(configureOptions ?? (_ => { })) { Name = optionsName }; return app.UseMiddleware<VkontakteAuthenticationMiddleware>(options); }
public static IApplicationBuilder UseVkontakteAuthentication(this IApplicationBuilder app, Action <VkontakteAuthenticationOptions> configureOptions = null, string optionsName = "") { var options = new ConfigureOptions <VkontakteAuthenticationOptions>(configureOptions ?? (_ => { })) { Name = optionsName }; return(app.UseMiddleware <VkontakteAuthenticationMiddleware>(options)); }
/// <summary> /// Initializes a new <see cref="T:Microsoft.AspNet.Authentication.Google.GoogleAuthenticationMiddleware"/>. /// /// </summary> /// <param name="next">The next middleware in the HTTP pipeline to invoke.</param><param name="dataProtectionProvider"/><param name="loggerFactory"/><param name="encoder"/><param name="sharedOptions"/><param name="options">Configuration options for the middleware.</param><param name="configureOptions"/> public MyGoogleAuthenticationMiddleware(RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IUrlEncoder encoder, IOptions<SharedAuthenticationOptions> sharedOptions, IOptions<GoogleAuthenticationOptions> options, ConfigureOptions<GoogleAuthenticationOptions> configureOptions = null) : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options, configureOptions) { if (this.Options.Scope.Count != 0) return; this.Options.Scope.Add("openid"); this.Options.Scope.Add("profile"); this.Options.Scope.Add("email"); }
public SimpleBearerMiddleware( RequestDelegate next, IOptions <SimpleBearerOptions> options, ILoggerFactory loggerFactory, IUrlEncoder encoder, ConfigureOptions <SimpleBearerOptions> configureOptions = null ) : base(next, options, loggerFactory, encoder, configureOptions) { }
public MyAuthMiddleware( RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IUrlEncoder urlEncoder, IOptions <MyAuthOptions> options, ConfigureOptions <MyAuthOptions> configureOptions) : base(next, options, loggerFactory, urlEncoder, configureOptions) { }
public VkontakteAuthenticationMiddleware(RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IUrlEncoder encoder, IOptions <SharedAuthenticationOptions> externalOptions, IOptions <VkontakteAuthenticationOptions> options, ConfigureOptions <VkontakteAuthenticationOptions> configureOptions = null) : base(next, dataProtectionProvider, loggerFactory, encoder, externalOptions, options, configureOptions) { }
public InstagramAuthenticationMiddleware(RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IUrlEncoder encoder, IOptions <SharedAuthenticationOptions> sharedOptions, IOptions <InstagramAuthenticationOptions> options, ConfigureOptions <InstagramAuthenticationOptions> configureOptions = null) : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options, configureOptions) { }
public static IServiceCollection AddCmsWeb(this IServiceCollection services) { var optionsSetup = new ConfigureOptions <RazorViewEngineOptions>(options => { // TODO: Add providers for CMS as described here: https://github.com/aspnet/AspNetCore/issues/1490#issuecomment-221676623 }); services.AddSingleton <IConfigureOptions <RazorViewEngineOptions> >(optionsSetup); return(services); }
/// <summary> /// Bearer authentication component which is added to an HTTP pipeline. This constructor is not /// called by application code directly, instead it is added by calling the the IAppBuilder UseOAuthBearerAuthentication /// extension method. /// </summary> public OAuthBearerAuthenticationMiddleware( RequestDelegate next, IServiceProvider services, ILoggerFactory loggerFactory, IOptions <OAuthBearerAuthenticationOptions> options, ConfigureOptions <OAuthBearerAuthenticationOptions> configureOptions) : base(next, services, options, configureOptions) { _logger = loggerFactory.Create <OAuthBearerAuthenticationMiddleware>(); if (Options.Notifications == null) { Options.Notifications = new OAuthBearerAuthenticationNotifications(); } if (Options.SecurityTokenValidators == null) { Options.SecurityTokenValidators = new List <ISecurityTokenValidator> { new JwtSecurityTokenHandler() }; } if (string.IsNullOrWhiteSpace(Options.TokenValidationParameters.ValidAudience) && !string.IsNullOrWhiteSpace(Options.Audience)) { Options.TokenValidationParameters.ValidAudience = Options.Audience; } if (Options.ConfigurationManager == null) { if (Options.Configuration != null) { Options.ConfigurationManager = new StaticConfigurationManager <OpenIdConnectConfiguration>(Options.Configuration); } else if (!(string.IsNullOrWhiteSpace(Options.MetadataAddress) && string.IsNullOrWhiteSpace(Options.Authority))) { if (string.IsNullOrWhiteSpace(Options.MetadataAddress) && !string.IsNullOrWhiteSpace(Options.Authority)) { Options.MetadataAddress = Options.Authority; if (!Options.MetadataAddress.EndsWith("/", StringComparison.Ordinal)) { Options.MetadataAddress += "/"; } Options.MetadataAddress += ".well-known/openid-configuration"; } HttpClient httpClient = new HttpClient(ResolveHttpMessageHandler(Options)); httpClient.Timeout = Options.BackchannelTimeout; httpClient.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB Options.ConfigurationManager = new ConfigurationManager <OpenIdConnectConfiguration>(Options.MetadataAddress, httpClient); } } }
private SocketTransportFactory CreatSocketTransportFactory(ApplicationLifetime lifeTime, LoggerFactory loggerFactory) { var configureOptions = new ConfigureOptions <SocketTransportOptions>(transportOptions => transportOptions.IOQueueCount = _serverSettings.IOQueueCount); var optionsFactory = new OptionsFactory <SocketTransportOptions>(new[] { configureOptions }, new List <IPostConfigureOptions <SocketTransportOptions> >()); var optionsManager = new OptionsManager <SocketTransportOptions>(optionsFactory); var socketTransportFactory = new SocketTransportFactory(optionsManager, lifeTime, loggerFactory); return(socketTransportFactory); }
public ThrottleService( ILoggerFactory loggerFactory, IEnumerable <IRequirementHandler> handlers, IEnumerable <IExclusionHandler> exclusionHandlers, ISystemClock clock, IThrottleCounterStore store, IOptions <ThrottleOptions> options, ConfigureOptions <ThrottleOptions> configureOptions = null) { if (loggerFactory == null) { throw new ArgumentNullException(nameof(loggerFactory)); } if (handlers == null) { throw new ArgumentNullException(nameof(handlers)); } if (exclusionHandlers == null) { throw new ArgumentNullException(nameof(exclusionHandlers)); } if (clock == null) { throw new ArgumentNullException(nameof(clock)); } if (store == null) { throw new ArgumentNullException(nameof(store)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } _options = options.Value; if (configureOptions != null) { configureOptions.Configure(_options); } _options.BuildPolicies(); _handlers = handlers.ToArray(); _exclusionHandlers = exclusionHandlers.ToArray(); _logger = loggerFactory.CreateLogger <ThrottleService>(); _clock = clock; _store = store; }
/// <summary> /// Initializes a new <see cref="T:Microsoft.AspNet.Authentication.Facebook.FacebookAuthenticationMiddleware"/>. /// /// </summary> /// <param name="next">The next middleware in the HTTP pipeline to invoke.</param><param name="dataProtectionProvider"/><param name="loggerFactory"/><param name="encoder"/><param name="sharedOptions"/><param name="options">Configuration options for the middleware.</param><param name="configureOptions"/> public MyFacebookAuthenticationMiddleware(RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IUrlEncoder encoder, IOptions<SharedAuthenticationOptions> sharedOptions, IOptions<FacebookAuthenticationOptions> options, ConfigureOptions<FacebookAuthenticationOptions> configureOptions = null) : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options, configureOptions) { if (string.IsNullOrEmpty(this.Options.AppId)) throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, new object[1] { (object) "AppId" })); if (string.IsNullOrEmpty(this.Options.AppSecret)) throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Exception_OptionMustBeProvided, new object[1] { (object) "AppSecret" })); }
public ClaimsTransformationMiddleware( [NotNull] RequestDelegate next, [NotNull] IOptions<ClaimsTransformationOptions> options, ConfigureOptions<ClaimsTransformationOptions> configureOptions) { if (configureOptions != null) { Options = options.GetNamedOptions(configureOptions.Name); configureOptions.Configure(Options, configureOptions.Name); } else { Options = options.Options; } _next = next; }
public OpenIdConnectAuthenticationMiddlewareForTestingAuthenticate( RequestDelegate next, IDataProtectionProvider dataProtectionProvider, ILoggerFactory loggerFactory, IUrlEncoder encoder, IServiceProvider services, IOptions<SharedAuthenticationOptions> sharedOptions, IOptions<OpenIdConnectAuthenticationOptions> options, ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions = null, OpenIdConnectAuthenticationHandler handler = null ) : base(next, dataProtectionProvider, loggerFactory, encoder, services, sharedOptions, options, configureOptions) { _handler = handler; var customFactory = loggerFactory as InMemoryLoggerFactory; if (customFactory != null) Logger = customFactory.Logger; }
public ConfigureResult[] Configure(ConfigureOptions Options, string Action, [System.Xml.Serialization.XmlArrayItemAttribute("Configuration", IsNullable=false)] APIObject[] Configurations, out string OverallStatus, out string OverallStatusMessage, out string RequestID) { object[] results = this.Invoke("Configure", new object[] { Options, Action, Configurations}); OverallStatus = ((string)(results[1])); OverallStatusMessage = ((string)(results[2])); RequestID = ((string)(results[3])); return ((ConfigureResult[])(results[0])); }
/// <remarks/> public void ConfigureAsync(ConfigureOptions Options, string Action, APIObject[] Configurations) { this.ConfigureAsync(Options, Action, Configurations, null); }
/// <remarks/> public void ConfigureAsync(ConfigureOptions Options, string Action, APIObject[] Configurations, object userState) { if ((this.ConfigureOperationCompleted == null)) { this.ConfigureOperationCompleted = new System.Threading.SendOrPostCallback(this.OnConfigureOperationCompleted); } this.InvokeAsync("Configure", new object[] { Options, Action, Configurations}, this.ConfigureOperationCompleted, userState); }
private static TestServer CreateServer(ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions, IUrlEncoder encoder, ILoggerFactory loggerFactory, OpenIdConnectAuthenticationHandler handler = null) { return TestServer.Create( app => { app.UseMiddleware<OpenIdConnectAuthenticationMiddlewareForTestingAuthenticate>(configureOptions, encoder, loggerFactory, handler); app.Use(async (context, next) => { await next(); }); }, services => { services.AddWebEncoders(); services.AddDataProtection(); } ); }