Skip to content

Commit

Permalink
BREAKING CHANGE: incorporated breaking changes planned for v3
Browse files Browse the repository at this point in the history
  • Loading branch information
desusai7 committed Jul 19, 2024
1 parent 1df6b75 commit 8edfbf1
Show file tree
Hide file tree
Showing 14 changed files with 348 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import com.auth0.android.callback.Callback
import com.auth0.android.result.Credentials
import com.auth0.android.util.Clock
import java.util.*
import java.util.concurrent.Executor
import java.util.concurrent.Executors
import kotlin.math.min

/**
* Base class meant to abstract common logic across Credentials Manager implementations.
Expand Down Expand Up @@ -100,6 +97,65 @@ public abstract class DefaultCredentialsManager internal constructor(
minTtl: Int,
callback: Callback<Credentials, CredentialsManagerException>
)

@JvmSynthetic
@Throws(CredentialsManagerException::class)
public abstract suspend fun awaitCredentials(): Credentials

@JvmSynthetic
@Throws(CredentialsManagerException::class)
public abstract suspend fun awaitCredentials(scope: String?, minTtl: Int): Credentials

@JvmSynthetic
@Throws(CredentialsManagerException::class)
public abstract suspend fun awaitCredentials(
scope: String?,
minTtl: Int,
parameters: Map<String, String>
): Credentials

@JvmSynthetic
@Throws(CredentialsManagerException::class)
public abstract suspend fun awaitCredentials(
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
forceRefresh: Boolean
): Credentials

@JvmSynthetic
@Throws(CredentialsManagerException::class)
public abstract suspend fun awaitCredentials(
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
headers: Map<String, String>,
forceRefresh: Boolean
): Credentials

public abstract fun getCredentials(
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
callback: Callback<Credentials, CredentialsManagerException>
)

public abstract fun getCredentials(
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
forceRefresh: Boolean,
callback: Callback<Credentials, CredentialsManagerException>
)

public abstract fun getCredentials(
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
headers: Map<String, String>,
forceRefresh: Boolean,
callback: Callback<Credentials, CredentialsManagerException>
)
}

public abstract class SecuredCredentialsManager internal constructor(
Expand All @@ -109,6 +165,96 @@ public abstract class SecuredCredentialsManager internal constructor(
) : BaseCredentialsManager(
authenticationClient, storage, jwtDecoder
) {
public abstract fun getCredentials(fragmentActivity: FragmentActivity, authenticationOptions: LocalAuthenticationOptions, callback: Callback<Credentials, CredentialsManagerException>)
public abstract fun getCredentials(fragmentActivity: FragmentActivity, authenticationOptions: LocalAuthenticationOptions, scope: String?, minTtl: Int, callback: Callback<Credentials, CredentialsManagerException>)
public abstract fun getCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
callback: Callback<Credentials, CredentialsManagerException>
)

public abstract fun getCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String?,
minTtl: Int,
callback: Callback<Credentials, CredentialsManagerException>
)

@JvmSynthetic
@Throws(CredentialsManagerException::class)
public abstract suspend fun awaitCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions
): Credentials

@JvmSynthetic
@Throws(CredentialsManagerException::class)
public abstract suspend fun awaitCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String?,
minTtl: Int
): Credentials

@JvmSynthetic
@Throws(CredentialsManagerException::class)
public abstract suspend fun awaitCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String?,
minTtl: Int,
parameters: Map<String, String>
): Credentials

@JvmSynthetic
@Throws(CredentialsManagerException::class)
public abstract suspend fun awaitCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
forceRefresh: Boolean
): Credentials

@JvmSynthetic
@Throws(CredentialsManagerException::class)
public abstract suspend fun awaitCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
headers: Map<String, String>,
forceRefresh: Boolean
): Credentials

public abstract fun getCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
callback: Callback<Credentials, CredentialsManagerException>
)

public abstract fun getCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
forceRefresh: Boolean,
callback: Callback<Credentials, CredentialsManagerException>
)

public abstract fun getCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String? = null,
minTtl: Int = 0,
parameters: Map<String, String> = emptyMap(),
headers: Map<String, String> = emptyMap(),
forceRefresh: Boolean = false,
callback: Callback<Credentials, CredentialsManagerException>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class CredentialsManager @VisibleForTesting(otherwise = VisibleForTesting
*/
@JvmSynthetic
@Throws(CredentialsManagerException::class)
public suspend fun awaitCredentials(): Credentials {
override suspend fun awaitCredentials(): Credentials {
return awaitCredentials(null, 0)
}

Expand All @@ -76,7 +76,7 @@ public class CredentialsManager @VisibleForTesting(otherwise = VisibleForTesting
*/
@JvmSynthetic
@Throws(CredentialsManagerException::class)
public suspend fun awaitCredentials(scope: String?, minTtl: Int): Credentials {
override suspend fun awaitCredentials(scope: String?, minTtl: Int): Credentials {
return awaitCredentials(scope, minTtl, emptyMap())
}

Expand All @@ -92,7 +92,7 @@ public class CredentialsManager @VisibleForTesting(otherwise = VisibleForTesting
*/
@JvmSynthetic
@Throws(CredentialsManagerException::class)
public suspend fun awaitCredentials(
override suspend fun awaitCredentials(
scope: String?,
minTtl: Int,
parameters: Map<String, String>
Expand All @@ -113,7 +113,7 @@ public class CredentialsManager @VisibleForTesting(otherwise = VisibleForTesting
*/
@JvmSynthetic
@Throws(CredentialsManagerException::class)
public suspend fun awaitCredentials(
override suspend fun awaitCredentials(
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
Expand All @@ -136,7 +136,7 @@ public class CredentialsManager @VisibleForTesting(otherwise = VisibleForTesting
*/
@JvmSynthetic
@Throws(CredentialsManagerException::class)
public suspend fun awaitCredentials(
override suspend fun awaitCredentials(
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
Expand Down Expand Up @@ -200,7 +200,7 @@ public class CredentialsManager @VisibleForTesting(otherwise = VisibleForTesting
* @param parameters additional parameters to send in the request to refresh expired credentials
* @param callback the callback that will receive a valid [Credentials] or the [CredentialsManagerException].
*/
public fun getCredentials(
override fun getCredentials(
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
Expand All @@ -220,7 +220,7 @@ public class CredentialsManager @VisibleForTesting(otherwise = VisibleForTesting
* @param forceRefresh this will avoid returning the existing credentials and retrieves a new one even if valid credentials exist.
* @param callback the callback that will receive a valid [Credentials] or the [CredentialsManagerException].
*/
public fun getCredentials(
override fun getCredentials(
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
Expand All @@ -242,7 +242,7 @@ public class CredentialsManager @VisibleForTesting(otherwise = VisibleForTesting
* @param forceRefresh this will avoid returning the existing credentials and retrieves a new one even if valid credentials exist.
* @param callback the callback that will receive a valid [Credentials] or the [CredentialsManagerException].
*/
public fun getCredentials(
override fun getCredentials(
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.auth0.android.authentication.storage

import android.app.Activity
import android.content.Context
import android.opengl.Visibility
import android.provider.Settings.Secure
import android.text.TextUtils
import android.util.Base64
import android.util.Log
Expand Down Expand Up @@ -114,7 +111,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
*/
@JvmSynthetic
@Throws(CredentialsManagerException::class)
public suspend fun awaitCredentials(
override suspend fun awaitCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions
): Credentials {
Expand All @@ -137,7 +134,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
*/
@JvmSynthetic
@Throws(CredentialsManagerException::class)
public suspend fun awaitCredentials(
override suspend fun awaitCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String?,
Expand All @@ -163,7 +160,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
*/
@JvmSynthetic
@Throws(CredentialsManagerException::class)
public suspend fun awaitCredentials(
override suspend fun awaitCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String?,
Expand Down Expand Up @@ -198,7 +195,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
*/
@JvmSynthetic
@Throws(CredentialsManagerException::class)
public suspend fun awaitCredentials(
override suspend fun awaitCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String?,
Expand Down Expand Up @@ -236,7 +233,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
*/
@JvmSynthetic
@Throws(CredentialsManagerException::class)
public suspend fun awaitCredentials(
override suspend fun awaitCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String?,
Expand Down Expand Up @@ -325,7 +322,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
* @param parameters additional parameters to send in the request to refresh expired credentials
* @param callback the callback to receive the result in.
*/
public fun getCredentials(
override fun getCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String?,
Expand Down Expand Up @@ -361,7 +358,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
* @param forceRefresh this will avoid returning the existing credentials and retrieves a new one even if valid credentials exist.
* @param callback the callback to receive the result in.
*/
public fun getCredentials(
override fun getCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String?,
Expand Down Expand Up @@ -399,14 +396,14 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
* @param forceRefresh this will avoid returning the existing credentials and retrieves a new one even if valid credentials exist.
* @param callback the callback to receive the result in.
*/
public fun getCredentials(
override fun getCredentials(
fragmentActivity: FragmentActivity,
authenticationOptions: LocalAuthenticationOptions,
scope: String? = null,
minTtl: Int = 0,
parameters: Map<String, String> = emptyMap(),
headers: Map<String, String> = emptyMap(),
forceRefresh: Boolean = false,
scope: String?,
minTtl: Int,
parameters: Map<String, String>,
headers: Map<String, String>,
forceRefresh: Boolean,
callback: Callback<Credentials, CredentialsManagerException>
) {

Expand Down
10 changes: 4 additions & 6 deletions auth0/src/main/java/com/auth0/android/request/DefaultClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class DefaultClient @VisibleForTesting(otherwise = VisibleForTesting.PRIV
readTimeout: Int,
private val defaultHeaders: Map<String, String>,
enableLogging: Boolean,
private val gson: Gson,
sslSocketFactory: SSLSocketFactory?,
trustManager: X509TrustManager?
) : NetworkingClient {
Expand All @@ -40,11 +41,8 @@ public class DefaultClient @VisibleForTesting(otherwise = VisibleForTesting.PRIV
connectTimeout: Int = DEFAULT_TIMEOUT_SECONDS,
readTimeout: Int = DEFAULT_TIMEOUT_SECONDS,
defaultHeaders: Map<String, String> = mapOf(),
enableLogging: Boolean = false
) : this(connectTimeout, readTimeout, defaultHeaders, enableLogging, null, null)

//TODO: receive this via internal constructor parameters
private val gson: Gson = GsonProvider.gson
enableLogging: Boolean = false,
) : this(connectTimeout, readTimeout, defaultHeaders, enableLogging, GsonProvider.gson, null, null)

@get:VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal val okHttpClient: OkHttpClient
Expand All @@ -71,6 +69,7 @@ public class DefaultClient @VisibleForTesting(otherwise = VisibleForTesting.PRIV
.map { urlBuilder.addQueryParameter(it.key, it.value as String) }
requestBuilder.method(options.method.toString(), null)
}

else -> {
// add parameters as body
val body = gson.toJson(options.parameters).toRequestBody(APPLICATION_JSON_UTF8)
Expand All @@ -90,7 +89,6 @@ public class DefaultClient @VisibleForTesting(otherwise = VisibleForTesting.PRIV
val builder = OkHttpClient.Builder()

// logging
//TODO: OFF by default!
if (enableLogging) {
val logger: Interceptor = HttpLoggingInterceptor()
.setLevel(HttpLoggingInterceptor.Level.BODY)
Expand Down
Loading

0 comments on commit 8edfbf1

Please sign in to comment.