Giter VIP home page Giter VIP logo

jsonwebtokens.jl's Introduction

JSONWebTokens.jl

License CI codecov

Secure your Julia APIs with JWT.

Requirements

Julia v1.3 or later.

Installation

julia> import Pkg; Pkg.add("JSONWebTokens")

Usage

For HMAC RSA Algorithms

Encode:

import JSONWebTokens
claims_dict = Dict( "sub" => "1234567890", "name" => "John Doe", "iat" => 1516239022)
encoding = JSONWebTokens.HS256("secretkey") # select HS256 encoding
jwt = JSONWebTokens.encode(encoding, claims_dict)
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJzdWIiOiIxMjM0NTY3ODkwIiwiaWF0IjoxNTE2MjM5MDIyfQ.TjUTSL0RQayQG-y_h2Tl3FmAgxhC0fYtmeiU7jnMdXY"

Decode:

JSONWebTokens.decode(encoding, jwt)
Dict{String,Any} with 3 entries:
  "name" => "John Doe"
  "sub"  => "1234567890"
  "iat"  => 1516239022

For RSASSA RSA Algorithms

First, generate public and private keys. You can use openssl.

$ openssl genrsa -out private.pem 2048
$ openssl rsa -in private.pem -out public.pem -outform PEM -pubout

Use the private key to encode.

import JSONWebTokens
claims_dict = Dict( "sub" => "1234567890", "name" => "John Doe", "iat" => 1516239022)
rsa_private = JSONWebTokens.RS256("private.pem") # accepts a filepath, string or base64 encoded string
jwt = JSONWebTokens.encode(rsa_private, claims_dict)
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UiLCJzdWIiOiIxMjM0NTY3ODkwIiwiaWF0IjoxNTE2MjM5MDIyfQ.HUXm8CAiY9EKX3dU1Ym7bZvL7yXMu3TC9iL1do0jvM0oD2rSqY5K06KmQy1qJETYZAIZIgA6ZrX2Q3ug01DVu-Yf1Kx3-OpC39eYuBGH-7P1QgwEcizbh6dw07LGC-xshru1v_tKi9IaogiitnEMLLeGdOuCTtYw2gDRjACq2L2UiJTAgurZ_yxE3cMApo492leubNo9fADtRPpofy37Q2VivfS4XwlTkS9Bxg6jrkBhTr-ieuiBx_kAmk2Zps5f9ih-aNPXi_3p5tNH-8LUMJ5L2CTb6Ui1ghyElI7k8wfXzQIm0fGRiQu9OBnqgm2Bh9AivquXXeX6JQGxyntDqA"

Use the public key to decode.

rsa_public = JSONWebTokens.RS256("public.pem") # accepts a filepath, string or base64 encoded string
JSONWebTokens.decode(rsa_public, jwt)
Dict{String,Any} with 3 entries:
  "name" => "John Doe"
  "sub"  => "1234567890"
  "iat"  => 1516239022

Supported Algorithms

  • HS256

  • HS384

  • HS512

  • RS256

  • RS384

References

jsonwebtokens.jl's People

Contributors

abhimanyuaryan avatar dilumaluthge avatar felipenoris 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.