All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fortysevendeg.intools.jwt.models.JWTTokenRaw.scala Maven / Gradle / Ivy

There is a newer version: 0.0.13
Show newest version
package com.fortysevendeg.intools.jwt.models

import scala.util.matching.Regex
import com.fortysevendeg.intools.jwt.models.Types.{JWTClaim, JWTHeader, JWTSignature}

final case class JWTTokenRaw private (jwtHeader: JWTHeader, jwtClaim: JWTClaim, jwtSigantureOpt: Option[JWTSignature])

object JWTTokenRaw:
  private val jwtRegex: Regex = "^([A-Za-z0-9-_=]+)\\.([A-Za-z0-9-_=]+)\\.?([A-Za-z0-9-_+/=]*)$".r

  def fromString: String => Option[JWTTokenRaw] = _ match {
    case jwtRegex(header, claim, signature) =>
      val sign = if signature == "" then None else Some(JWTSignature(signature))
      Some(JWTTokenRaw(JWTHeader(header), JWTClaim(claim), sign))
    case _                                  => None
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy