Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HtmlHelper{TModel}"/> class.
 /// </summary>
 public HtmlHelper(
     IHtmlGenerator htmlGenerator,
     ICompositeViewEngine viewEngine,
     IModelMetadataProvider metadataProvider,
     IHtmlEncoder htmlEncoder,
     IUrlEncoder urlEncoder,
     IJavaScriptStringEncoder javaScriptStringEncoder)
     : base(htmlGenerator, viewEngine, metadataProvider, htmlEncoder, urlEncoder, javaScriptStringEncoder)
 {
     if (htmlGenerator == null)
     {
         throw new ArgumentNullException(nameof(htmlGenerator));
     }
     if (viewEngine == null)
     {
         throw new ArgumentNullException(nameof(viewEngine));
     }
     if (metadataProvider == null)
     {
         throw new ArgumentNullException(nameof(metadataProvider));
     }
     if (htmlEncoder == null)
     {
         throw new ArgumentNullException(nameof(htmlEncoder));
     }
     if (urlEncoder == null)
     {
         throw new ArgumentNullException(nameof(urlEncoder));
     }
     if (javaScriptStringEncoder == null)
     {
         throw new ArgumentNullException(nameof(javaScriptStringEncoder));
     }
 }
        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;
        }
        /// <summary>
        /// Initializes a new <see cref="GoogleAuthenticationMiddleware"/>.
        /// </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 MultiTenantGoogleMiddleware(
            RequestDelegate next,
            IDataProtectionProvider dataProtectionProvider,
            ILoggerFactory loggerFactory,
            ISiteResolver siteResolver,
            ISiteRepository siteRepository,
            IOptions <MultiTenantOptions> multiTenantOptionsAccesor,
            IUrlEncoder encoder,
            IOptions <SharedAuthenticationOptions> sharedOptions,
            GoogleOptions options)
            : base(
                next,
                dataProtectionProvider,
                loggerFactory,
                encoder,
                siteResolver,
                multiTenantOptionsAccesor,
                sharedOptions,
                options)
        {
            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");
            }

            this.loggerFactory = loggerFactory;
            this.siteResolver  = siteResolver;
            multiTenantOptions = multiTenantOptionsAccesor.Value;
            siteRepo           = siteRepository;
        }
 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);
     }
 }
        /// <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 MultiTenantMicrosoftAccountMiddleware(
            RequestDelegate next,
            IDataProtectionProvider dataProtectionProvider,
            ILoggerFactory loggerFactory,
            ISiteResolver siteResolver,
            ISiteRepository siteRepository,
            IOptions <MultiTenantOptions> multiTenantOptionsAccesor,
            IUrlEncoder encoder,
            IOptions <SharedAuthenticationOptions> sharedOptions,
            MicrosoftAccountOptions options)
            : base(
                next,
                dataProtectionProvider,
                loggerFactory,
                encoder,
                siteResolver,
                multiTenantOptionsAccesor,
                sharedOptions,
                options)
        {
            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.Value;
            siteRepo           = siteRepository;
        }
 public DeveloperSecurityMiddleware(
     RequestDelegate next,
     DeveloperAuthenticationOptions options,
     ILoggerFactory loggerFactory,
     IUrlEncoder encoder) : base(next, options, loggerFactory, encoder)
 {
 }
        //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 MultiTenantOAuthMiddleware(
            RequestDelegate next,
            IDataProtectionProvider dataProtectionProvider,
            IHttpContextAccessor contextAccessor,
            ILoggerFactory loggerFactory,
            IUrlEncoder encoder,
            //ISiteResolver siteResolver,
            ITenantResolver <SiteSettings> siteResolver,
            IOptions <MultiTenantOptions> multiTenantOptionsAccesor,
            IOptions <SharedAuthenticationOptions> sharedOptions,
            TOptions options)
            : base(next, options, loggerFactory, encoder)
        {
            //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 = new HttpClient(Options.BackchannelHttpHandler ?? new HttpClientHandler());
            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.Value.SignInScheme;
            }
            this.contextAccessor = contextAccessor;
            this.loggerFactory   = loggerFactory;
            this.siteResolver    = siteResolver;
            multiTenantOptions   = multiTenantOptionsAccesor.Value;
        }
Beispiel #8
0
        /// <summary>
        /// Initializes a new <see cref="SharePointAuthenticationMiddleware"/>.
        /// </summary>
        /// <param name="next">The next middleware in the HTTP pipeline to invoke.</param>
        /// <param name="loggerFactory"></param>
        /// <param name="encoder"></param>
        /// <param name="options">Configuration options for the middleware.</param>
        public SharePointAuthenticationMiddleware(
            RequestDelegate nextMiddleware,
            ILoggerFactory loggerFactory,
            IUrlEncoder encoder,
            SharePointAuthenticationOptions options)
            : base(nextMiddleware, options, loggerFactory, encoder)
        {
            if (nextMiddleware == null)
            {
                throw new ArgumentNullException(nameof(nextMiddleware));
            }
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }
            if (encoder == null)
            {
                throw new ArgumentNullException(nameof(encoder));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _nextMiddleware = nextMiddleware;
        }
 public MultiTenantFacebookMiddleware(
     RequestDelegate next,
     IDataProtectionProvider dataProtectionProvider,
     ILoggerFactory loggerFactory,
     ISiteResolver siteResolver,
     ISiteRepository siteRepository,
     IOptions <MultiTenantOptions> multiTenantOptionsAccesor,
     IUrlEncoder encoder,
     IOptions <SharedAuthenticationOptions> sharedOptions,
     FacebookOptions options)
     : base(next,
            dataProtectionProvider,
            loggerFactory,
            encoder,
            siteResolver,
            multiTenantOptionsAccesor,
            sharedOptions,
            options)
 {
     //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.Value;
     siteRepo           = siteRepository;
 }
Beispiel #10
0
        /// <summary>
        /// Initializes a new <see cref="YoukuMiddleware" />.
        /// </summary>
        /// <param name="next">The next middleware in the application 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>
        public YoukuMiddleware(
            RequestDelegate next,
            IDataProtectionProvider dataProtectionProvider,
            ILoggerFactory loggerFactory,
            IUrlEncoder encoder,
            IOptions <SharedAuthenticationOptions> sharedOptions,
            YoukuOptions options)
            : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            if (dataProtectionProvider == null)
            {
                throw new ArgumentNullException(nameof(dataProtectionProvider));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (encoder == null)
            {
                throw new ArgumentNullException(nameof(encoder));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
        }
        /// <summary>
        /// Creates a new instance of the ActiveDirectoryMiddleware.
        /// </summary>
        /// <param name="next">The next middleware in the pipeline.</param>
        /// <param name="options">The Active Directory configuration options.</param>
        /// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
        public ActiveDirectoryMiddleware(
            RequestDelegate next,
            ActiveDirectoryOptions options,
            ILoggerFactory loggerFactory,
            IUrlEncoder encoder)
            : base(next, options, loggerFactory, encoder)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            if (encoder == null)
            {
                throw new ArgumentNullException(nameof(encoder));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            _next   = next;
            _logger = loggerFactory.CreateLogger <ActiveDirectoryMiddleware>();
        }
        /// <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;
        }
Beispiel #13
0
 public BearerAuthenticationMiddleware(
     RequestDelegate next,
     ILoggerFactory loggerFactory,
     IUrlEncoder encoder,
     BearerOption options)
     : base(next, options, loggerFactory, encoder)
 {
 }
 public SimpleBearerMiddleware(
     RequestDelegate next,
     ILoggerFactory loggerFactory,
     IUrlEncoder encoder,
     SimpleBearerOptions options)
     : base(next, options, loggerFactory, encoder)
 {
 }
Beispiel #15
0
 public ChunkingCookieManager(IUrlEncoder urlEncoder)
 {
     // Lowest common denominator. Safari has the lowest known limit (4093), and we leave little extra just in case.
     // See http://browsercookielimits.x64.me/.
     ChunkSize = 4090;
     ThrowForPartialCookies = true;
     Encoder = urlEncoder ?? UrlEncoder.Default;
 }
 public SitemapHandler(IGetStandards getStandards, IGetFrameworks getFrameworks, IGetProviderDetails getProviders, IUrlEncoder urlEncoder, IXmlDocumentSerialiser documentSerialiser)
 {
     _getStandards          = getStandards;
     _getFrameworks         = getFrameworks;
     _getProviders          = getProviders;
     _urlEncoder            = urlEncoder;
     _xmlDocumentSerialiser = documentSerialiser;
 }
 public ChunkingCookieManager(IUrlEncoder urlEncoder)
 {
     // Lowest common denominator. Safari has the lowest known limit (4093), and we leave little extra just in case.
     // See http://browsercookielimits.x64.me/.
     ChunkSize = 4090;
     ThrowForPartialCookies = true;
     Encoder = urlEncoder ?? UrlEncoder.Default;
 }
 /// <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");
 }
Beispiel #19
0
        /// <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 OAuthMiddleware(
            [NotNull] RequestDelegate next,
            [NotNull] IDataProtectionProvider dataProtectionProvider,
            [NotNull] ILoggerFactory loggerFactory,
            [NotNull] IUrlEncoder encoder,
            [NotNull] IOptions <SharedAuthenticationOptions> sharedOptions,
            [NotNull] TOptions options)
            : base(next, options, loggerFactory, encoder)
        {
            // todo: review error handling
            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.Events == null)
            {
                Options.Events = new OAuthEvents();
            }

            if (Options.StateDataFormat == null)
            {
                var dataProtector = dataProtectionProvider.CreateProtector(
                    GetType().FullName, Options.AuthenticationScheme, "v1");
                Options.StateDataFormat = new PropertiesDataFormat(dataProtector);
            }

            Backchannel = new HttpClient(Options.BackchannelHttpHandler ?? new HttpClientHandler());
            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.Value.SignInScheme;
            }
        }
Beispiel #20
0
        public static void Run(IUrlEncoder urlEncoder, IUpdater updater)
        {
            using (var mwvm = new MainWindowViewModel(urlEncoder, updater))
            {
                var app = BuildAvaloniaApp();

                app.BeforeStarting(x => mwvm.AsyncStart());
                app.Start <MainWindow>(() => mwvm);
            }
        }
Beispiel #21
0
 public SimpleBearerMiddleware(
     RequestDelegate next,
     IOptions <SimpleBearerOptions> options,
     ILoggerFactory loggerFactory,
     IUrlEncoder encoder,
     ConfigureOptions <SimpleBearerOptions> configureOptions = null
     )
     : base(next, options, loggerFactory, encoder, configureOptions)
 {
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="WebAssetItemMerger"/> class.
        /// </summary>
        /// <param name="assetRegistry">The asset registry.</param>
        /// <param name="urlResolver">The URL resolver.</param>
        /// <param name="urlEncoder">The URL encoder.</param>
        public WebAssetItemMerger(IWebAssetRegistry assetRegistry, IUrlResolver urlResolver, IUrlEncoder urlEncoder)
        {
            Guard.IsNotNull(assetRegistry, "assetRegistry");
            Guard.IsNotNull(urlResolver, "urlResolver");
            Guard.IsNotNull(urlEncoder, "urlEncoder");

            this.assetRegistry = assetRegistry;
            this.urlResolver = urlResolver;
            this.urlEncoder = urlEncoder;
        }
 public AzureADMiddleware(
     RequestDelegate next,
     IDataProtectionProvider dataProtectionProvider,
     ILoggerFactory loggerFactory,
     IUrlEncoder encoder,
     IOptions <SharedAuthenticationOptions> sharedOptions,
     AzureADOptions options)
     : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options)
 {
 }
 public MyAuthMiddleware(
     RequestDelegate next,
     IDataProtectionProvider dataProtectionProvider,
     ILoggerFactory loggerFactory,
     IUrlEncoder urlEncoder,
     IOptions <MyAuthOptions> options,
     ConfigureOptions <MyAuthOptions> configureOptions)
     : base(next, options, loggerFactory, urlEncoder, configureOptions)
 {
 }
 public AuthorizeBasicMiddleware(
     RequestDelegate next,
     IOptions <BasicOptions> options,
     ILoggerFactory loggerFactory,
     IUrlEncoder encoder,
     string authScheme) :
     base(next, options, loggerFactory, encoder,
          new ConfigureOptions <BasicOptions>(o => o.AuthenticationScheme = authScheme) { Name = authScheme })
 {
 }
Beispiel #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HtmlHelper{TModel}"/> class.
 /// </summary>
 public HtmlHelper(
     [NotNull] IHtmlGenerator htmlGenerator,
     [NotNull] ICompositeViewEngine viewEngine,
     [NotNull] IModelMetadataProvider metadataProvider,
     [NotNull] IHtmlEncoder htmlEncoder,
     [NotNull] IUrlEncoder urlEncoder,
     [NotNull] IJavaScriptStringEncoder javaScriptStringEncoder)
     : base(htmlGenerator, viewEngine, metadataProvider, htmlEncoder, urlEncoder, javaScriptStringEncoder)
 {
 }
 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 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 ImgurAuthenticationMiddleware(
     [NotNull] RequestDelegate next,
     [NotNull] ImgurAuthenticationOptions options,
     [NotNull] IDataProtectionProvider dataProtectionProvider,
     [NotNull] ILoggerFactory loggerFactory,
     [NotNull] IUrlEncoder encoder,
     [NotNull] IOptions <SharedAuthenticationOptions> externalOptions)
     : base(next, dataProtectionProvider, loggerFactory, encoder, externalOptions, options)
 {
 }
Beispiel #30
0
 public UserService(ILogger <UserService> logger, ISignInManager <User> signInManager, IUserManager <User> userManager, IOptions <AppSettings> appSettings,
                    IInvitationTokenRepository invitationTokenRepository, IEmailSender emailSender, IUrlEncoder urlEncoder)
 {
     _logger      = logger;
     _userManager = userManager;
     _invitationTokenRepository = invitationTokenRepository;
     _emailSender   = emailSender;
     _urlEncoder    = urlEncoder;
     _signInManager = signInManager;
     _appSettings   = appSettings.Value;
 }
 public TwitterClient(
     ITwitterApiConfiguration configuration,
     IUrlEncoder urlEncoder,
     IHtmlLinkParser htmlLinkParser,
     ITwitterHashtagParser hashtagParser)
 {
     _configuration = configuration;
     _urlEncoder = urlEncoder;
     _htmlLinkParser = htmlLinkParser;
     _hashtagParser = hashtagParser;
 }
        /// <summary>
        /// Converts a dictionary object to a query string representation such as:
        /// firstname=shannon&lastname=deminick
        /// </summary>
        /// <param name="d"></param>
        /// <param name="urlEncoder"></param>
        /// <returns></returns>
        public static string ToQueryString(this IDictionary<string, object> d, IUrlEncoder urlEncoder)
        {
            if (!d.Any()) return "";

            var builder = new StringBuilder();
            foreach (var i in d)
            {
                builder.Append($"{urlEncoder.UrlEncode(i.Key)}={(i.Value == null ? string.Empty : urlEncoder.UrlEncode(i.Value.ToString()))}&");
            }
            return builder.ToString().TrimEnd('&');
        }
        /// <summary>
        /// URL-encodes a string and writes the result to the supplied output.
        /// </summary>
        /// <remarks>
        /// The encoded value is safe for use in the segment, query, or
        /// fragment portion of a URI.
        /// </remarks>
        public static void UrlEncode(this IUrlEncoder urlEncoder, string value, TextWriter output)
        {
            if (urlEncoder == null)
            {
                throw new ArgumentNullException(nameof(urlEncoder));
            }

            if (!String.IsNullOrEmpty(value))
            {
                urlEncoder.UrlEncode(value, 0, value.Length, output);
            }
        }
Beispiel #34
0
        /// <summary>
        /// This is used in methods like BeginUmbracoForm and SurfaceAction to generate an encrypted string which gets submitted in a request for which
        /// Umbraco can decrypt during the routing process in order to delegate the request to a specific MVC Controller.
        /// </summary>
        /// <param name="urlEncoder"></param>
        /// <param name="controllerName"></param>
        /// <param name="controllerAction"></param>
        /// <param name="area"></param>
        /// <param name="additionalRouteVals"></param>
        /// <returns></returns>
        public string CreateEncryptedRouteString(IUrlEncoder urlEncoder, string controllerName, string controllerAction, string area, object additionalRouteVals = null)
        {
            //need to create a params string as Base64 to put into our hidden field to use during the routes
            var surfaceRouteParams = $"{ReservedAdditionalKeys.Controller}={urlEncoder.UrlEncode(controllerName)}&{ReservedAdditionalKeys.Action}={urlEncoder.UrlEncode(controllerAction)}&{ReservedAdditionalKeys.Area}={area}";

            var additionalRouteValsAsQuery = additionalRouteVals?.ToDictionary<object>().ToQueryString(urlEncoder);

            if (string.IsNullOrWhiteSpace(additionalRouteValsAsQuery) == false)
                surfaceRouteParams += "&" + additionalRouteValsAsQuery;

            return Convert.ToBase64String(_dataProtector.Protect(Encoding.UTF8.GetBytes(surfaceRouteParams)));
        }
Beispiel #35
0
        public OAuthAuthorizationServerMiddleware(
            RequestDelegate next,
            OAuthAuthorizationServerOptions options,
            ILoggerFactory logger,
            IUrlEncoder encoder,
            IDataProtectionProvider dataProtectionProvider
            ) : base(next, options, logger, encoder)
        {
            if (dataProtectionProvider == null)
            {
                throw new ArgumentNullException(nameof(dataProtectionProvider));
            }

            if (Options.Provider == null)
            {
                Options.Provider = new OAuthAuthorizationServerProvider();
            }

            if (Options.AccessTokenFormat == null)
            {
                Options.AccessTokenFormat = new TicketDataFormat(dataProtectionProvider.CreateProtector("Access_Token"));
            }
            if (Options.RefreshTokenFormat == null)
            {
                Options.RefreshTokenFormat = new TicketDataFormat(dataProtectionProvider.CreateProtector("Refresh_Token"));
            }
            if (Options.AuthorizationCodeFormat == null)
            {
                Options.AuthorizationCodeFormat = new TicketDataFormat(dataProtectionProvider.CreateProtector("Auth_Code"));
            }
            if (Options.AuthorizeEndpointPath == null)
            {
                Options.AuthorizeEndpointPath = new PathString("/Authorize");
            }
            if (Options.TokenEndpointPath == null)
            {
                Options.AuthorizeEndpointPath = new PathString("/Token");
            }

            if (Options.AuthorizationCodeProvider == null)
            {
                Options.AuthorizationCodeProvider = new AuthenticationTokenProvider();
            }
            if (Options.AccessTokenProvider == null)
            {
                Options.AccessTokenProvider = new AuthenticationTokenProvider();
            }
            if (Options.RefreshTokenProvider == null)
            {
                Options.RefreshTokenProvider = new AuthenticationTokenProvider();
            }
        }
        /// <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(
            [NotNull] RequestDelegate next,
            [NotNull] ILoggerFactory loggerFactory,
            [NotNull] IUrlEncoder encoder,
            [NotNull] IOptions <OAuthBearerAuthenticationOptions> options,
            ConfigureOptions <OAuthBearerAuthenticationOptions> configureOptions)
            : base(next, options, loggerFactory, encoder, configureOptions)
        {
            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";
                    }

                    var httpClient = new HttpClient(ResolveHttpMessageHandler(Options));
                    httpClient.Timeout = Options.BackchannelTimeout;
                    httpClient.MaxResponseContentBufferSize = 1024 * 1024 * 10; // 10 MB

                    Options.ConfigurationManager = new ConfigurationManager <OpenIdConnectConfiguration>(Options.MetadataAddress, httpClient);
                }
            }
        }
 /// <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 OpenIdConnectMiddlewareForTestingAuthenticate(
     RequestDelegate next,
     IDataProtectionProvider dataProtectionProvider,
     ILoggerFactory loggerFactory,
     IUrlEncoder encoder,
     IServiceProvider services,
     IOptions<SharedAuthenticationOptions> sharedOptions,
     OpenIdConnectOptions options,
     IHtmlEncoder htmlEncoder,
     OpenIdConnectHandler handler = null
     )
 : base(next, dataProtectionProvider, loggerFactory, encoder, services, sharedOptions, options, htmlEncoder)
 {
     _handler = handler;
 }
        //TODO: Need to implement something similar
        /// <summary>
        /// This is used in methods like BeginUmbracoForm and SurfaceAction to generate an encrypted string which gets submitted in a request for which
        /// Umbraco can decrypt during the routing process in order to delegate the request to a specific MVC Controller.
        /// </summary>
        /// <param name="urlEncoder"></param>
        /// <param name="controllerName"></param>
        /// <param name="controllerAction"></param>
        /// <param name="area"></param>
        /// <param name="additionalRouteVals"></param>
        /// <returns></returns>
        internal static string CreateEncryptedRouteString(IUrlEncoder urlEncoder, string controllerName, string controllerAction, string area, object additionalRouteVals = null)
        {
            //need to create a params string as Base64 to put into our hidden field to use during the routes
            var surfaceRouteParams = $"c={urlEncoder.UrlEncode(controllerName)}&a={urlEncoder.UrlEncode(controllerAction)}&ar={area}";

            var additionalRouteValsAsQuery = additionalRouteVals ?. ToDictionary<object>().ToQueryString(urlEncoder);

            if (string.IsNullOrWhiteSpace(additionalRouteValsAsQuery) == false)
                surfaceRouteParams += "&" + additionalRouteValsAsQuery;

            //TODO: We need to encrypt! for now we'll base64 :(
            //return surfaceRouteParams.EncryptWithMachineKey();

            return Convert.ToBase64String(Encoding.UTF8.GetBytes(surfaceRouteParams));
        }
 public OpenIdConnectMiddlewareForTestingAuthenticate(
     RequestDelegate next,            
     IDataProtectionProvider dataProtectionProvider,
     ILoggerFactory loggerFactory,
     IUrlEncoder encoder,
     IServiceProvider services,
     IOptions<SharedAuthenticationOptions> sharedOptions,
     OpenIdConnectOptions options,
     OpenIdConnectHandler handler = null
     )
 : base(next, dataProtectionProvider, loggerFactory, encoder, services, sharedOptions, options)
 {
     _handler = handler;
     var customFactory = loggerFactory as InMemoryLoggerFactory;
     if (customFactory != null)
         Logger = customFactory.Logger;
 }
 public OpenIdConnectAuthenticationMiddlewareForTestingAuthenticate(
     RequestDelegate next,            
     IDataProtectionProvider dataProtectionProvider,
     ILoggerFactory loggerFactory,
     IUrlEncoder encoder,
     IServiceProvider services,
     IOptions<ExternalAuthenticationOptions> externalOptions,
     IOptions<OpenIdConnectAuthenticationOptions> options,
     ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions = null,
     OpenIdConnectAuthenticationHandler handler = null
     )
 : base(next, dataProtectionProvider, loggerFactory, encoder, services, externalOptions, options, configureOptions)
 {
     _handler = handler;
     var customFactory = loggerFactory as InMemoryLoggerFactory;
     if (customFactory != null)
         Logger = customFactory.Logger;
 }
Beispiel #42
0
 public AwsQuerySigner(HashAlgorithm hashAlgorithm, IUrlEncoder urlEncoder)
 {
     _hashAlgorithm = hashAlgorithm;
     _urlEncoder = urlEncoder;
 }
 public QueryStringNameValueCollection(NameValueCollection coll, IUrlEncoder urlEncoder)
     : base(coll)
 {
     _urlEncoder = urlEncoder;
 }
 public ViewModelFactory(IAppConfig appConfig, IUrlGenerator urlGenerator, IUrlEncoder urlEncoder)
 {
     _appConfig = appConfig;
     _urlGenerator = urlGenerator;
     _urlEncoder = urlEncoder;
 }
 private static TestServer CreateServer(Action<OpenIdConnectOptions> configureOptions, IUrlEncoder encoder, OpenIdConnectHandler handler = null)
 {
     return TestServer.Create(
         app =>
         {
             var options = new OpenIdConnectOptions();
             configureOptions(options);
             app.UseMiddleware<OpenIdConnectMiddlewareForTestingAuthenticate>(options, encoder, handler);
             app.Use(async (context, next) =>
             {
                 await next();
             });
         },
         services =>
         {
             services.AddWebEncoders();
             services.AddDataProtection();
         }
     );
 }
 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();
         }
     );
 }
 /// <summary>
 /// Creates an UmbracoForm
 /// </summary>
 /// <param name="urlEncoder"></param>
 /// <param name="viewContext"></param>
 /// <param name="controllerName"></param>
 /// <param name="controllerAction"></param>
 /// <param name="area"></param>
 /// <param name="method"></param>
 /// <param name="additionalRouteVals"></param>
 public UmbracoForm(
     IUrlEncoder urlEncoder,
     ViewContext viewContext,
     string controllerName,
     string controllerAction,
     string area,
     FormMethod method,
     object additionalRouteVals = null)
     : base(viewContext)
 {
     _viewContext = viewContext;
     _method = method;
     _encryptedString = CreateEncryptedRouteString(urlEncoder, controllerName, controllerAction, area, additionalRouteVals);
 }
Beispiel #48
0
 public static NameValueCollection ParseQueryString(string query, IUrlEncoder urlEncoder)
 {
     var coll = System.Web.HttpUtility.ParseQueryString(query);
     return new QueryStringNameValueCollection(coll, urlEncoder);
 }
 /// <summary>
 /// Creates an UmbracoForm
 /// </summary>
 /// <param name="urlEncoder"></param>
 /// <param name="viewContext"></param>
 /// <param name="controllerName"></param>
 /// <param name="controllerAction"></param>
 /// <param name="area"></param>
 /// <param name="additionalRouteVals"></param>
 public UmbracoForm(
     IUrlEncoder urlEncoder,
     ViewContext viewContext,
     string controllerName,
     string controllerAction,
     string area,
     object additionalRouteVals = null)
     : base(viewContext)
 {
     _viewContext = viewContext;
     var surfaceFormHelper = viewContext.HttpContext.ApplicationServices.GetRequiredService<SurfaceFormHelper>();
     _encryptedString = surfaceFormHelper.CreateEncryptedRouteString(urlEncoder, controllerName, controllerAction, area, additionalRouteVals);
 }
Beispiel #50
0
 public EncodedQueryBuilder(IUrlEncoder urlEncoder)
 {
     _urlEncoder = urlEncoder;
 }