angular-oauth2
AngularJS OAuth2 authentication module written in ES6.
Installation
Choose your preferred method:
- Bower:
bower install angular-oauth2
- NPM:
npm install --save angular-oauth2
- Download: angular-oauth2
Usage
angular-oauth2
dependencies.
1. Download
If you're using bower
they will be automatically downloaded upon installing this library.
angular-oauth2
and dependencies.
2. Include
OAuth
(required) and OAuthToken
(optional):
3. Configure angular ;
OAuth
errors and do something with them (optional):
4. Catch angular ;
API
OAuthProvider
Configuration defaults:
OAuthProvider;
OAuth
Check authentication status:
/** * Verifies if the `user` is authenticated or not based on the `token` * cookie. * * @return */ OAuth;
Get an access token:
/** * Retrieves the `access_token` and stores the `response.data` on cookies * using the `OAuthToken`. * * @param * @param * @return */ OAuth;
Refresh access token:
/** * Retrieves the `refresh_token` and stores the `response.data` on cookies * using the `OAuthToken`. * * @return */ OAuth
Revoke access token:
/** * Revokes the `token` and removes the stored `token` from cookies * using the `OAuthToken`. * * @return */ OAuth
NOTE: An event oauth:error
will be sent everytime a responseError
is emitted:
{ status: 400, data: { error: 'invalid_request' }
{ status: 400, data: { error: 'invalid_grant' }
{ status: 401, data: { error: 'invalid_token' }
{ status: 401, headers: { 'www-authenticate': 'Bearer realm="example"' } }
OAuthTokenProvider
OAuthTokenProvider
uses angular-localforage to store token.
OAuthToken
If you want to manage the token
yourself you can use OAuthToken
service.
Please check the OAuthToken source code to see all the available methods.
Contributing & Development
Contribute
Found a bug or want to suggest something? Take a look first on the current and closed issues. If it is something new, please submit an issue.
Develop
It will be awesome if you can help us evolve angular-oauth2
. Want to help?
- Fork it.
npm install
.- Do your magic.
- Run the tests:
gulp test
. - Build:
gulp build
- Create a Pull Request.
The source files are written in ES6.