platanus-angular-auth
v0.1.0
Published
Angular Auth ============
Downloads
4
Keywords
Readme
Angular Auth
Library to help integrate Token Authentication between Angularjs and json API
Installation
Install the bower package.
$ bower install platanus-angular-auth
Include the JS file in your project and add the module as an Angular Dependency
angular.module('yourapp', ['PlAuth']);
Using
The library includes a service called AuthSrv
and a Restmod Mixing called HttpAuth
.
You can use AuthSrv
to store a user's credentials and check the status of those credentials.
// Creating a session using a Restmod Model called Session
Session.$create().$then(function(data) {
AuthSrv.store(data);
});
The store function would look for an uid
and token
property on the response and persist if they have values.
Then if your Restmod Models use the HttpAuth
mixing, by default, the library will add an Authorization header on each request like this:
'X-User-Email': '[email protected]'
'X-User-Token': 'xxx'
Config
You can change the default uid and token expected from server response using AuthConfigProvider
like this:
angular.module('yourapp', ['PlAuth']).config(function(AuthConfigProvider){
AuthConfigProvider.setUidKey('email');
AuthConfigProvider.setTokenKey('auth_token');
});
To change the default uid and token headers sent to the server you can do:
angular.module('yourapp', ['PlAuth']).config(function(AuthConfigProvider){
AuthConfigProvider.setUidHeaderName('X-Admin-Email');
AuthConfigProvider.setTokenHeaderName('X-Admin-User');
});
You can change the default local storage prefix. If you don't, keys will be prefixed with angularAuth
.
angular.module('yourapp', ['PlAuth']).config(function(AuthConfigProvider){
AuthConfigProvider.setLocalStoragePrefix('myCustomPrefix');
});
Live Demo
Check out a live Demo using the library Live Demo
API
AuthSrv
isLogged()
Returns if the session is logged
isRegistered()
Returns true or false whether we have an uid
persisted
store(object)
Saves uid
and token
from a given object
on LocalStorage
clear()
Removes uid
and token
from LocalStorage
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Credits
Thank you contributors!
angular-auth is maintained by platanus.
License
AngularAuth is © 2015 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.