diff --git a/src/main/scala/authentikat/jwt/JwtHeader.scala b/src/main/scala/authentikat/jwt/JwtHeader.scala index b57a9c8..7e65b1f 100644 --- a/src/main/scala/authentikat/jwt/JwtHeader.scala +++ b/src/main/scala/authentikat/jwt/JwtHeader.scala @@ -2,22 +2,27 @@ package authentikat.jwt import org.json4s._ import org.json4s.jackson.JsonMethods._ -import org.json4s.jackson.Serialization -import util.control.Exception.allCatch +import scala.util.control.Exception.allCatch -case class JwtHeader(algorithm: Option[String], - contentType: Option[String], - typ: Option[String]) { +case class JwtHeader( + algorithm: Option[String], + contentType: Option[String], + typ: Option[String] + ) { def asJsonString: String = { val toSerialize = - algorithm.map(x ⇒ ("alg", x)).toSeq ++ - contentType.map(x ⇒ ("cty", x)).toSeq ++ - typ.map(x ⇒ ("typ", x)).toSeq + algorithm.map(x => ("alg" -> x)).toSeq ++ + contentType.map(x => ("cty", x)).toSeq ++ + typ.map(x => ("typ", x)).toSeq + val map = toSerialize.toMap + + import org.json4s.native.Serialization.write implicit val formats = org.json4s.DefaultFormats - org.json4s.jackson.Serialization.write(toSerialize) + + write(map) } } @@ -27,7 +32,7 @@ object JwtHeader { implicit val formats = DefaultFormats - def apply(algorithm: String = null, contentType: String = null, typ: String = "JWT"): JwtHeader = { + def apply(algorithm: String, contentType: String = null, typ: String = "JWT"): JwtHeader = { JwtHeader(Option(algorithm), Option(contentType), Option(typ)) } @@ -44,4 +49,4 @@ object JwtHeader { def fromJsonStringOpt(jsonString: String): Option[JwtHeader] = allCatch opt { fromJsonString(jsonString) } -} +} \ No newline at end of file diff --git a/src/test/scala/authentikat/jwt/JsonWebTokenSpec.scala b/src/test/scala/authentikat/jwt/JsonWebTokenSpec.scala index 3798c38..176cd1f 100644 --- a/src/test/scala/authentikat/jwt/JsonWebTokenSpec.scala +++ b/src/test/scala/authentikat/jwt/JsonWebTokenSpec.scala @@ -17,6 +17,9 @@ class JsonWebTokenSpec extends FunSpec with Matchers { it("should have three parts for a token created with claims map claims") { val result = JsonWebToken.apply(header, claims, "secretkey") + println(result) + println(result) + println(result) result.split("\\.").length should equal(3) } @@ -88,6 +91,7 @@ class JsonWebTokenSpec extends FunSpec with Matchers { describe("JwtHeader") { it("should render to json as per spec") { val header = JwtHeader("algorithm", "contentType") + println(header.asJsonString) val expectedJson = "{\"alg\":\"algorithm\",\"cty\":\"contentType\",\"typ\":\"JWT\"}" header.asJsonString should equal(expectedJson) @@ -97,7 +101,7 @@ class JsonWebTokenSpec extends FunSpec with Matchers { describe("JwtClaimsSet") { val date = new Date - val dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'") + val dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")) val dateIso8601 = dateFormat.format(date) diff --git a/version.sbt b/version.sbt index 3f81713..cfa5eb7 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version := "0.4.4" +version := "0.4.5"