Skip to content

Commit

Permalink
Merge branch '47-remove-initial-access-token' into 'master'
Browse files Browse the repository at this point in the history
Resolve "Remove initial access token"

Closes #47

See merge request pace/mobile/android/pace-cloud-sdk!42
  • Loading branch information
Martin Dinh committed Feb 11, 2021
2 parents b87756e + a5629bb commit 2fb1983
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 38 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> // Default: emptyList()
Expand Down Expand Up @@ -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)).
Expand Down
13 changes: 0 additions & 13 deletions library/src/main/java/cloud/pace/sdk/PACECloudSDK.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand All @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions library/src/main/java/cloud/pace/sdk/utils/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = emptyList(),
var locationAccuracy: Int? = null
) {
init {
authenticationMode = if (accessToken != null) AuthenticationMode.NATIVE else authenticationMode
}
}
)

enum class AuthenticationMode(val value: String) {
NATIVE("Native"),
Expand Down

0 comments on commit 2fb1983

Please sign in to comment.