示例#1
0
 /// <summary>
 /// Enables digest authentication
 /// </summary>
 /// <param name="builder">The <see cref="AuthenticationBuilder"/></param>
 /// <param name="config">Mandatory configuration for Digest Authentication</param>
 /// <param name="authenticationScheme">The authentication scheme.</param>
 /// <param name="displayName">The display name for the authentication handler.</param>
 /// <returns>A reference to builder after the operation has completed.</returns>
 public static AuthenticationBuilder AddDigestAuthentication(this AuthenticationBuilder builder,
                                                             DigestAuthenticationConfiguration config,
                                                             string authenticationScheme,
                                                             string displayName)
 {
     return(builder.AddScheme <DigestAuthenticationOptions, DigestAuthenticationHandler>(authenticationScheme,
                                                                                         displayName,
                                                                                         options => { options.Configuration = config; }));
 }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            BasicAuthCredentialValidator  basicValidator  = new BasicAuthCredentialValidator("farnsworth", "GoodNewsEveryone!");
            DigestAuthCredentialValidator digestValidator = new DigestAuthCredentialValidator("leela", "Nibbler");

            services.AddAuthentication(BasicAuthenticationDefaults.AuthenticationScheme).AddBasicAuthentication("Basic", (options) => { options.Realm = "Basic Auth Realm"; }, basicValidator.ValidateCredentials);
            services.AddAuthentication("Digest").AddDigestAuthentication(DigestAuthenticationConfiguration.Create(digestValidator.ServerNonce, "Digest Auth Realm"), digestValidator);
            services.AddAuthentication(HttpSysDefaults.AuthenticationScheme);
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
示例#3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Example configuration providing an IUsernameSecretProvider (which returns the secret for a given username in plaintext)
            // services.AddScoped<IUsernameSecretProvider, TrivialUsernameSecretProvider>();
            // services.AddAuthentication("Digest")
            //         .AddDigestAuthentication(DigestAuthenticationConfiguration.Create("VerySecret", "some-realm", 60, true, 20));

            // Example configuration using IUsernameHashedSecretProvider (which returns the pre-computed MD5 hash of the secret "A1")
            services.AddScoped <IUsernameHashedSecretProvider, TrivialUsernameHashedSecretProvider>();
            services.AddAuthentication("Digest")
            .AddDigestAuthentication(DigestAuthenticationConfiguration.Create("VerySecret", "some-realm", 60, true, 20));

            services.AddControllers();
        }
示例#4
0
        public void Configuration(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

            config.Routes.MapHttpRoute(name: "DefaultApi",
                                       routeTemplate: "api/{controller}/{id}",
                                       defaults: new {
                id = RouteParameter.Optional
            });

            // Example configuration providing an IUsernameSecretProvider (which returns the secret for a given username in plaintext)
            // app.Use<DigestAuthenticationMiddleware>(DigestAuthenticationConfiguration.Create("VerySecure", "test-realm", 30, true, 20),
            //                                         new TrivialUsernameSecretProvider());

            // Example configuration using IUsernameHashedSecretProvider (which returns the pre-computed MD5 hash of the secret "A1")
            app.Use <DigestAuthenticationMiddleware>(DigestAuthenticationConfiguration.Create("VerySecure", "test-realm", 30, true, 20),
                                                     new TrivialUsernameHashedSecretProvider());
            app.UseWebApi(config);
        }
示例#5
0
 public DigestAuthenticationHandler(DigestAuthenticationConfiguration config, IUsernameHashedSecretProvider usernameHashedSecretProvider, IClock clock)
 {
     _digestAuth = new DigestAuthImplementation(config, usernameHashedSecretProvider, clock);
 }
示例#6
0
 public DigestAuthenticationMiddleware(OwinMiddleware next, DigestAuthenticationConfiguration config, IUsernameSecretProvider usernameSecretProvider) :
     base(next, new DigestAuthenticationOptions())
 {
     _config = config;
     _usernameSecretProvider = usernameSecretProvider;
 }
示例#7
0
 /// <summary>
 /// Enables digest authentication
 /// </summary>
 /// <param name="builder">The <see cref="AuthenticationBuilder"/></param>
 /// <param name="config">Mandatory configuration for Digest Authentication</param>
 /// <returns>A reference to builder after the operation has completed.</returns>
 public static AuthenticationBuilder AddDigestAuthentication(this AuthenticationBuilder builder, DigestAuthenticationConfiguration config) =>
 builder.AddDigestAuthentication(config, "Digest", "Digest");