Created
May 2, 2018 14:53
-
-
Save jmkoni/63114562c67a371db1297877f47fe6fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.json4s.DefaultFormats | |
import org.json4s.jackson.JsonMethods.parse | |
import pdi.jwt.{Jwt, JwtAlgorithm} | |
import scala.util.Try | |
/* | |
* This object decodes JWTs that are created by another application. | |
* There are a few different options available for parsing JWTs and I went with: | |
* http://pauldijou.fr/jwt-scala/samples/jwt-core/ | |
*/ | |
object JWT { | |
implicit val formats = DefaultFormats | |
def parseUserJwt(token: String): Try[UserTokenData] = { | |
for { | |
decoded <- Jwt.decode(token, | |
Configuration.SecretKey, | |
Seq(JwtAlgorithm.HS256)) // this will return a string | |
userTokenData = parse(decoded).extract[Token].data // this parses the string to JSON and extracts to a token | |
} yield userTokenData | |
} | |
} | |
case class Token(data: UserTokenData, exp: Int, iat: Int, iss: String) | |
case class UserTokenData(email: String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment