Skip to content

ksarath/scala-jwt-token-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JWT Token Sample in Scala

Using iain-logan jwt library.

Usage

Creating a JWT token generator

object jwtTokenGen extends JWT {
    override protected def secret: String = "my-signature-key"
    override protected def issuer: String = "jwt-token-sample-app"
}

Creating private headers and claims

case class PrivateClaim(value: String) extends ClaimValue {
  override val field: ClaimField = PrivateClaim
  override val jsValue: JsValue = JsString(value)
}

object PrivateClaim extends ClaimField {
  override def attemptApply(value: JsValue): Option[ClaimValue] = value.asOpt[String].map(apply)
  override val name: String = "claim_field_name"
}

Generating a JWT token

val jwtToken = jwtTokenGen.generateToken("token_subject", "target_audience", Seq(PrivateClaim("private claim")), (System.currentTimeMillis + 30000) / 1000)

Validating and decrypting JWT token

jwtTokenGen.validateAndDecryptToken("target_audience", Set(PrivateClaim), jwtToken)

Returns a Jwt wrapped in Success on success, otherwise Failure.

License

This software is licensed under the MIT license, see LICENSE.

About

Scala Jwt Token Example

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages