Erlang JWT Library
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
doc Move to G-Corp Jun 8, 2018
lib Bug correction + add missing claims Jun 8, 2018
src Move to G-Corp Jun 8, 2018
test Bug correction + add missing claims Jun 8, 2018
.editorconfig Move to rebar3 Aug 15, 2016
.gitignore Add rebar.lock Aug 15, 2016
.travis.yml Add travis CI Jun 13, 2017
Makefile
README.md Move to G-Corp Jun 8, 2018
bu.mk Prepare 0.2.0 release May 29, 2018
mix.exs Prepare 1.0.0 Jun 8, 2018
mix.lock Prepare 0.2.0 release May 29, 2018
overview.edoc Move to G-Corp Jun 8, 2018
rebar.config Update unit dep Nov 7, 2018
rebar.lock Prepare 0.2.0 release May 29, 2018
rebar3 Update mix.exs Oct 11, 2017

README.md

JWErl

Copyright (c) 2015, 2016, 2017, 2018 G-Corp

Version: 1.0.0

Authors: Gregoire Lejeune (gregoire.lejeune@gmail.com).

Build Status Hex.pm version Hex.pm downloads License
JWT

Warning, versions prior to 1.0.0 are affected by this vulnerabilitie. Get up to date!

Support

  • HS256, HS384, HS512
  • RS256, RS384, RS512
  • ES256, ES384, ES512

Usage

Erlang

% signed by default (hs256)
Jwt = jwerl:sign([{name, <<"bob">>}]).
jwerl:verify(Jwt).

% signed by specifing method
Jwt = jwerl:sign([{name, <<"bob">>}], hs512).
jwerl:verify(Jwt, hs512).

% signed with secret key
Jwt = jwerl:sign([{name, <<"bob">>}], hs256, <<"kkey">>).
jwerl:verify(Jwt, hs256, <<"kkey">>).

% signed by none
Jwt = jwerl:sign([{name, <<"bob">>}], none).
jwerl:verify(Jwt, none).

% signed by RS512
{ok, PrivtPem} = file:read_file("path/to/rsa_private_key.pem"),
{ok, PublcPem} = file:read_file("path/to/rsa_public.pem"),
Jwt = jwerl:sign([{name, <<"bob">>}], rs512, PrivtPem).
jwerl:verify(Jwt, rs512, PublcPem).

% signed by ES256
{ok, PrivtPem} = file:read_file("path/to/es_private_key.pem"),
{ok, PublcPem} = file:read_file("path/to/es_public.pem"),
Jwt = jwerl:sign([{name, <<"bob">>}], es256, PrivtPem).
jwerl:verify(Jwt, es256, PublcPem).

Elixir

% signed by default (hs256)
jwt = Jwerl.sign([name: "bob"]).
Jwerl.verify(jwt).

% signed by specifing method
jwt = Jwerl.sign([name: "bob"], :hs512).
Jwerl.verify(jwt, :hs512).

% signed with secret key
jwt = Jwerl.sign([name: "bob"], :hs256, "kkey").
Jwerl.verify(jwt, :hs256, "kkey").

% signed by none
jwt = Jwerl.sign([name: "bob"], none).
Jwerl.verify(jwt, :none).

% signed by RS512
{ok, private_pem} = File.read("path/to/rsa_private_key.pem"),
{ok, public_pem} = File.read("path/to/rsa_public.pem"),
jwt = Jwerl.sign([name: "bob"], :rs512, private_pem).
Jwerl.verify(jwt, :rs512, public_pem).

% signed by ES256
{ok, private_pem} = File.read("path/to/es_private_key.pem"),
{ok, public_pem} = File.read("path/to/es_public.pem"),
jwt = Jwerl.sign([name: "bob"], :es256, private_pem).
Jwerl.verify(jwt, :es256, public_pem).

Licence

Copyright (c) 2015, 2016, 2017, 2018, G-Corp
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Modules

jwerl