• This repository has been archived on 04/Jul/2018
  • Stars
    star
    119
  • Rank 297,930 (Top 6 %)
  • Language
    Clojure
  • Created over 11 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Clojure library for JSON Web Token(JWT)

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)))

You can specify algorithm name (OPTIONAL) for more secure verification.

(ns foo
  (:require
    [clj-jwt.core  :refer :all]))

;; verify with specified algorithm
(let [key   "secret"
      token (-> {:foo "bar"} jwt (sign :HS256 key) to-str)]
  (-> token str->jwt (verify :HS256 key)) ;; => true
  (-> token str->jwt (verify :none key))) ;; => false

Decode

(ns foo
  (:require
    [clj-jwt.core  :refer :all]))

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

;; decode plain JWT
(let [token (-> claim jwt to-str)]
  (println (-> token str->jwt :claims)))

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

License

Copyright ยฉ 2015 uochan

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

More Repositories

1

vim-iced

Clojure Interactive Development Environment for Vim8/Neovim
Vim Script
490
star
2

antq

Point out your outdated dependencies.
Clojure
334
star
3

misaki

Jekyll inspired static site generator in Clojure
Clojure
319
star
4

dad

Small configuration management tool for Clojure
Clojure
123
star
5

jubot

Chatbot framework in Clojure
Clojure
68
star
6

build.edn

Make your Clojure library build process easy.
Clojure
63
star
7

merr

๐Ÿ”ฅ Minimal and good enough error handling library for Clojure/ClojureScript
Clojure
48
star
8

cuma

Extensible micro template engine for Clojure
Clojure
31
star
9

testdoc

Yet another doctest implementation in Clojure
Clojure
25
star
10

vivi.vim

Support to setup Elixir development environment in Vim.
Vim Script
22
star
11

babashka-test-action

Github Action to run clojure.test by Babashka
Clojure
14
star
12

clj-xmas

๐ŸŽ„ ๐ŸŽ„ ๐ŸŽ„
Clojure
14
star
13

iced-nrepl

nREPL middleware to support vim-iced.
Clojure
13
star
14

vim-iced-coc-source

vim-iced plugin for completing with coc.nvim
Vim Script
13
star
15

clj-gravatar

gravatar api wrapper for clojure
Clojure
9
star
16

vim-iced-fern-debugger

vim-iced debugging plugin powered by fern.vim
Vim Script
9
star
17

thrempl

A proof of concept for simple template engine using threading macros
Clojure
9
star
18

clj-vimhelp

Vim help file parser/convertor written by Clojure
Clojure
8
star
19

kaocha-nrepl

nREPL middleware for kaocha
Clojure
8
star
20

docker-asciidoctor-jp

Makefile
7
star
21

clj-text-decoration

Text decoration library
Clojure
7
star
22

frontmatter

Parse front matter from a file
Clojure
6
star
23

corne

Commandline argument parser for Common Lisp
Common Lisp
6
star
24

dps-parinfer

WIP
TypeScript
5
star
25

shelltest

Shell testing tool inspired by doctest.
Go
5
star
26

vim-iced-kaocha

vim-iced plugin for testing with kaocha
Vim Script
5
star
27

selenium-ide-pretty-report

JavaScript
5
star
28

ddu-source-custom-list

Custom list source for ddu.vim
TypeScript
5
star
29

gauche

source for gauche
Scheme
4
star
30

antq-action

Shell
4
star
31

deno-nrepl-client

TypeScript
4
star
32

clj-password-check

password checker library for clojure
Clojure
4
star
33

vim-textimer

Text based timer vim plugin heaviliy inspired by Efforless.
Vim Script
4
star
34

rewrite-indented

Clojure
4
star
35

vim-iced-project-namespaces

vim-iced plugin to jump to namespace in your project
Vim Script
4
star
36

liquidz

Clojure
4
star
37

lein-vim

vim plugin for leiningen
Vim Script
4
star
38

vim-icedon

TypeScript
4
star
39

misaki-markdown

Markdown Compiler for Misaki
Clojure
4
star
40

opera-widgets

source code for opera widgets
JavaScript
3
star
41

dotfiles

Vim Script
3
star
42

default

default repository
3
star
43

vimfiler-sendto

sendto plugin for vimfiler
Vim Script
3
star
44

misaki-clostache

misaki compiler using Clostache
Clojure
3
star
45

vim-iced-multi-session

vim-iced plugin to add support for multi session
Vim Script
3
star
46

template-scala-gae

scala project template for google app engine
Scala
3
star
47

pod-uochan-tarayo

Clojure
3
star
48

vim-iced-ddc-source

vim-iced plugin for completing with ddc.vim
TypeScript
3
star
49

debug-reader

Gauche like debug print reader
Clojure
3
star
50

liquidz.github.com

Clojure
3
star
51

Titanium-BookMemo

JavaScript
2
star
52

deno-bencode

Bencode decoder/encode for Deno
TypeScript
2
star
53

heroku-template

Clojure
2
star
54

neelm

Clojure
2
star
55

_dead_repo_pipette_

new_data = pipette(data, template)
Elixir
2
star
56

vim-iced-neil

vim-iced plugin to add support for babashka/neil
Vim Script
2
star
57

yuruyomi

lazy management tool for reading books
Clojure
2
star
58

lein-autotest-notify

leiningen plugin for auto testing and notifying test result with growl
Clojure
2
star
59

unitaskpapera

task paper clone for opera unite
JavaScript
2
star
60

lp

Lazy Presentation Tool
JavaScript
2
star
61

docker-heroku-toolbelt

Shell
2
star
62

namakemono

lazy language "NAMAKEMONO"
C
2
star
63

vim-iced-function-list

Vim Script
1
star
64

collepi

Clojure
1
star
65

plojuctor

presentation tool in clojure repl
Clojure
1
star
66

unite-bookmark-file

Vim Script
1
star
67

practical-compojure-sample

Clojure
1
star
68

family-bot

Elixir
1
star
69

kininaru-hon

Clojure
1
star
70

vim-elin

Clojure
1
star
71

clojure-twitter

twitter4j wrapper for clojure
Clojure
1
star
72

vim-iced-asyncomplete

vim-iced plugin for completing with asyncomplete.vim
Vim Script
1
star
73

vim-colors-uochan

Vim Script
1
star
74

favook

JavaScript
1
star
75

digitalocean

Makefile
1
star
76

kansobun

Clojure
1
star
77

clj-error-checker

Clojure
1
star
78

testframework

library package to build web application easily
Clojure
1
star
79

clojure-ical

icalendar library for clojure
Clojure
1
star
80

clj-htmltpl

Clojure
1
star
81

vim-file-to-file

A vim plugin to write part of a file to a separete file
Vim Script
1
star
82

unite-circleci

Unite candidates for CircleCI
Vim Script
1
star
83

cl-docset-generator

Common Lisp
1
star
84

clojure-simply

write clojure code more simply
Clojure
1
star
85

nrepl-json

nREPL JSON Transport
Clojure
1
star
86

clj-digest

digest functions for clojure
Clojure
1
star
87

jubot-sample

Clojure
1
star
88

clj-spymemcached

simple spymemcached wrapper
Clojure
1
star
89

mixi_app_test

JavaScript
1
star
90

clj-pretty-error

Library to controll exception and stack traces for Clojure
Clojure
1
star
91

smile-celtic

Clojure
1
star
92

lt-note

JavaScript
1
star
93

collepi-android

Java
1
star
94

hello-nrepl-middleware

Clojure
1
star
95

clj-path

Clojure
1
star
96

dps-paredit

TypeScript
1
star
97

docker-jupyter

Makefile
1
star
98

norosi

WIP: Notification, work logging, and etc.
Clojure
1
star