Library to help integrate Token Authentication between Angularjs and json API
- We will leave the Issues open as a discussion forum only.
- We do not guarantee a response from us in the Issues.
- We are no longer accepting pull requests.
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']);
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': 'alf@melmack.com'
'X-User-Token': 'xxx'
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');
});
Check out a live Demo using the library Live Demo
Returns if the session is logged
Returns true or false whether we have an uid
persisted
Saves uid
and token
from a given object
on LocalStorage
Removes uid
and token
from LocalStorage
- 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
Thank you contributors!
angular-auth is maintained by platanus.
AngularAuth is © 2015 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.