No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
src
test
.editorconfig
.gitignore
.jshintrc
README.md
bower.json
gulpfile.js
karma.conf.js
package.json

README.md

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': 'alf@melmack.com'
'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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Credits

Thank you contributors!

Platanus

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.