Пример #1
0
        /// <summary>
        /// Authenticate users using an OpenID provider
        /// </summary>
        /// <param name="app">The <see cref="IAppBuilder"/> passed to the configuration method</param>
        /// <param name="options">Middleware configuration options</param>
        /// <returns>The updated <see cref="IAppBuilder"/></returns>
        public static IAppBuilder UseOpenIDAuthentication(this IAppBuilder app, OpenIDAuthenticationOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            app.Use(typeof(OpenIDAuthenticationMiddleware), app, options);
            return(app);
        }
        /// <summary>
        /// Authenticate users using an OpenID provider
        /// </summary>
        /// <param name="app">The <see cref="IAppBuilder"/> passed to the configuration method</param>
        /// <param name="options">Middleware configuration options</param>
        /// <returns>The updated <see cref="IAppBuilder"/></returns>
        public static IAppBuilder UseOpenIDAuthentication(this IAppBuilder app, OpenIDAuthenticationOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException("app");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            app.Use(typeof(OpenIDAuthenticationMiddleware), app, options);
            return app;
        }
        private static HttpMessageHandler ResolveHttpMessageHandler(OpenIDAuthenticationOptions options)
        {
            HttpMessageHandler handler = options.BackchannelHttpHandler ?? new WebRequestHandler();

            // If they provided a validator, apply it or fail.
            if (options.BackchannelCertificateValidator != null)
            {
                // Set the cert validate callback
                var webRequestHandler = handler as WebRequestHandler;
                if (webRequestHandler == null)
                {
                    throw new InvalidOperationException(Resources.Exception_ValidatorHandlerMismatch);
                }
                webRequestHandler.ServerCertificateValidationCallback = options.BackchannelCertificateValidator.Validate;
            }

            return(handler);
        }
Пример #4
0
        /// <summary>
        /// Authenticate users using an OpenID provider
        /// </summary>
        /// <param name="app">The <see cref="IAppBuilder"/> passed to the configuration method</param>
        /// <param name="providerUri">The uri of the OpenID provider</param>
        /// <param name="providerName">Name of the OpenID provider</param>
        /// <param name="uriIsProviderLoginUri">True if the specified uri is the provider login uri and not the provider discovery uri</param>
        /// <returns>The updated <see cref="IAppBuilder"/></returns>
        public static IAppBuilder UseOpenIDAuthentication(this IAppBuilder app, string providerUri, string providerName, bool uriIsProviderLoginUri)
        {
            var authOptions = new OpenIDAuthenticationOptions
            {
                Caption            = providerName,
                AuthenticationType = providerName,
                CallbackPath       = new PathString("/signin-openid" + providerName.ToLowerInvariant())
            };

            if (uriIsProviderLoginUri)
            {
                authOptions.ProviderLoginUri = providerUri;
            }
            else
            {
                authOptions.ProviderDiscoveryUri = providerUri;
            }
            return(UseOpenIDAuthentication(app, authOptions));
        }
        /// <summary>
        /// Authenticate users using an OpenID provider
        /// </summary>
        /// <param name="app">The <see cref="IAppBuilder"/> passed to the configuration method</param>
        /// <param name="providerUri">The uri of the OpenID provider</param>
        /// <param name="providerName">Name of the OpenID provider</param>
        /// <param name="uriIsProviderLoginUri">True if the specified uri is the provider login uri and not the provider discovery uri</param>
        /// <returns>The updated <see cref="IAppBuilder"/></returns>
        public static IAppBuilder UseOpenIDAuthentication(this IAppBuilder app, string providerUri, string providerName, bool uriIsProviderLoginUri)
        {
            var authOptions = new OpenIDAuthenticationOptions
            {
                Caption = providerName,
                AuthenticationType = providerName,
                CallbackPath = new PathString("/signin-openid" + providerName.ToLowerInvariant())
            };
            if (uriIsProviderLoginUri)
            {
                authOptions.ProviderLoginUri = providerUri;
            }
            else
            {

                authOptions.ProviderDiscoveryUri = providerUri;
            }
            return UseOpenIDAuthentication(app, authOptions);
        }