Giter Club home page Giter Club logo

jwt.el's Introduction

JWT

This provides support for using JWT tokens (rfc7519).

https://tools.ietf.org/html/rfc7519

Example

{
  "iss": "jira:1314039",
  "iat": 1300819370,
  "exp": 1300819380,
  "qsh": "8063ff4ca1e41df7bc90c8ab6d0f6207d491cf6dad7c66ea797b4614b71922e9",
  "sub": "batman",
  "context": {
    "user": {
      "email": "",
      "username": "bwayne",
      "displayName": "Bruce Wayne"
    }
  }
}

Testing

GET http://www.mocky.io/v2/5ba012bf30000012007b147c
X-Auth-Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

Usage

Parse

Verify

(require 'jwt)

(decode-jwt
 (encode-jwt #:iss "joe"
             #:iat #f
             #:exp 1300819380))

Sign

(setq hmac-secret "my$ecretK3y")
$ openssl genrsa -out private.pem 2048
$ openssl rsa -in private.pem -out public.pem -outform PEM -pubout

Resources

Implementations

See https://jwt.io/ for a full list of implementations.

  • JavaScript
const parse = token => JSON.parse(
    window.atob(
        token.split('.')[1]
            .replace('-', '+')
            .replace('_', '/')));
Algorithm algorithm = Algorithm.HMAC256("secret");

String token = JWT.create()
    .withIssuer("auth0")
    .sign(algorithm);

JWTVerifier verifier = JWT.require(algorithm)
        .withIssuer("auth0")
        .build(); //Reusable verifier instance
DecodedJWT jwt = verifier.verify(token);
(def claim
  {:iss "foo"
   :exp (plus (now) (days 1))
   :iat (now)})

(let [token (-> claim jwt (sign :HS256 "secret") to-str)]
  (-> token str->jwt (verify "secret")))
(defvar *key* (ironclad:ascii-string-to-byte-array "my$ecret"))

(defvar *token*
  (jose:encode :hs256 *key* '(("hello" . "world"))))

const token = jwt.sign({ foo: 'bar' }, 'shhhhh');
const decoded = jwt.verify(token, 'shhhhh');
payload = { 'foo': 'bar', 'wup': 90 };
token = jwt.generate_jwt(payload, key, 'PS256', datetime.timedelta(minutes=5))
header, claims = jwt.verify_jwt(token, pub_key, ['RS256'])
let token = encode(&Header::default(), &my_claims, "secret".as_ref())?;
let decoded = decode::<Claims>(&token, "secret".as_ref(), &Validation::default())?;
(decode-jwt
 (encode-jwt #:iss "joe"
             #:iat #f
             #:exp 1300819380))
token = JWT.encode payload, hmac_secret, 'HS256'
token_rsa = JWT.encode payload, rsa_private, 'RS256'
decoded_token = JWT.decode token, hmac_secret, true, { algorithm: 'HS256' }
claim = {
  iss: 'nov',
  exp: 1.week.from_now,
  nbf: Time.now
}
jws = JSON::JWT.new(claim).sign(private_key, :RS256)
  • Go
  • Elixir
  • Haskell
  • Scala

Development

(add-hook 'emacs-lisp-mode-hook 'ert-modeline-mode)

jwt.el's People

Watchers

Jason Walsh avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.