<commit_before>package com.baulsupp.okurl.services.strava

import com.baulsupp.okurl.authenticator.authflow.AuthOption
import com.baulsupp.okurl.authenticator.authflow.Callback
import com.baulsupp.okurl.authenticator.authflow.Prompt
import com.baulsupp.okurl.authenticator.authflow.Scopes
import com.baulsupp.okurl.authenticator.oauth2.Oauth2Flow
import com.baulsupp.okurl.authenticator.oauth2.Oauth2Token
import com.baulsupp.okurl.credentials.ServiceDefinition
import com.baulsupp.okurl.kotlin.form
import com.baulsupp.okurl.kotlin.query
import com.baulsupp.okurl.kotlin.request

data class AuthResponse(
  val token_type: String,
  val access_token: String,
  val athlete: Map<String, Any>?,
  val refresh_token: String,
  val expires_at: Long,
  val state: String? = null
)

class StravaAuthFlow(override val serviceDefinition: ServiceDefinition<Oauth2Token>) : Oauth2Flow(
  serviceDefinition) {
  override fun options(): List<AuthOption<*>> {
    return listOf(
      Prompt("strava.clientId", "Strava Client Id", null, false),
      Prompt("strava.clientSecret", "Strava Client Secret", null, true),
      Scopes("strava.scopes", "Strava Scopes", known = listOf(
        "read_all",
        "profile:read_all",
        "profile:write",
        "activity:read_all",
        "activity:write")),
      Callback
    )
  }

  override suspend fun start(): String {
    val clientId = options["strava.clientId"] as String
    @Suppress("UNCHECKED_CAST") val scopes = options["strava.scopes"] as List<String>
    val callback = options["callback"] as String

    return "https://www.strava.com/oauth/authorize?client_id=$clientId&redirect_uri=${callback}&response_type=code&scope=${scopes.joinToString(
      ",")}"<commit_msg>Define state<commit_after>package com.baulsupp.okurl.services.strava

import com.baulsupp.okurl.authenticator.authflow.AuthOption
import com.baulsupp.okurl.authenticator.authflow.Callback
import com.baulsupp.okurl.authenticator.authflow.Prompt
import com.baulsupp.okurl.authenticator.authflow.Scopes
import com.baulsupp.okurl.authenticator.oauth2.Oauth2Flow
import com.baulsupp.okurl.authenticator.oauth2.Oauth2Token
import com.baulsupp.okurl.credentials.ServiceDefinition
import com.baulsupp.okurl.kotlin.form
import com.baulsupp.okurl.kotlin.query
import com.baulsupp.okurl.kotlin.request

data class AuthResponse(
  val token_type: String,
  val access_token: String,
  val athlete: Map<String, Any>?,
  val refresh_token: String,
  val expires_at: Long,
  val state: String? = null
)

class StravaAuthFlow(override val serviceDefinition: ServiceDefinition<Oauth2Token>) : Oauth2Flow(
  serviceDefinition) {
  override fun options(): List<AuthOption<*>> {
    return listOf(
      Prompt("strava.clientId", "Strava Client Id", null, false),
      Prompt("strava.clientSecret", "Strava Client Secret", null, true),
      Scopes("strava.scopes", "Strava Scopes", known = listOf(
        "read_all",
        "profile:read_all",
        "profile:write",
        "activity:read_all",
        "activity:write")),
      Callback
    )
  }

  override suspend fun start(): String {
    val clientId = options["strava.clientId"] as String
    @Suppress("UNCHECKED_CAST") val scopes = options["strava.scopes"] as List<String>
    val callback = options["callback"] as String
    val state = options["state"] as String

    return "https://www.strava.com/oauth/authorize?client_id=$clientId&redirect_uri=${callback}&response_type=code&scope=${scopes.joinToString(
      ",")}&state=$state"
{'fraction_non_alphanumeric': 0.11861990305104078, 'fraction_numerical': 0.003421727972626176, 'mean_word_length': 4.788778877887789, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '6440804', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1140, 'n_words': 215}