jwt-simple - JWT(JSON Web Token) encode and decode module.
JWT(JSON Web Token) encode and decode module.
$ sbt clean publish-local
Before running the tests the first time, you must ensure the npm packages are installed:
$ npm install
Then you can run the tests:
$ sbt test
import io.scalajs.JSON
import io.scalajs.npm.jwtsimple._
import scala.scalajs.js
val payload = js.Dictionary("foo" -> "bar")
val secret = "scalajs"
// encode
val token = JwtSimple.encode(payload, secret)
println(s"token: $token") //=> eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIifQ.GmVaWnUkI1glyMfggMz6u4T-8I5KPfk8Kmc4PxKJz50
// decode
val decoded = JwtSimple.decode(token, secret)
println(s"payload: ${JSON.stringify(decoded)}") //=> { foo: "bar" }
To add the JwtSimple
binding to your project, add the following to your build.sbt:
libraryDependencies += "io.scalajs.npm" %%% "jwt-simple" % "0.5.0"
Optionally, you may add the Sonatype Repository resolver:
resolvers += Resolver.sonatypeRepo("releases")