<commit_before>package io.flow.play.controllers

import org.apache.commons.codec.binary.Base64

import authentikat.jwt._

object BasicAuthorization {

  trait Authorization
  case class Token(token: String) extends Authorization
  case class JWTToken(userId: String) extends Authorization

  def get(value: Option[String]): Option[Authorization] = {
    value.flatMap { get }
  }

  /**
    * Parses the actual authorization header value. Acceptable types are:
    * - Basic - the API Token for the user.
    * - Bearer - the JWT Token for the user with that contains an id field representing the user id in the database
   */
  def get(headerValue: String): Option[Authorization] = {
    headerValue.split(" ").toList match {
      case "Basic" :: value :: Nil => {
        new String(Base64.decodeBase64(value.getBytes)).split(":").toList match {
          case Nil => None
          case token :: rest => Some(Token(token))
        }
      }

      case "Bearer" :: value :: Nil => {
        value match {
          case JsonWebToken(header, claimsSet, signature) => createJWTToken(claimsSet)
          case _ => None
        }
      }
      case _ => None
    }
  }

  private[this] def createJWTToken(claimsSet: JwtClaimsSetJValue): Option[JWTToken] = {
    claimsSet.asSimpleMap.toOption match {
      case Some(claims) =>
        println(s"got claims! ${claims}")
        claims.get("id").map(JWTToken)
      case _ => {
        println("got nothing back?")
        None
      }
    }
  }

}<commit_msg>remove printlns<commit_after>package io.flow.play.controllers

import org.apache.commons.codec.binary.Base64

import authentikat.jwt._

object BasicAuthorization {

  trait Authorization
  case class Token(token: String) extends Authorization
  case class JWTToken(userId: String) extends Authorization

  def get(value: Option[String]): Option[Authorization] = {
    value.flatMap { get }
  }

  /**
    * Parses the actual authorization header value. Acceptable types are:
    * - Basic - the API Token for the user.
    * - Bearer - the JWT Token for the user with that contains an id field representing the user id in the database
   */
  def get(headerValue: String): Option[Authorization] = {
    headerValue.split(" ").toList match {
      case "Basic" :: value :: Nil => {
        new String(Base64.decodeBase64(value.getBytes)).split(":").toList match {
          case Nil => None
          case token :: rest => Some(Token(token))
        }
      }

      case "Bearer" :: value :: Nil => {
        value match {
          case JsonWebToken(header, claimsSet, signature) => createJWTToken(claimsSet)
          case _ => None
        }
      }
      case _ => None
    }
  }

  private[this] def createJWTToken(claimsSet: JwtClaimsSetJValue): Option[JWTToken] =
    claimsSet.asSimpleMap.toOption match {
      case Some(claims) => claims.get("id").map(JWTToken)
      case _ => None
    }
}
{'fraction_non_alphanumeric': 0.11099656357388316, 'fraction_numerical': 0.004123711340206186, 'mean_word_length': 2.727272727272727, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6197766', 'n_tokens_mistral': 881, 'n_tokens_neox': 863, 'n_words': 231}