ua-security
UA Security is a simple token-based security module for Angular JS applications. It contains a few configurable services to perform common authentication and authorization tasks. Those tasks include:
- login: authenticate user against configured REST endpoint and store the user credentials locally
- logout: request that the REST endpoint destroy its token and remove authenticated user locally
- isAuthenticated: authenticated user exists
- isAnonymous: no authenticated user exists
- hasAllRoles: the authenticated user has all roles supplied
- hasAnyRole: the authenticated user has any of the roles supplied
Installation
bower install angular-ua-security
Usage
angular.module('your-app', ['ua.security']);
Configuration
Security Service
- securityServiceProvider.setAuthTokenHeader: the name of the key used to store the token when communicating with the REST endpoint
Authentication Service
- authenticationServiceProvider.setAuthenticationUrl: the absolute url of the REST endpoint providing authentication
- authenticationServiceProvider.setLogoutUrl: the absolute url of the REST endpoint providing logout
Example
angular.module('your-app', ['ua.security']) .config(function(authenticationServiceProvider, securityServiceProvider){ authenticationServiceProvider.setAuthenticationUrl('https://api.domain.com/login'); authenticationServiceProvider.setLogoutUrl('https://api.domain.com/logout'); securityServiceProvider.setAuthTokenHeader('auth-token'); });
Authors and Contributors
- David Spies (@dspies)
Problems
This project has a very specific scope at the moment, but feel free to contact me with any questions or suggestions. I will update the ua-security wiki in future with a roadmap. If you have problems, please file an issue or better yet, submit a pull request.