Skip to content

Commit

Permalink
Filled out readme with installation instructions and usage, added bad…
Browse files Browse the repository at this point in the history
…ges.
  • Loading branch information
zakhenry committed Jul 1, 2015
1 parent ceffdff commit fa9de4d
Showing 1 changed file with 62 additions and 3 deletions.
65 changes: 62 additions & 3 deletions README.md
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);
})

};

}])
```

0 comments on commit fa9de4d

Please sign in to comment.