Giter Site home page Giter Site logo

jwtyped's Introduction

JWTyped

Build Status codecov Maven Central

Opinionated implementation of JWT in scala

  • secure by default (only secure algorithm supported, no none)
  • small api enforcing security
  • typed
  • no external dependencies

Getting Started

Dependencies

libraryDependencies += "com.github.etaty" %% "jwtyped" % "0.1.0"

Usage

// encode
val key = Secret.fromString("secret")
val algorithm = HS256(key)
val header = Header("JWT", "HS256")
val payload = Payload(sub = "1234567890", name = "John Doe", admin = true)
val message = Message.from(header, payload)
val tokenEncoded = JWT.encode(message, algorithm)

// decode
JWT.decode[Header, Payload](tokenEncoded, algorithm)

// or
JWT.decode[Header, Payload](tokenEncoded, { 
  case (Header, Payload) =>
    // you can decide which algorithm you want to use
    Right(algorithm)
})

Algorithms supported

see implemation file

  • HmacSHA*
    • HS256
    • HS384
    • HS512
  • SHA*withRSA
    • RS256
    • RS384
    • RS512
  • SHA*withECDSA
    • ES256
    • ES384
    • ES512

SHA*withECDSA with Bouncy Castle

Dependencies

libraryDependencies += "org.bouncycastle" % "bcpkix-jdk15on" % "1.55"

Add bouncy castle as a provider

import java.security.Security
import org.bouncycastle.jce.provider.BouncyCastleProvider

val BOUNCY_CASTLE_PROVIDER = "BC"

if (Security.getProvider(BOUNCY_CASTLE_PROVIDER) == null) {
  Security.addProvider(new BouncyCastleProvider())
}

jwtyped's People

Contributors

etaty avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  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.