diff --git a/README.md b/README.md index 1629992..e0ceb6b 100644 --- a/README.md +++ b/README.md @@ -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 ` 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 +```