No description
Find a file
2014-09-15 23:24:02 +09:00
src/clj_jwt see #9 code refinement 2014-09-15 23:22:48 +09:00
test see #9 code refinement 2014-09-15 23:22:48 +09:00
.gitignore #5 bug fix: handling string key problem 2014-06-19 21:54:25 +09:00
.travis.yml add .travis.yml 2013-05-03 01:01:34 +09:00
project.clj Use a constant time equality check for HMAC signature verification 2014-08-30 15:36:51 -03:00
README.md see add clj-jwt.intdate which convert joda-time and IntDate value each other 2014-04-20 18:34:15 +09:00

clj-jwt

Build Status Dependency Status

A Clojure library for JSON Web Token(JWT) draft-ietf-oauth-json-web-token-19

Supporting algorithms

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

Not supporting

  • JSON Web Encryption (JWE)

Usage

Leiningen

clj-jwt

Generate

(ns foo
  (:require
    [clj-jwt.core  :refer :all]
    [clj-jwt.key   :refer [private-key]]
    [clj-time.core :refer [now plus days]]))

(def claim
  {:iss "foo"
   :exp (plus (now) (days 1))
   :iat (now)})

(def rsa-prv-key (private-key "rsa/private.key" "pass phrase"))
(def ec-prv-key  (private-key "ec/private.key"))

;; plain JWT
(-> claim jwt to-str)

;; HMAC256 signed JWT
(-> claim jwt (sign :HS256 "secret") to-str)

;; RSA256 signed JWT
(-> claim jwt (sign :RS256 rsa-prv-key) to-str)

;; ECDSA256 signed JWT
(-> claim jwt (sign :ES256 ec-prv-key) to-str)

Verify

(ns foo
  (:require
    [clj-jwt.core  :refer :all]
    [clj-jwt.key   :refer [private-key public-key]]
    [clj-time.core :refer [now plus days]]))

(def claim
  {:iss "foo"
   :exp (plus (now) (days 1))
   :iat (now)})

(def rsa-prv-key (private-key "rsa/private.key" "pass phrase"))
(def rsa-pub-key (public-key  "rsa/public.key"))
(def ec-prv-key  (private-key "ec/private.key"))
(def ec-pub-key  (public-key  "ec/public.key"))

;; verify plain JWT
(let [token (-> claim jwt to-str)]
  (-> token str->jwt verify))

;; verify HMAC256 signed JWT
(let [token (-> claim jwt (sign :HS256 "secret") to-str)]
  (-> token str->jwt (verify "secret")))

;; verify RSA256 signed JWT
(let [token (-> claim jwt (sign :RS256 rsa-prv-key) to-str)]
  (-> token str->jwt (verify rsa-pub-key)))

;; verify ECDSA256 signed JWT
(let [token (-> claim jwt (sign :ES256 ec-prv-key) to-str)]
  (-> token str->jwt (verify ec-pub-key)))

License

Copyright © 2014 uochan

Distributed under the Eclipse Public License, the same as Clojure.