Skip to content

Commit

Permalink
Merge branch 'release/v0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
tafax committed Jan 27, 2014
2 parents 637462b + d63ad69 commit af8151e
Show file tree
Hide file tree
Showing 27 changed files with 4,154 additions and 2,157 deletions.
23 changes: 21 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,26 @@ module.exports = function(grunt)
},
concat: {
options: {
banner: '<%= meta.banner %>'
banner: '<%= meta.banner %>\n\n\'use strict\';\n\n',
process: function(src, filepath) {
return '\n// Source: ' + filepath + '\n\n' +
src.replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, '$1');
}
},
dist: {
src: ['<%= dirs.src %>/**/*.js'],
src: [
'src/angular-digest-auth.js',
'src/config/config-module.js',
'src/config/config-state-machine.js',
'src/services/dg-auth-service.js',
'src/services/auth-client.js',
'src/services/auth-events.js',
'src/services/auth-identity.js',
'src/services/auth-server.js',
'src/services/auth-service.js',
'src/services/auth-requests.js',
'src/services/auth-storage.js'
],
dest: '<%= dirs.dest %>/<%= pkg.name %>.dev.js'
}
},
Expand Down Expand Up @@ -129,4 +145,7 @@ module.exports = function(grunt)

// Build task.
grunt.registerTask('build', ['test', 'concat', 'removelogging', 'uglify']);

// Version task.
grunt.registerTask('version', ['bump', 'build']);
};
160 changes: 62 additions & 98 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ It is an AngularJS module to manage HTTP Digest Authentication. It provides basi
to sign in and sign out. It automatically manages the synchronization between the client and the
server after the user did the login.

**NB:** *the module is under development and so some features or APIs can change.*

#Installation
You can download this by:
* Using bower and running `bower install angular-digest-auth --save` (recommended)
Expand All @@ -17,7 +15,7 @@ var app = angular.module('myApp', ['dgAuth']);
````

#Dependencies
This module depends on [angular](https://github.com/angular/angular.js), [angular-cookies](https://github.com/angular/bower-angular-cookies)
This module depends on [angular](https://github.com/angular/angular.js), [angular-state-machine](https://github.com/tafax/angular-state-machine)
and [angular-md5](https://github.com/gdi2290/angular-md5).

#Configuration
Expand All @@ -26,9 +24,9 @@ You have to provide a few configurations in order to work.
###Login and logout
How to configure the urls to sing in and sign out.
````javascript
app.config(['authServiceProvider', function(authServiceProvider)
app.config(['dgAuthServiceProvider', function(dgAuthServiceProvider)
{
authServiceProvider.setConfig({
dgAuthServiceProvider.setConfig({
login: {
method: 'POST',
url: '/signin'
Expand All @@ -48,35 +46,59 @@ app.config(['authServiceProvider', function(authServiceProvider)
###Header
How to configure the header to search server information.
````javascript
app.config(['authServerProvider', function(authServerProvider)
app.config(['dgAuthServiceProvider', function(dgAuthServiceProvider)
{
dgAuthServiceProvider.setHeader('Your-Header-For-Authentication');
}]);
````

###Limit
How to configure the limit of number requests to sign in. When the limit is exceeded
`limit` of login callbacks is invoked. The default limit is 4.
N.B.: the limit includes the request to sign in place during the invocation of the `start` method.
````javascript
app.config(['dgAuthServiceProvider', function(dgAuthServiceProvider)
{
authServerProvider.setHeader('Your-Header-For-Authentication');
/**
* Sets the limit to 5 requests.
* 4 requests after the invocation of start method.
*/
dgAuthServiceProvider.setLimit(5);

/**
* Sets the limit of requests to infinite.
*/
dgAuthServiceProvider.setLimit('inf');
}]);
````

###Calbacks
How to configure what happens at the user login and/or logout.
````javascript
app.config(['authServiceProvider', function(authServiceProvider)
app.config(['dgAuthServiceProvider', function(dgAuthServiceProvider)
{
/**
* You can add the callbacks to manage what happens after
* successful of the login.
*/
authServiceProvider.callbacks.login.push(['serviceInject', function(serviceInject)
dgAuthServiceProvider.callbacks.login.push(['serviceInject', function(serviceInject)
{
return {
successful: function(data)
successful: function(response)
{
//Your code...
},
error: function(response)
{
//Your code to manage the login successful.
//Your code...
},
error: function(error)
required: function(response)
{
//Your code to manage the login error.
//Your code...
},
required: function()
limit: function(response)
{
//Your code to manage the need for a login.
//Your code...
}
};
}]);
Expand All @@ -87,57 +109,49 @@ app.config(['authServiceProvider', function(authServiceProvider)
* You can add the callbacks to manage what happens after
* successful of the logout.
*/
authServiceProvider.callbacks.logout.push(['serviceInject', function(serviceInject)
dgAuthServiceProvider.callbacks.logout.push(['serviceInject', function(serviceInject)
{
return {
successful: function(data)
successful: function(response)
{
//Your code to manage the logout successful.
//Your code...
},
error: function(error)
error: function(response)
{
//Your code to manage the logout error.
//Your code...
}
};
}]);
}]);
````

###Storage
By default, after the user has made the login, the credentials are stored in **sessionStorage** and the module
processes all further requests with this credentials. If you want the user is automatically reconnected when
he returns in your app, you can specify the **localStorage** as default storage.
By default, after the user has made the login, the credentials are stored in `sessionStorage` and the module
processes all further requests with this credentials. If you want to restore the user credentials when
he returns in your app, you can specify the `localStorage` as default storage.
````javascript
app.config(['authStorageProvider', 'authServiceProvider', function(authStorageProvider, authServiceProvider)
app.config(['dgAuthServiceProvider', function(dgAuthServiceProvider)
{
/**
* Tells to service that it can be reconnect the user
* even if he has signed out or he has closed the browser.
*/
authServiceProvider.setAutomatic(true);

/**
* Uses localStorage instead the sessionStorage.
* The service can automatically reconnect the user
* only with localStorage.
*/
authStorageProvider.setStorage(localStorage);
dgAuthServiceProvider.setStorage(localStorage);
}]);
````

Obviously, if you want to specify your own storage object, you can :).

#Usage
For basic usage, you can launch the `signin()` when your app goes run.
For basic usage, you can launch the `start()` when your app goes run.
````javascript
app.run(['authService', function(authService)
app.run(['dgAuthService', function(dgAuthService)
{
/**
* It tries to sign in. If the service doesn't find
* the credentials stored or the user is not signed in yet,
* the service executes the required function.
*/
authService.signin();
dgAuthService.start();
}]);
````

Expand All @@ -146,41 +160,38 @@ Then you have to sign in another time.
````javascript
$scope.submit = function(user)
{
authService.setCredentials(user.username, user.password);
authService.signin();
dgAuthService.setCredentials(user.username, user.password);
dgAuthService.signin();
};
````

#Authorization
You can use a functionality of authService to authorize the user to navigate in your app.
You can use a functionality of dgAuthService to authorize the user to navigate in your app.
````javascript
app.config(['$routeProvider', function($routeProvider)
{
/**
* Define the routing to the login.
*/
$routeProvider.when('path/to/login', {...});

/**
* Use a variable in resolve to authorize the users.
* The method 'isAuthenticated()' returns a promise
* which you can use to validate the requests.
* The method 'isAuthorized()' returns a promise
* which you can use to authorize the requests.
*/
$routeProvider.when('some/path', {
...
resolve: {
auth: ['authService', '$q', '$location', function(authService, $q, $location)
auth: ['dgAuthService', '$q', '$location', function(dgAuthService, $q, $location)
{
var deferred = $q.defer();

authService.isAuthenticated().then(function()
dgAuthService.isAuthorized().then(function(authorized)
{
deferred.resolve();
if(authorized)
deferred.resolve();
else
deferred.reject();
},
function()
function(authorized)
{
deferred.reject();
$location.path('path/to/login');
});

return deferred.promise;
Expand All @@ -190,52 +201,5 @@ app.config(['$routeProvider', function($routeProvider)
}]);
````

#Events
You can use the events to handle the module environment.
````javascript
authentication: {
headerNotFound: //After a login request no header has been found.
header: //A valid header is found in server response.
request: //After a login request a valid authentication request is found in the server response.
},
process: {
request: //A request is processed by the module.
response: //A response with status 401 is processed by the module.
},
login: {
successful: //The login is successful.
error: //The login responds with an error.
required: //The login is required to access a functionality.
},
logout: {
successful: //The logout is successful
error: //The logout responds with an error.
},
credential: {
submitted: //The new credentials are submitted.
stored: //The credentials are stored in the auth storage.
restored: //The credentials in the storage are restored.
}
````

Use the `authEvents` service to handle the events and do your own tasks. For example, with
`authEvents.getEvent('login.error')` you can handle if an error appears in the login procedure and
afterwards you can notify this error in your view to the user.
Also you can specify your events.
````javascript
app.config(['authEventsProvider', function(authEventsProvider)
{
authEventsProvider.setEvents({
authentication: {
header: 'my_header_event'
},
credential: {
restored: 'my_credential_event'
}
...
});
}]);
````

#License
[MIT](https://github.com/tafax/angular-digest-auth/blob/master/LICENSE)
45 changes: 23 additions & 22 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{
"name": "angular-digest-auth",
"version": "0.3.0",
"main": "./dist/angular-digest-auth.min.js",
"description": "AngularJS module to manage HTTP Digest Authentication",
"repository": {
"type": "git",
"url": "git://github.com/tafax/angular-digest-auth.git"
},
"dependencies": {
"angular-cookies": ">=1.2.5",
"angular-md5": ">=0.0.3",
"angular": ">=1.2.5"
},
"devDependencies": {
"angular-mocks": ">=1.2.5"
},
"ignore": [
"node_modules",
"components",
"lib"
]
}
"name": "angular-digest-auth",
"version": "0.4.0",
"main": "./dist/angular-digest-auth.min.js",
"description": "AngularJS module to manage HTTP Digest Authentication",
"repository": {
"type": "git",
"url": "git://github.com/tafax/angular-digest-auth.git"
},
"dependencies": {
"angular-cookies": "*",
"angular-md5": "*",
"angular-state-machine": "*",
"angular": "*"
},
"devDependencies": {
"angular-mocks": "*"
},
"ignore": [
"node_modules",
"components",
"lib"
]
}
Loading

0 comments on commit af8151e

Please sign in to comment.