Skip to content

Commit

Permalink
Clean up documentation and code to abide with linter.
Browse files Browse the repository at this point in the history
This brings several clean ups in the code base:

- Documentation: better hierarchy in hexdocs
- Code: use linter for stabilishing the same style throughout the codebase
- Travis config: add Elixir 1.2

Since most of it is just cosmetic, everything is packed together.
  • Loading branch information
cs-victor-nascimento committed Mar 10, 2016
1 parent 6807ff9 commit b9b5cd1
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 249 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/_build
/deps
/cover
erl_crash.dump
*.ez
/doc
Expand Down
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
sudo: false # to use faster container based build environment
language: elixir

elixir:
- 1.0.5
- 1.1.1
- 1.2.2

otp_release:
- 17.5
- 18.0
- 18.2

after_script:
- mix deps.get --only docs
- MIX_ENV=docs mix docs # generate docs to check if it is not breaking.
- MIX_ENV=test mix bench
- MIX_ENV=test mix coveralls.travis

matrix:
exclude:
- otp_release: 17.5
elixir: 1.2.2
112 changes: 63 additions & 49 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,106 +1,120 @@
# v1.1.0
## v1.2.0 (not released)

* Enhancements
- Bumped JOSE dependency to 1.7.1
- Added native `libsodium`, `keccakf1600` and `libdecaf` support
- Generated claims are available after signing (thanks to [@lnikkila](https://github.com/lnikkila))
- Using `credo` lint checker

* Bug fixes
- Fix validation of `iat` on the same second (thanks to [@lnikkila](https://github.com/lnikkila))

## v1.1.0

* Enhancements
* Add EdDSA support: Ed25519, Ed25519ph, Ed448, Ed448ph
- Add EdDSA support: Ed25519, Ed25519ph, Ed448, Ed448ph

## v1.0.0

# v1.0.0
* Enhancements
* The `none` algorithm can be used if and only if `allow_none_algorithm` exists as an application variable
on the `joken` app and is set to `true`. Otherwise an error is thrown
* The `none` algorithm can be used if and only if `allow_none_algorithm` exists as an application variable on the `joken` app and is set to `true`. Otherwise an error is thrown

* Joken
* Added `peek/2`, `get_data/1`, `with_header_arg/3`, `with_header_args/2`, `none/1`
* Joken: added `peek/2`, `get_data/1`, `with_header_arg/3`, `with_header_args/2`, `none/1`

* Bug fixes
* Ensures `Plug` is loading before loading `Joken.Plug`
* Ensures `Plug` is loading before loading `Joken.Plug`

## v0.16.1

# v0.16.1
* Bug Fixes
* `Joken.Plug` - Fixed capture of default `on_error` function causing compilation errors
* `Joken.Plug` - Fixed capture of default `on_error` function causing compilation errors

## v0.16.0

# v0.16.0
* Enhancements
* Updated API to allow for more flexibility for signing and verifying tokens
* Joken.Plug has been added.
* Small fixes to make sure Joken works with Elixir 1.1
* Added support for the following signing algorithms:
* ES256
* ES384
* ES512
* PS256
* PS384
* PS512
* RS256
* RS384
* RS512
* Updated API to allow for more flexibility for signing and verifying tokens
* Joken.Plug has been added.
* Small fixes to make sure Joken works with Elixir 1.1
* Added support for the following signing algorithms:
* ES256
* ES384
* ES512
* PS256
* PS384
* PS512
* RS256
* RS384
* RS512

* Breaking
* The new API is completely different than the old one. Take a look [here to find out how to go from 0.15 to 0.16](https://github.com/bryanjos/joken/wiki/Moving-from-0.15-to-0.16)
* `encode` and `decode` in the Joken module have been renamed to `sign` and `verify`.
* This release also deprecates [plugJWT](https://hex.pm/packages/plug_jwt). Use `Joken.Plug` instead
* The new API is completely different than the old one. Take a look [here to find out how to go from 0.15 to 0.16](https://github.com/bryanjos/joken/wiki/Moving-from-0.15-to-0.16)
* `encode` and `decode` in the Joken module have been renamed to `sign` and `verify`.
* This release also deprecates [plugJWT](https://hex.pm/packages/plug_jwt). Use `Joken.Plug` instead

## v0.15.0

# v0.15.0
* Enhancements
* Add options parameter to `Joken.Config.validate_claim`
* Moved validation helpers functions to `Joken.Helpers`
* Add options parameter to `Joken.Config.validate_claim`
* Moved validation helpers functions to `Joken.Helpers`

# v0.14.1
## v0.14.1

* Enhancements
* Enhancements
* Using the Dict Protocol for accessing data

# v0.14.0
## v0.14.0

* Enhancements
* Enhancements
* The `Joken.Config` behaviour handles the configuration of the secret_key, algorithm, encode and decode functions, as well as functions for adding and validating claims
* Add `options` parameter to `Joken.Token.decode`
* Add `options` parameter to `Joken.decode`
* Removed `:none` algorithm completely

* Breaking
* Breaking
* `Joken.Codec` is replaced by `Joken.Config`.
* `json_module` in config is replaced by `config_module`.
* `algorithm` and `secret_key` in config is replaced by implementing the `algorithm` and `secret_key` functions on `Joken.Config`.
* `Joken.Token.encode` now has a signature of `(joken_config, payload)` since the algorithm and secret key are defined inside of the passed in `joken_config` module.
* `Joken.Token.decode` now has a signature of `(joken_config, jwt, options \\ [])` since the algorithm and secret key are defined inside of the passed in `joken_config` module.

# v0.13.1
## v0.13.1

* Enhancements
* Enhancements
* Checking to make sure signature is on token unless `:none` is passed as the algorithm

# v0.13.0
## v0.13.0

* Enhancements
* Enhancements
* Validating iat claim
* Verifying signature before getting the data
p
## v0.12.0

# v0.12.0

* Enhancements
* Enhancements
* Signature is now verified just from the header and payload strings.
* Added `decode_secret_key?` parameter

# v0.11.0
## v0.11.0

* Enhancements
* Enhancements
* `Joken` module now looks more like old API from 0.8 with the exception that it reads configuration from a :joken config block.
* For security reasons, now using the configured algorithm for checking signature instead of the one specified in the header.
* Added algorithm paramter to `Joken.Token.decode` to be used when verifying signatures

# v0.10.1
## v0.10.1

* Enhancements
* Enhancements
* Fixed documentation typos
* Joken now uses an Agent instead of implementing GenServer


# v0.10.0
## v0.10.0

* Enhancements
* Enhancements
* No longer has a dependency on Timex or JSX
* Can now use any json library as long as you implement the behaviour, `Joken.Codec`
* Joken module is now a GenServer
* secret_key, algorithm, and json_module are now configured when the starting Joken module

* Breaking
* Breaking
* `Joken.encode(payload, secret, algorithm, claims)` is now `Joken.encode(pid, payload, claims)` and `Joken.decode(token, secret, claims)` is now `Joken.decode(pid, token, claims)`. `secret_key` and `algorithm` are now configured along with `json_module` when starting the Joken module via any of the `Joken.start_link` functions. You could also use the `Joken.Token` module directly instead which isn't a GenServer and allows you to put in all of the parameters needed whenever you call encode or decode.
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Joken [![Documentation](https://img.shields.io/badge/docs-hexpm-blue.svg)](http://hexdocs.pm/joken/) [![Downloads](https://img.shields.io/hexpm/dt/joken.svg)](https://hex.pm/packages/joken) [![Build](https://travis-ci.org/bryanjos/joken.svg?branch=master)](https://travis-ci.org/bryanjos/joken)
# Joken

[![Documentation](https://img.shields.io/badge/docs-hexpm-blue.svg)](http://hexdocs.pm/joken/) [![Downloads](https://img.shields.io/hexpm/dt/joken.svg)](https://hex.pm/packages/joken) [![Build](https://travis-ci.org/bryanjos/joken.svg?branch=master)](https://travis-ci.org/bryanjos/joken)

[Documentation](http://hexdocs.pm/joken/)

Expand Down Expand Up @@ -39,7 +41,10 @@ Joken allows you to use any claims you wish, but has convenience methods for the

For a more in depth description of each claim, please see the reference specification [here](https://tools.ietf.org/html/rfc7519).

## Usage:
You can view the changelog [here](https://github.com/bryanjos/joken/blob/master/CHANGELOG.md) or on the official documentation in the "Pages" section.


## Usage

All you need to generate a token is a `Joken.Token` struct with proper values.
There you can set:
Expand Down Expand Up @@ -112,7 +117,7 @@ my_verified_token = "some_token"

There are other options and helper functions available. See the docs of the `Joken` module for a complete documentation.

## Plug:
## Plug

Joken also comes with a Plug for verifying JWTs in web applications.

Expand Down Expand Up @@ -185,27 +190,26 @@ to the route. The keys that Joken will look for in that map are:

- `joken_on_error`: Same as `on_error` above. Overrides `on_error` if defined on the Plug

### EdDSA
## Native crypto

Native C support for Ed25519 and Ed25519ph can be provided by the libsodium asynchronous port driver by adding it as a dependency to a project's Mix file:
Joken is based on cryptography implemented by the [erlang-jose](https://github.com/potatosalad/erlang-jose) project. One of the features it provides is the ability to auto detect the presence of native crypto libraries with a NIF (Erlang's Native Implemented Function) interface. Some of these libraries are:

```elixir
defp deps do
[
{:joken, "~> 1.1"},
{:libsodium, "~> 0.0.2"}
]
end
```
- [erlang-libsodium](https://github.com/potatosalad/erlang-libsodium): provides native implemented crypto for Ed25519 and Ed25519ph
- [erlang-keccakf1600](https://github.com/potatosalad/erlang-keccakf1600): provides SHA-3 NIFs
- [erlang-libdecaf](https://github.com/potatosalad/erlang-libdecaf): provides ed448goldilocks NIFs

While there isn't native C support for Ed448 and Ed448ph yet, there is a notable performance improvement by using a native C driver the SHA-3 related functions used by these signature algorithms by adding the [keccakf1600](https://github.com/potatosalad/erlang-keccakf1600) asynchronous port driver as a dependency to a project's Mix file:
Joken inherits that auto discovery feature. So, in order to increase speed in scenarios that you are using these crypto libraries, all you need to do is add them as dependencies:

```elixir
defp deps do
[
{:joken, "~> 1.1"},
{:keccakf1600, "~> 0.0.1"}
{:libsodium, "~> 0.0.3"},
{:keccakf1600, "~> 0.0.1"},
{:libdecaf, "~> 0.0.1"}
]
end
```

Be advised though that this is a work in progress by [@potatosalad](https://github.com/potatosalad).

15 changes: 7 additions & 8 deletions bench/joken_token_bench.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ defmodule Joken.Token.Bench do
use Benchfella
import Joken
import Joken.Fixtures
alias Joken.Signer

@secret "test"

Expand All @@ -23,25 +22,25 @@ defmodule Joken.Token.Bench do
## ------------------------------
## HS256, HS384, HS512 benchmarks
## ------------------------------

bench "HS256 token generation" do
token |> sign(hs256(@secret)) |> get_compact
:ok
end

bench "HS384 token generation" do
token |> sign(hs384(@secret)) |> get_compact
:ok
end

bench "HS512 token generation" do
token |> sign(hs512(@secret)) |> get_compact
:ok
end

## ------------------------------
## RS256, RS384, RS512 benchmarks
## ------------------------------
## ------------------------------
bench "RS256 token generation" do
token |> sign(rs256(rsa_key)) |> get_compact
:ok
Expand Down Expand Up @@ -77,7 +76,7 @@ defmodule Joken.Token.Bench do

## ------------------------------
## PS256, PS384, PS512 benchmarks
## ------------------------------
## ------------------------------
bench "PS256 token generation" do
token |> sign(ps256(rsa_key)) |> get_compact
:ok
Expand All @@ -87,7 +86,7 @@ defmodule Joken.Token.Bench do
token |> sign(ps384(rsa_key)) |> get_compact
:ok
end

bench "PS512 token generation" do
token |> sign(ps512(rsa_key)) |> get_compact
:ok
Expand Down Expand Up @@ -115,5 +114,5 @@ defmodule Joken.Token.Bench do
token |> sign(ed448ph(ed448ph_key)) |> get_compact
:ok
end

end
Loading

0 comments on commit b9b5cd1

Please sign in to comment.