Skip to content

Commit a5629bb

Browse files
MelissaAtPaceMartin Dinh
authored andcommitted
Remove initial access token
1 parent b87756e commit a5629bb

File tree

4 files changed

+8
-38
lines changed

4 files changed

+8
-38
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ clientAppVersion: String
8080
clientAppBuild: String
8181
apiKey: String
8282
clientId: String? // Default: null
83-
accessToken: String? // Default: null
8483
authenticationMode: AuthenticationMode // Default: AuthenticationMode.WEB
8584
environment: Environment // Default: Environment.PRODUCTION
8685
extensions: List<String> // Default: emptyList()
@@ -520,7 +519,7 @@ Some of our services (e.g. `PayPal`) do not open the URL in the WebView, but in
520519
### Native login
521520
If the client app uses its own login and wants to pass an access token to the apps, follow these steps:
522521

523-
1. Initialize the `PACECloudSDK` with `authenticationMode = AuthenticationMode.NATIVE` and an optional start `accessToken = "Your access token"`.
522+
1. Initialize the `PACECloudSDK` with `authenticationMode = AuthenticationMode.NATIVE`
524523
2. Pass an `AppCallbackImpl` instance to `AppKit.openApps(...)` or `AppKit.openAppActivity(...)` and override the required callbacks (`onTokenInvalid(onResult: (String) -> Unit) {}` in this case)
525524
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
526525
in an endless loop. Make sure to clean up all the app related views as well (see [Removal of Apps](#removal-of-apps)).

library/src/main/java/cloud/pace/sdk/PACECloudSDK.kt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,4 @@ object PACECloudSDK {
4141
configuration.locationAccuracy = locationAccuracy
4242
}
4343
}
44-
45-
internal fun setAccessToken(accessToken: String?) {
46-
if (::configuration.isInitialized) {
47-
configuration.accessToken = accessToken
48-
AppKit.updateUserAgent()
49-
}
50-
}
51-
52-
internal fun resetAccessToken() {
53-
if (::configuration.isInitialized) {
54-
configuration.accessToken = null
55-
}
56-
}
5744
}

library/src/main/java/cloud/pace/sdk/appkit/app/webview/AppWebViewModel.kt

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ class AppWebViewModelImpl(
122122
}
123123

124124
override fun handleInvalidToken(message: String) {
125-
val initialToken = PACECloudSDK.configuration.accessToken
126-
if (initialToken != null && TokenValidator.isTokenValid(initialToken)) {
127-
PACECloudSDK.resetAccessToken()
128-
newToken.value = Event(initialToken)
129-
} else {
130-
sendOnTokenInvalid(message)
125+
appModel.onTokenInvalid { token ->
126+
if (TokenValidator.isTokenValid(token)) {
127+
newToken.value = Event(token)
128+
} else {
129+
handleInvalidToken(message)
130+
}
131131
}
132132
}
133133

@@ -141,17 +141,6 @@ class AppWebViewModelImpl(
141141
}
142142
}
143143

144-
private fun sendOnTokenInvalid(message: String) {
145-
appModel.onTokenInvalid { token ->
146-
if (TokenValidator.isTokenValid(token)) {
147-
PACECloudSDK.setAccessToken(token)
148-
newToken.value = Event(token)
149-
} else {
150-
sendOnTokenInvalid(message)
151-
}
152-
}
153-
}
154-
155144
override fun handleVerifyLocation(message: String) {
156145
try {
157146
val verifyLocationRequest = gson.fromJson(message, VerifyLocationRequest::class.java)

library/src/main/java/cloud/pace/sdk/utils/Configuration.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ data class Configuration @JvmOverloads constructor(
66
var clientAppBuild: String,
77
var apiKey: String,
88
var clientId: String? = null,
9-
var accessToken: String? = null,
109
var authenticationMode: AuthenticationMode = AuthenticationMode.WEB,
1110
var environment: Environment = Environment.PRODUCTION,
1211
var extensions: List<String> = emptyList(),
1312
var locationAccuracy: Int? = null
14-
) {
15-
init {
16-
authenticationMode = if (accessToken != null) AuthenticationMode.NATIVE else authenticationMode
17-
}
18-
}
13+
)
1914

2015
enum class AuthenticationMode(val value: String) {
2116
NATIVE("Native"),

0 commit comments

Comments
 (0)