@@ -12,6 +12,7 @@ import com.auth0.android.request.JsonAdapter
1212import com.auth0.android.request.NetworkingClient
1313import com.auth0.android.request.Request
1414import com.auth0.android.request.RequestOptions
15+ import com.auth0.android.request.RequestValidator
1516import com.auth0.android.request.ServerResponse
1617import kotlinx.coroutines.CoroutineDispatcher
1718import kotlinx.coroutines.Dispatchers
@@ -40,6 +41,8 @@ internal open class BaseRequest<T, U : Auth0Exception>(
4041
4142 private val options: RequestOptions = RequestOptions (method)
4243
44+ private val validators = mutableListOf<RequestValidator >()
45+
4346 override fun addHeader (name : String , value : String ): Request <T , U > {
4447 options.headers[name] = value
4548 return this
@@ -70,6 +73,11 @@ internal open class BaseRequest<T, U : Auth0Exception>(
7073 return this
7174 }
7275
76+ override fun addValidator (validator : RequestValidator ): Request <T , U > {
77+ validators.add(validator)
78+ return this
79+ }
80+
7381 /* *
7482 * Runs asynchronously and executes the network request, without blocking the current thread.
7583 * The result is parsed into a <T> value and posted in the callback's onSuccess method or a <U>
@@ -126,6 +134,7 @@ internal open class BaseRequest<T, U : Auth0Exception>(
126134 */
127135 @kotlin.jvm.Throws (Auth0Exception ::class )
128136 override fun execute (): T {
137+ runClientValidation()
129138 val response: ServerResponse
130139 try {
131140 if (dPoP?.shouldGenerateProof(url, options.parameters) == true ) {
@@ -176,4 +185,10 @@ internal open class BaseRequest<T, U : Auth0Exception>(
176185 }
177186 }
178187
188+ private fun runClientValidation () {
189+ validators.forEach { validator ->
190+ validator.validate(options)
191+ }
192+ }
193+
179194}
0 commit comments