pahlers / grunt-connect-http-auth

Http-auth middleware for grunt-connect.
MIT License
1 stars 1 forks source link

grunt-connect-http-auth

Http-auth middleware for grunt-connect.

NOTE

This package is not supported actively anymore. But it's opensource, so feel free to make changes, fork it, print it on paper or whatever. If you make a pull request I'm willing to review it and add it to the source.

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-connect-http-auth --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-connect-http-auth');

The "grunt-connect-http-auth" task

Grunt-connect-http-auth is using http-auth of gevorg as a middleware layer to add authenication.

Configuration

In your project's Gruntfile, add a section named auth to the connect data object passed into grunt.initConfig(). You find the configurations in the http-auth project.

grunt.initConfig({
  connect: {
    auth:{
      authRealm : "Private server",
      authList : ['foo:bar']
    }
  },
})

Adding the middleware

Expose the http-auth function to use in the middleware, at the top of the grunt file:

var authRequest = require('grunt-connect-http-auth/lib/utils').authRequest;

Add the middleware call from the connect option middleware hook

connect: {
    livereload: {
        options: {
            middleware: function (connect) {
                return [
                    authRequest
                ];
            }
        }
    }
}

Adding the "configureHttpAuth" task to the server task

For the server task, add the "configureHttpAuth" task before the "connect" task

grunt.registerTask('server', function (target) {
    grunt.task.run([
        'configureHttpAuth',
        'connect:livereload'
    ]);
});

Thanks

Todo

Release History

(Nothing yet)