<commit_before>package services.auth.providers

import play.api._
import play.api.mvc._
import services.auth._
import play.api.mvc.WithHeaders
import models.user.ProviderUser
import play.api.libs.concurrent.futureToPlayPromise
import models.user.SkimboToken

object LinkedIn extends OAuthProvider {

  override val name = "linkedin"
  override val namespace = "li"
  override val permissions = Seq(
    "r_fullprofile", // Get User details
    "r_emailaddress", // Get User email
    "rw_nus")         // Get Network activities
  override val permissionsSep = "+"

  // Override fetch method : define json format by default
  override def fetch(idUser: String, url: String) =
    super.fetch(idUser, url).withHeaders("x-li-format" -> "json")

  override def isInvalidToken(idUser:String, response: play.api.libs.ws.Response): Boolean = 
    response.status == 423
    
  override def distantUserToSkimboUser(idUser: String, response: play.api.libs.ws.Response): Option[ProviderUser] = {
    try {
      val me = response.json
      val id = (me \ "id").as[String]
      val fname = (me \ "firstName").asOpt[String]
      val lname = (me \ "lastName").asOpt[String]
      val displayName = Some(fname.getOrElse("") + " " + lname.getOrElse(""))<commit_msg>add 403 http code for linkedin invalid token<commit_after>package services.auth.providers

import play.api._
import play.api.mvc._
import services.auth._
import play.api.mvc.WithHeaders
import models.user.ProviderUser
import play.api.libs.concurrent.futureToPlayPromise
import models.user.SkimboToken

object LinkedIn extends OAuthProvider {

  override val name = "linkedin"
  override val namespace = "li"
  override val permissions = Seq(
    "r_fullprofile", // Get User details
    "r_emailaddress", // Get User email
    "rw_nus")         // Get Network activities
  override val permissionsSep = "+"

  // Override fetch method : define json format by default
  override def fetch(idUser: String, url: String) =
    super.fetch(idUser, url).withHeaders("x-li-format" -> "json")

  override def isInvalidToken(idUser:String, response: play.api.libs.ws.Response): Boolean = 
    response.status == 423 || response.status == 403
    
  override def distantUserToSkimboUser(idUser: String, response: play.api.libs.ws.Response): Option[ProviderUser] = {
    try {
      val me = response.json
      val id = (me \ "id").as[String]
      val fname = (me \ "firstName").asOpt[String]
      val lname = (me \ "lastName").asOpt[String]
      val displayName = Some(fname.getOrElse("") + " " + lname.getOrElse(""))
{'fraction_non_alphanumeric': 0.1189083820662768, 'fraction_numerical': 0.004678362573099415, 'mean_word_length': 3.673952641165756, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1447630', 'n_tokens_mistral': 805, 'n_tokens_neox': 772, 'n_words': 206}