From f7bdf2a10ecd54ccabd8415b2e46ba803fa49126 Mon Sep 17 00:00:00 2001 From: Stefano Russello Date: Tue, 17 Oct 2023 14:48:21 +0200 Subject: [PATCH] SCD-101 Token Custom SSO SCD-101 Token Custom SSO - GetKS and Logout with token for custom SSO - Authentication readme updated - Added modules namespace --- AuthenticationReadMe.md | 77 ++++++++++++++++++- Changelog.md | 2 + build.gradle | 4 +- streamamg-sdk-authentication/build.gradle | 1 + .../AuthenticationSDK.kt | 2 + .../StreamAMGAuthenticationSDK.kt | 33 ++++++-- .../extension/RxExtensions.kt | 2 +- streamamg-sdk-cloudmatrix/build.gradle | 1 + streamamg-sdk-core/build.gradle | 1 + streamamg-sdk-playkit/build.gradle | 1 + streamamg-sdk-playkit2go/build.gradle | 1 + streamamg-sdk-purchases/build.gradle | 1 + streamamg-sdk-streamplay/build.gradle | 1 + 13 files changed, 116 insertions(+), 11 deletions(-) diff --git a/AuthenticationReadMe.md b/AuthenticationReadMe.md index 69bc2c8..c708970 100644 --- a/AuthenticationReadMe.md +++ b/AuthenticationReadMe.md @@ -4,6 +4,7 @@ StreamSDK Authentication SDK The StreamSDK Authentication SDK is a light wrapper around the authentication API and provides: * Logging in via email and password +* Logging in using custom SSO * Getting a token * Getting a KSession * Storing credentials and logging in silently @@ -49,9 +50,10 @@ authenticationSdk.initWithURL("https://my.client.url.payments/", "lang=" + Local `initWithURL` takes 2 parameters: the base url of the service, and a second optional parameter string which is appended to all requests -## Usage +Logging In +======== +To authenticate with the selected StreamAMG Authentication API, simply pass an email and password to the login function, with a callback block -Once initialised, call the functions of the SDK with callbacks: ``` authenticationSdk.login(email, password) { result -> when (result) { @@ -61,13 +63,52 @@ authenticationSdk.login(email, password) { result -> } ``` +Alternatively, it is also possible to automatically login a previously verified user as long as they have not since logged out: + +``` +authenticationSdk.loginSilent { result -> + when (result) { + is LoginResult.LoginOK -> onloginSuccess() + else -> handleLoginError(result) + } +} +``` + +Logging Out +========= +To end a user's session and remove the user's credentials from the Keychain, you can log the user out: + +``` +authenticationSdk.logout { result -> + when (result) { + is LogoutResult.LogoutOK -> onlogoutSuccess() + else -> handleLogoutError(result) + } +} +``` + +Requesting Key Session Token +======================= +If the Authentication API is providing Key Session Tokens, these can also be requested via the SDK: + +``` +authenticationSdk.getKS(entryID) { keySessionResult -> + if (keySessionResult is GetKeySessionResult.Granted) { + // Valid KS + KS = keySessionResult.keySession + } else { + // Manage other GetKeySessionResult type + } +} +``` + Using custom SSO ======================= Authentication SDK supports custom SSO implementation that are correctly configured with CloudPay and are able to generate a valid use JWT token. ## Start the session with custom SSO -In order to comunicate with CloudPay the app needs to start the session with the users token. +In order to communicate with CloudPay the app needs to start the session with the users token generated. This is an optional step and required only if you are not using cloud pay login but you want to start a user session to log the sessions and so get CloudPay check the concurrency. ``` authenticationSdk.startSession("jwtToken", @@ -110,6 +151,7 @@ authenticationSdk.updateUserSummary(firstname,lastname, token } ) ``` + ## Retrieve user summary The retrieve user summary function allows a user to retrieve their user details if the user has a valid token. @@ -125,6 +167,35 @@ authenticationSdk.getUserSummary(token } ) ``` + +## Logout with custom SSO + +If you are using custom SSO, to logout from cloudpay, use this method to logout by passing the token you previously used to start the SSO. + +``` +authenticationSdk.logoutWithToken(token) { result -> + when (result) { + is LogoutResult.LogoutOK -> onlogoutSuccess() + else -> handleLogoutError(result) + } +} +``` + +## GetKS with custom SSO + +If you are using custom SSO, then to get the user entitlements use this method. Please pass the same token you used to start the custom SSO session. + +``` +authenticationSdk.getKSWithToken(token, entryID) { keySessionResult -> + if (keySessionResult is GetKeySessionResult.Granted) { + // Valid KS + KS = keySessionResult.keySession + } else { + // Manage other GetKeySessionResult type + } +} +``` + Change Log: =========== diff --git a/Changelog.md b/Changelog.md index fb2d233..d3e638d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,8 @@ Change Log: All notable changes to this project will be documented in this section. +### 1.2.5 - Updated Authentication module with new methods to logout and getKS with third party JWT tokens. + ### 1.2.4 - Updated MediaType APIs from POST to GET ### 1.2.3 - Fixed StreamPlay FixtureID field types diff --git a/build.gradle b/build.gradle index b314ad1..9c33afa 100644 --- a/build.gradle +++ b/build.gradle @@ -15,8 +15,8 @@ plugins { id 'maven-publish' } // Versions of the library modules are matched (eg 1.0 core goes with 1.0 cloudmatrix) to prevent dependency issues -ext.SDK_VERSION_CODE = 24 -ext.SDK_VERSION_NAME = "1.2.4" +ext.SDK_VERSION_CODE = 25 +ext.SDK_VERSION_NAME = "1.2.5" publishing { publications { diff --git a/streamamg-sdk-authentication/build.gradle b/streamamg-sdk-authentication/build.gradle index c322a33..2b62024 100644 --- a/streamamg-sdk-authentication/build.gradle +++ b/streamamg-sdk-authentication/build.gradle @@ -4,6 +4,7 @@ plugins { } android { + namespace = "com.streamamg.streamamg_sdk_authentication" compileSdkVersion 33 defaultConfig { diff --git a/streamamg-sdk-authentication/src/main/java/com/streamamg/streamamg_sdk_authentication/AuthenticationSDK.kt b/streamamg-sdk-authentication/src/main/java/com/streamamg/streamamg_sdk_authentication/AuthenticationSDK.kt index 490e51c..8b7c4f6 100644 --- a/streamamg-sdk-authentication/src/main/java/com/streamamg/streamamg_sdk_authentication/AuthenticationSDK.kt +++ b/streamamg-sdk-authentication/src/main/java/com/streamamg/streamamg_sdk_authentication/AuthenticationSDK.kt @@ -19,7 +19,9 @@ interface AuthenticationSDK { @Deprecated("Use login with callback which returns the token") fun loginSyncToken(email: String, password: String): String fun getKS(entryID: String, callback: (GetKeySessionResult) -> Unit) + fun getKSWithToken(token: String, entryID: String, callback: (GetKeySessionResult) -> Unit) fun logout(callback: (LogoutResult) -> Unit) + fun logoutWithToken(token: String, callback: (LogoutResult) -> Unit) fun startSession(token: String, onSuccess: () -> Unit,onError: (Error) -> Unit) fun updateUserSummary( firstName: String, diff --git a/streamamg-sdk-authentication/src/main/java/com/streamamg/streamamg_sdk_authentication/StreamAMGAuthenticationSDK.kt b/streamamg-sdk-authentication/src/main/java/com/streamamg/streamamg_sdk_authentication/StreamAMGAuthenticationSDK.kt index 771d883..d60d1f3 100644 --- a/streamamg-sdk-authentication/src/main/java/com/streamamg/streamamg_sdk_authentication/StreamAMGAuthenticationSDK.kt +++ b/streamamg-sdk-authentication/src/main/java/com/streamamg/streamamg_sdk_authentication/StreamAMGAuthenticationSDK.kt @@ -20,7 +20,7 @@ import timber.log.Timber internal class StreamAMGAuthenticationSDK( private val coreSDK: StreamAMGSDK, - @VisibleForTesting var api: AuthenticationApi? = null + @get:VisibleForTesting var api: AuthenticationApi? = null ) : AuthenticationSDK { private var apiUrl: String? = null @@ -80,10 +80,21 @@ internal class StreamAMGAuthenticationSDK( } override fun logout(callback: (LogoutResult) -> Unit) { + logoutWithToken(sessionId, callback) + } + /** + Logs out a user by sending a logout request with the provided token. + - Parameters: + - token: The authentication token for the user. + - callback: A closure to be called upon completion of the logout operation. It takes a `LogoutResult` type as an argument. + - Note: Make sure the `url` property is properly set before calling this method. + This function sends a logout request to the authentication API and handles the response accordingly. + */ + override fun logoutWithToken(token: String, callback: (LogoutResult) -> Unit) { clearSavedCredentials() - api?.logout(paramsMap, sessionId) + api?.logout(paramsMap, token) ?.applySchedulers() ?.subscribeBy( onSuccess = { @@ -217,7 +228,7 @@ internal class StreamAMGAuthenticationSDK( return Single.create { login(email, password) { result -> if (result is LoginResult.LoginOK && loginResponse?.authenticationToken != null) { - it.onSuccess(loginResponse!!.authenticationToken) + it.onSuccess(loginResponse!!.authenticationToken!!) } else { loginResponse = LoginResponse() loginResponse?.authenticationToken = null @@ -281,12 +292,25 @@ internal class StreamAMGAuthenticationSDK( } override fun getKS(entryID: String, callback: (GetKeySessionResult) -> Unit) { + getKSWithToken(sessionId, entryID, callback) + } + + /** + Retrieves a Key Session (KS) for a specific entry using the provided token. + - Parameters: + - token: The authentication token for the user. + - entryID: The ID of the entry for which the KS is requested. + - callback: A closure to be called upon completion of the KS retrieval operation. It takes a `GetKeySessionResult` type as an argument. + - Note: Ensure that the `url` property is properly set before calling this method. + This function sends a request to retrieve a Key Session (KS) for a specific entry and handles the response accordingly. + */ + override fun getKSWithToken(token: String, entryID: String, callback: (GetKeySessionResult) -> Unit) { if (!isInitialized()) { callback.invoke(GetKeySessionResult.Error(Exception("PaymentSDK not initialized"))) return } - api?.getKS(entryID, sessionId, paramsMap) + api?.getKS(entryID, token, paramsMap) ?.applySchedulers() ?.subscribeBy( onSuccess = { response -> @@ -299,7 +323,6 @@ internal class StreamAMGAuthenticationSDK( callback.invoke(GetKeySessionResult.Error(it)) }) ?.addTo(disposable) - } private fun handleKSLoginResponse(loginResponse: LoginResponse, callback: (GetKeySessionResult) -> Unit) { diff --git a/streamamg-sdk-authentication/src/main/java/com/streamamg/streamamg_sdk_authentication/extension/RxExtensions.kt b/streamamg-sdk-authentication/src/main/java/com/streamamg/streamamg_sdk_authentication/extension/RxExtensions.kt index 45960bd..23cd7ef 100644 --- a/streamamg-sdk-authentication/src/main/java/com/streamamg/streamamg_sdk_authentication/extension/RxExtensions.kt +++ b/streamamg-sdk-authentication/src/main/java/com/streamamg/streamamg_sdk_authentication/extension/RxExtensions.kt @@ -4,6 +4,6 @@ import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers import io.reactivex.rxjava3.core.Single import io.reactivex.rxjava3.schedulers.Schedulers -fun Single.applySchedulers(): Single { +fun Single.applySchedulers(): Single { return subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) } \ No newline at end of file diff --git a/streamamg-sdk-cloudmatrix/build.gradle b/streamamg-sdk-cloudmatrix/build.gradle index 8c75541..a3ddd14 100644 --- a/streamamg-sdk-cloudmatrix/build.gradle +++ b/streamamg-sdk-cloudmatrix/build.gradle @@ -4,6 +4,7 @@ plugins { } android { + namespace = "com.streamamg.streamamg_sdk_cloudmatrix" compileSdkVersion 33 defaultConfig { diff --git a/streamamg-sdk-core/build.gradle b/streamamg-sdk-core/build.gradle index c5e5a6c..ce2223f 100644 --- a/streamamg-sdk-core/build.gradle +++ b/streamamg-sdk-core/build.gradle @@ -4,6 +4,7 @@ plugins { } android { + namespace = "com.streamamg.streamapi_core" compileSdkVersion 33 defaultConfig { diff --git a/streamamg-sdk-playkit/build.gradle b/streamamg-sdk-playkit/build.gradle index 5ec5691..c4ab519 100644 --- a/streamamg-sdk-playkit/build.gradle +++ b/streamamg-sdk-playkit/build.gradle @@ -4,6 +4,7 @@ plugins { } android { + namespace = "com.streamamg.amg_playkit" compileSdkVersion 33 defaultConfig { diff --git a/streamamg-sdk-playkit2go/build.gradle b/streamamg-sdk-playkit2go/build.gradle index 90949b9..4b32825 100644 --- a/streamamg-sdk-playkit2go/build.gradle +++ b/streamamg-sdk-playkit2go/build.gradle @@ -4,6 +4,7 @@ plugins { } android { + namespace = "com.streamamg.streamamg_sdk_playkit2go" compileSdkVersion 33 defaultConfig { diff --git a/streamamg-sdk-purchases/build.gradle b/streamamg-sdk-purchases/build.gradle index 7cfa4a6..005d27a 100644 --- a/streamamg-sdk-purchases/build.gradle +++ b/streamamg-sdk-purchases/build.gradle @@ -4,6 +4,7 @@ plugins { } android { + namespace = "com.streamamg.streamamg_sdk_purchases" compileSdkVersion 33 defaultConfig { diff --git a/streamamg-sdk-streamplay/build.gradle b/streamamg-sdk-streamplay/build.gradle index e2fba4b..cbc56d8 100644 --- a/streamamg-sdk-streamplay/build.gradle +++ b/streamamg-sdk-streamplay/build.gradle @@ -4,6 +4,7 @@ plugins { } android { + namespace = "com.streamamg.streamapi_streamplay" compileSdkVersion 33 defaultConfig {