jwtyped


License

License

GroupId

GroupId

com.github.etaty
ArtifactId

ArtifactId

jwtyped_2.11
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

jwtyped
jwtyped
Project URL

Project URL

https://github.com/etaty/jwtyped
Project Organization

Project Organization

com.github.etaty
Source Code Management

Source Code Management

https://github.com/etaty/jwtyped

Download jwtyped_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.etaty/jwtyped_2.11/ -->
<dependency>
    <groupId>com.github.etaty</groupId>
    <artifactId>jwtyped_2.11</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.etaty/jwtyped_2.11/
implementation 'com.github.etaty:jwtyped_2.11:0.1.0'
// https://jarcasting.com/artifacts/com.github.etaty/jwtyped_2.11/
implementation ("com.github.etaty:jwtyped_2.11:0.1.0")
'com.github.etaty:jwtyped_2.11:jar:0.1.0'
<dependency org="com.github.etaty" name="jwtyped_2.11" rev="0.1.0">
  <artifact name="jwtyped_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.etaty', module='jwtyped_2.11', version='0.1.0')
)
libraryDependencies += "com.github.etaty" % "jwtyped_2.11" % "0.1.0"
[com.github.etaty/jwtyped_2.11 "0.1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.8

provided (2)

Group / Artifact Type Version
org.scoverage : scalac-scoverage-runtime_2.11 jar 1.1.1
org.scoverage : scalac-scoverage-plugin_2.11 jar 1.1.1

test (6)

Group / Artifact Type Version
io.circe : circe-core_2.11 jar 0.5.4
io.circe : circe-generic_2.11 jar 0.5.4
io.circe : circe-parser_2.11 jar 0.5.4
org.specs2 : specs2-core_2.11 jar 3.8.6
org.specs2 : specs2-scalacheck_2.11 jar 3.8.6
org.bouncycastle : bcpkix-jdk15on jar 1.55

Project Modules

There are no modules declared in this project.

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

Versions

Version
0.1.0