Skip to content

Commit

Permalink
Add information about usage to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrik Bjornskov committed Aug 30, 2015
1 parent 24b7253 commit 9e3bb71
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,51 @@ Antenna

[![Build Status](https://travis-ci.org/henrikbjorn/Antenna.svg?branch=master)](https://travis-ci.org/henrikbjorn/Antenna)

Recentry i had to implement authentication in an AngularJS application. For this pupose i found
https://github.com/sahat/satellizer which supports different flows of authentication, one of these
is username/password through JSON Web Token (JWT).
Antenna is a small library that helps integrating JWT (JSON Web Token) for projects using
the Symfony Security Component.

This small library combines firebase/php-jwt and two custom Symfony Security SimplePreAuthenticators
in order to have a simple flow.
In order to use this library you need to set up two authenticators in your firewall.

`TokenExchangeAuthenticator` only purpose is to take the username / password provided in a JSON request and return a
valid JWT token. Depending on the way it have been setup.
The first is `UsernamePasswordAuthenticator` which uses the security flow to authenticate through and
then "hijack" the request by rendering a body with a token `{ "token" : "json web token here" }`.

`TokenAuthenticator` assumes a `Authorization: Bearer my-token` header is present and will use a `TokenUserProvider`
implementation to authenticate the User.
The second uses the `Authorization: Bearer <json web token>` header style to authenticate your
users by validating the JWT.

Using Symfony Standard it would look something like:

``` yaml
services:
antenna.coder:
class: Antenna\Coder
arguments: ['shared-secret']

antenna.username_password_authenticator:
class: Antenna\Security\UsernamePasswordAuthenticator
arguments: [@security.user_checker, @security.encoder_factory, @antenna.coder]

antenna.token_authenticator:
class: Antenna\Security\TokenAuthenticator
arguments: [@security.user_checker, @antenna.coder]

security:
providers:
in_memory:
memory:
users:
henrikbjorn:
password: my-unique-password
roles: 'ROLE_USER'

firewalls:
token_exchange:
pattern: ^/auth
simple-preauth:
provider: in_memory
authenticator: antenna.username_password_authenticator
web_token:
pattern: ^/api
simple-preauth:
provider: in_memory
authenticator: antenna.token_authenticator
```

0 comments on commit 9e3bb71

Please sign in to comment.