-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filled out readme with installation instructions and usage, added bad…
…ges.
- Loading branch information
Showing
1 changed file
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,68 @@ | ||
# Angular JSON Web Token Authentication Module | ||
Angular authentication with JSON Web tokens. | ||
|
||
## Usage | ||
[![Build Status](https://travis-ci.org/spira/angular-jwt-auth.svg?branch=master)](https://travis-ci.org/spira/angular-jwt-auth) | ||
[![Coverage Status](https://coveralls.io/repos/spira/angular-jwt-auth/badge.svg?branch=master)](https://coveralls.io/r/spira/angular-jwt-auth?branch=master) | ||
[![Dependency Status](https://gemnasium.com/spira/angular-jwt-auth.svg)](https://gemnasium.com/spira/angular-jwt-auth) | ||
|
||
## Intro | ||
This module is for authenticating with a remote REST API, and attaching the auth token to all subsequent `$http` xhr | ||
requests to the API. | ||
|
||
The module has the following features | ||
* Basic (username/password) authentication | ||
* Automatic token refreshing when it is about to expire, | ||
* Persisting the token to `localstorage` so it is available between sessions | ||
* Token based authentication (useful for authenticating a confirmed registration email). | ||
|
||
## Installation | ||
|
||
Install through bower: | ||
|
||
```sh | ||
bower install angular-jwt-auth | ||
``` | ||
bower install angular-jwt-auth --save | ||
``` | ||
|
||
## Usage | ||
|
||
* Require the `ngJwtAuth` module in your angular application | ||
|
||
```js | ||
angular.module('app', ['ngJwtAuth']) | ||
``` | ||
|
||
* (Optionally) configure the service provider | ||
|
||
```js | ||
angular.module('app', ['ngJwtAuth']) | ||
.config(['ngJwtAuthServiceProvider', function(ngJwtAuthServiceProvider){ | ||
ngJwtAuthServiceProvider | ||
.setApiEndpoints({ | ||
base: '/api/auth/jwt', | ||
login: '/login', | ||
refresh: '/refresh' | ||
}) | ||
; | ||
}]) | ||
``` | ||
|
||
* Inject the `ngJwtAuthService` and use it! | ||
|
||
```js | ||
angular.module('app', ['ngJwtAuth']) | ||
.controller('AppCtrl', ['ngJwtAuthService', function(ngJwtAuthService){ | ||
|
||
$scope.login = function(username, password){ | ||
|
||
ngJwtAuthService.authenticate(username, password) | ||
.then(function(authenticatedUser){ | ||
console.log("Login Success!", authenticatedUser); | ||
}) | ||
.catch(function(err){ | ||
console.error(err); | ||
}) | ||
|
||
}; | ||
|
||
}]) | ||
``` |