diff --git a/README.md b/README.md index 002ac711..11f0c7e1 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,6 @@ clientAppVersion: String clientAppBuild: String apiKey: String clientId: String? // Default: null -accessToken: String? // Default: null authenticationMode: AuthenticationMode // Default: AuthenticationMode.WEB environment: Environment // Default: Environment.PRODUCTION extensions: List // Default: emptyList() @@ -520,7 +519,7 @@ Some of our services (e.g. `PayPal`) do not open the URL in the WebView, but in ### Native login If the client app uses its own login and wants to pass an access token to the apps, follow these steps: -1. Initialize the `PACECloudSDK` with `authenticationMode = AuthenticationMode.NATIVE` and an optional start `accessToken = "Your access token"`. +1. Initialize the `PACECloudSDK` with `authenticationMode = AuthenticationMode.NATIVE` 2. Pass an `AppCallbackImpl` instance to `AppKit.openApps(...)` or `AppKit.openAppActivity(...)` and override the required callbacks (`onTokenInvalid(onResult: (String) -> Unit) {}` in this case) 3. If the access token is invalid, the *AppKit* calls the `onTokenInvalid` function. The client app needs to call the `onResult` function to set a new access token. In case that you can't retrieve a new valid token, don't call `onResult`, otherwise you will most likely end up in an endless loop. Make sure to clean up all the app related views as well (see [Removal of Apps](#removal-of-apps)). diff --git a/library/src/main/java/cloud/pace/sdk/PACECloudSDK.kt b/library/src/main/java/cloud/pace/sdk/PACECloudSDK.kt index 5450bde0..c42bc95b 100644 --- a/library/src/main/java/cloud/pace/sdk/PACECloudSDK.kt +++ b/library/src/main/java/cloud/pace/sdk/PACECloudSDK.kt @@ -41,17 +41,4 @@ object PACECloudSDK { configuration.locationAccuracy = locationAccuracy } } - - internal fun setAccessToken(accessToken: String?) { - if (::configuration.isInitialized) { - configuration.accessToken = accessToken - AppKit.updateUserAgent() - } - } - - internal fun resetAccessToken() { - if (::configuration.isInitialized) { - configuration.accessToken = null - } - } } diff --git a/library/src/main/java/cloud/pace/sdk/appkit/app/webview/AppWebViewModel.kt b/library/src/main/java/cloud/pace/sdk/appkit/app/webview/AppWebViewModel.kt index c76c1abd..4b8697ff 100644 --- a/library/src/main/java/cloud/pace/sdk/appkit/app/webview/AppWebViewModel.kt +++ b/library/src/main/java/cloud/pace/sdk/appkit/app/webview/AppWebViewModel.kt @@ -122,12 +122,12 @@ class AppWebViewModelImpl( } override fun handleInvalidToken(message: String) { - val initialToken = PACECloudSDK.configuration.accessToken - if (initialToken != null && TokenValidator.isTokenValid(initialToken)) { - PACECloudSDK.resetAccessToken() - newToken.value = Event(initialToken) - } else { - sendOnTokenInvalid(message) + appModel.onTokenInvalid { token -> + if (TokenValidator.isTokenValid(token)) { + newToken.value = Event(token) + } else { + handleInvalidToken(message) + } } } @@ -141,17 +141,6 @@ class AppWebViewModelImpl( } } - private fun sendOnTokenInvalid(message: String) { - appModel.onTokenInvalid { token -> - if (TokenValidator.isTokenValid(token)) { - PACECloudSDK.setAccessToken(token) - newToken.value = Event(token) - } else { - sendOnTokenInvalid(message) - } - } - } - override fun handleVerifyLocation(message: String) { try { val verifyLocationRequest = gson.fromJson(message, VerifyLocationRequest::class.java) diff --git a/library/src/main/java/cloud/pace/sdk/utils/Configuration.kt b/library/src/main/java/cloud/pace/sdk/utils/Configuration.kt index 09920da6..e8101044 100644 --- a/library/src/main/java/cloud/pace/sdk/utils/Configuration.kt +++ b/library/src/main/java/cloud/pace/sdk/utils/Configuration.kt @@ -6,16 +6,11 @@ data class Configuration @JvmOverloads constructor( var clientAppBuild: String, var apiKey: String, var clientId: String? = null, - var accessToken: String? = null, var authenticationMode: AuthenticationMode = AuthenticationMode.WEB, var environment: Environment = Environment.PRODUCTION, var extensions: List = emptyList(), var locationAccuracy: Int? = null -) { - init { - authenticationMode = if (accessToken != null) AuthenticationMode.NATIVE else authenticationMode - } -} +) enum class AuthenticationMode(val value: String) { NATIVE("Native"),