From bffe531ab765a29eb19b6a61ff97bd069ea11591 Mon Sep 17 00:00:00 2001 From: this-Aditya Date: Thu, 12 Sep 2024 18:51:36 +0530 Subject: [PATCH 1/9] Added dependency for oAuth manager --- app/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/app/build.gradle b/app/build.gradle index 3b7e8fa..0b7d3e7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -101,6 +101,7 @@ dependencies { implementation "org.radarbase:radar-android-weather:$radar_commons_android_version" implementation "org.radarbase:radar-android-audio:$radar_commons_android_version" implementation "org.radarbase:radar-android-faros:$radar_commons_android_version" + implementation "org.radarbase:radar-android-login-oauth2:$radar_commons_android_version" implementation "org.radarbase:radar-android-polar:$radar_commons_android_version" implementation "org.radarbase:radar-android-google-sleep:$radar_commons_android_version" implementation "org.radarbase:radar-android-google-activity:$radar_commons_android_version" From afac6df7bf10be43a83d86abb87cca0a067d794d Mon Sep 17 00:00:00 2001 From: this-Aditya Date: Thu, 12 Sep 2024 18:52:07 +0530 Subject: [PATCH 2/9] Configuring oAuthManager in AuthService --- app/src/main/java/org/radarcns/detail/AuthServiceImpl.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/org/radarcns/detail/AuthServiceImpl.kt b/app/src/main/java/org/radarcns/detail/AuthServiceImpl.kt index 44024c9..5d2c8a1 100644 --- a/app/src/main/java/org/radarcns/detail/AuthServiceImpl.kt +++ b/app/src/main/java/org/radarcns/detail/AuthServiceImpl.kt @@ -3,11 +3,13 @@ package org.radarcns.detail import org.radarbase.android.auth.AppAuthState import org.radarbase.android.auth.AuthService import org.radarbase.android.auth.LoginManager +import org.radarbase.android.auth.oauth2.OAuth2LoginManager import org.radarbase.android.auth.portal.ManagementPortalLoginManager class AuthServiceImpl : AuthService() { override fun createLoginManagers(appAuth: AppAuthState): List = listOf( ManagementPortalLoginManager(this, appAuth), + OAuth2LoginManager(this) ) override fun showLoginNotification() = Unit From 16b1b043768913c87d0aa9eb59d12b45c3a92275 Mon Sep 17 00:00:00 2001 From: this-Aditya Date: Thu, 12 Sep 2024 18:53:08 +0530 Subject: [PATCH 3/9] Extracting data from QR code from SEP UI --- .../org/radarcns/detail/LoginActivityImpl.kt | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt b/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt index 4f653b9..ebe8c56 100644 --- a/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt +++ b/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt @@ -37,6 +37,7 @@ import org.json.JSONObject import org.radarbase.android.RadarApplication.Companion.radarConfig import org.radarbase.android.RadarConfiguration.Companion.BASE_URL_KEY import org.radarbase.android.auth.* +import org.radarbase.android.auth.oauth2.OAuth2LoginManager import org.radarbase.android.auth.portal.ManagementPortalLoginManager import org.radarbase.android.util.Boast import org.radarbase.android.util.NetworkConnectedReceiver @@ -61,7 +62,8 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne private lateinit var binding: ActivityLoginBinding - private lateinit var qrCodeScanner: QrCodeScanner + private lateinit var mpQrCodeScanner: QrCodeScanner + private lateinit var oAuthQrCodeScanner: QrCodeScanner private lateinit var dialog: Dialog private lateinit var mainHandler: Handler @@ -76,9 +78,13 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne networkReceiver = NetworkConnectedReceiver(this, this) didCreate = true - qrCodeScanner = QrCodeScanner(this) { value -> + mpQrCodeScanner = QrCodeScanner(this) { value -> value?.takeTrimmedIfNotEmpty() - ?.also { parseQrCode(it) } + ?.also { parseMpQrCode(it) } + } + oAuthQrCodeScanner = QrCodeScanner(this) { value -> + value?.takeTrimmedIfNotEmpty() + ?.also { parseOAuthQrCode(it) } } with(binding) { @@ -102,7 +108,7 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne networkReceiver.run { unregister() } } - private fun parseQrCode(qrCode: String) { + private fun parseMpQrCode(qrCode: String) { onProcessing() logger.info("Read tokenUrl: {}", qrCode) @@ -142,6 +148,30 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne } } + private fun parseOAuthQrCode(qrData: String) { + onProcessing() + logger.debug("Processing data from QR code {}", qrData) + + if (qrData.isEmpty()) { + loginFailed(null, QrException("QR code is empty. Please retry")) + logger.error("QR code is empty. Please retry") + return + } + + applyOAuthManager { binder, oAuthManager, authState -> + if (qrData.startsWith('{')) { + try { + + } catch (ex: Exception) { + loginFailed(oAuthManager, ex) + } + } else { + // QR code should have data in JSON format if scanning from SEP UI + loginFailed(oAuthManager, QrException("QR code doesn't contains the data in JSON format")) + } + } + } + private fun applyMpManager(callback: (AuthService.AuthServiceBinder, ManagementPortalLoginManager, AppAuthState) -> Unit) { authConnection.applyBinder { val manager = managers.find { it is ManagementPortalLoginManager } @@ -152,6 +182,16 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne } } + private fun applyOAuthManager(callback: (AuthService.AuthServiceBinder, OAuth2LoginManager, AppAuthState) -> Unit) { + authConnection.applyBinder { + val oauthManager = managers.find { it is OAuth2LoginManager } + as? OAuth2LoginManager ?: return@applyBinder + applyState { + callback(this@applyBinder, oauthManager, this) + } + } + } + private fun onProcessing() { setLoader(true) } @@ -184,7 +224,7 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne private fun scan(@Suppress("UNUSED_PARAMETER") view: View) { if (canLogin) { canLogin = false - qrCodeScanner.start() + mpQrCodeScanner.start() } } From 432027b17965d2a73603d2fcba49a31ae0c8d8ae Mon Sep 17 00:00:00 2001 From: this-Aditya Date: Fri, 13 Sep 2024 17:22:04 +0530 Subject: [PATCH 4/9] Parsing QR data --- app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt b/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt index ebe8c56..77cd456 100644 --- a/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt +++ b/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt @@ -161,13 +161,15 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne applyOAuthManager { binder, oAuthManager, authState -> if (qrData.startsWith('{')) { try { - + oAuthManager.parsePreLoginQr(authState, qrData) } catch (ex: Exception) { loginFailed(oAuthManager, ex) + return@applyOAuthManager } } else { // QR code should have data in JSON format if scanning from SEP UI loginFailed(oAuthManager, QrException("QR code doesn't contains the data in JSON format")) + return@applyOAuthManager } } } From 8aaa29d93f17e7ef727c0cbf33aab3a1770274c2 Mon Sep 17 00:00:00 2001 From: this-Aditya Date: Fri, 13 Sep 2024 17:45:04 +0530 Subject: [PATCH 5/9] Updating login activity's UI --- app/src/main/res/layout/activity_login.xml | 36 +++++++++++++++++++--- app/src/main/res/values/strings.xml | 6 ++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 2e56d6c..1285f13 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -45,24 +45,25 @@ android:padding="@dimen/size_medium"> + + + + + + + Download and Install Error in package name! - Log in to pRMT App with the QR Code or Token provided to you. - Login + Log in to pRMT App with the QR Code or Token provided to you by Management Portal. + Log in to pRMT App with the QR Code provided to you by Self Enrolment Portal. + Login With Management Portal + Login With Self Enrolment Portal ItemDetailHostActivity Items Item Detail From 99ed7931e6cdb11dad878ac69d7527cdffef58c4 Mon Sep 17 00:00:00 2001 From: this-Aditya Date: Fri, 13 Sep 2024 17:50:57 +0530 Subject: [PATCH 6/9] Added functionality for scanning QR code from SEP --- .../org/radarcns/detail/LoginActivityImpl.kt | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt b/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt index 77cd456..b6090ad 100644 --- a/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt +++ b/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt @@ -63,7 +63,7 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne private lateinit var binding: ActivityLoginBinding private lateinit var mpQrCodeScanner: QrCodeScanner - private lateinit var oAuthQrCodeScanner: QrCodeScanner + private lateinit var sepQrCodeScanner: QrCodeScanner private lateinit var dialog: Dialog private lateinit var mainHandler: Handler @@ -82,13 +82,14 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne value?.takeTrimmedIfNotEmpty() ?.also { parseMpQrCode(it) } } - oAuthQrCodeScanner = QrCodeScanner(this) { value -> + sepQrCodeScanner = QrCodeScanner(this) { value -> value?.takeTrimmedIfNotEmpty() ?.also { parseOAuthQrCode(it) } } with(binding) { - scanButton.setOnClickListener { v -> scan(v) } + mpScanButton.setOnClickListener { v -> scanQrFromMP(v) } + sepScanButton.setOnClickListener { scanQrFromSEP() } enterCredentialsButton.setOnClickListener { v -> enterCredentials(v) } loader.visibility = View.GONE } @@ -171,6 +172,7 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne loginFailed(oAuthManager, QrException("QR code doesn't contains the data in JSON format")) return@applyOAuthManager } + binder.update(oAuthManager) } } @@ -213,23 +215,32 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne private fun checkNetworkConnection() = with(binding) { if (networkIsConnected) { - scanButton.isEnabled = true + mpScanButton.isEnabled = true + sepScanButton.isEnabled = true enterCredentialsButton.isEnabled = true messageText.text = "" } else { - scanButton.isEnabled = false + mpScanButton.isEnabled = false + sepScanButton.isEnabled = false enterCredentialsButton.isEnabled = false messageText.setText(R.string.no_connection) } } - private fun scan(@Suppress("UNUSED_PARAMETER") view: View) { + private fun scanQrFromMP(@Suppress("UNUSED_PARAMETER") view: View) { if (canLogin) { canLogin = false mpQrCodeScanner.start() } } + private fun scanQrFromSEP() { + if (canLogin) { + canLogin = false + sepQrCodeScanner.start() + } + } + override fun loginFailed(manager: LoginManager?, ex: Exception?) { canLogin = true @@ -372,11 +383,13 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne private fun setLoader(show: Boolean) = with(binding) { if (show) { - scanButton.visibility = View.GONE + mpScanButton.visibility = View.GONE + sepScanButton.visibility = View.GONE enterCredentialsButton.visibility = View.GONE loader.visibility = View.VISIBLE } else { - scanButton.visibility = View.VISIBLE + mpScanButton.visibility = View.VISIBLE + sepScanButton.visibility = View.VISIBLE enterCredentialsButton.visibility = View.VISIBLE loader.visibility = View.GONE } From 9951ef039c8a533f62df41a5ec8d0993ef7a4879 Mon Sep 17 00:00:00 2001 From: this-Aditya Date: Fri, 13 Sep 2024 18:04:47 +0530 Subject: [PATCH 7/9] function rename --- app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt b/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt index b6090ad..26f608a 100644 --- a/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt +++ b/app/src/main/java/org/radarcns/detail/LoginActivityImpl.kt @@ -84,7 +84,7 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne } sepQrCodeScanner = QrCodeScanner(this) { value -> value?.takeTrimmedIfNotEmpty() - ?.also { parseOAuthQrCode(it) } + ?.also { parseSepQrCode(it) } } with(binding) { @@ -149,7 +149,7 @@ class LoginActivityImpl : LoginActivity(), NetworkConnectedReceiver.NetworkConne } } - private fun parseOAuthQrCode(qrData: String) { + private fun parseSepQrCode(qrData: String) { onProcessing() logger.debug("Processing data from QR code {}", qrData) From 928e45e9432011c443af9858b8457f4fd1104525 Mon Sep 17 00:00:00 2001 From: this-Aditya Date: Mon, 23 Sep 2024 17:23:08 +0530 Subject: [PATCH 8/9] Passing authstate to oauth manager --- app/src/main/java/org/radarcns/detail/AuthServiceImpl.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/radarcns/detail/AuthServiceImpl.kt b/app/src/main/java/org/radarcns/detail/AuthServiceImpl.kt index 5d2c8a1..1bc3f2b 100644 --- a/app/src/main/java/org/radarcns/detail/AuthServiceImpl.kt +++ b/app/src/main/java/org/radarcns/detail/AuthServiceImpl.kt @@ -9,7 +9,7 @@ import org.radarbase.android.auth.portal.ManagementPortalLoginManager class AuthServiceImpl : AuthService() { override fun createLoginManagers(appAuth: AppAuthState): List = listOf( ManagementPortalLoginManager(this, appAuth), - OAuth2LoginManager(this) + OAuth2LoginManager(this, appAuth) ) override fun showLoginNotification() = Unit From b63788c47b57c4a66a471848dff1184ef03d270c Mon Sep 17 00:00:00 2001 From: this-Aditya Date: Mon, 23 Sep 2024 17:33:43 +0530 Subject: [PATCH 9/9] Concise SEP heading --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b3126f7..ef0a191 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -145,7 +145,7 @@ Log in to pRMT App with the QR Code or Token provided to you by Management Portal. Log in to pRMT App with the QR Code provided to you by Self Enrolment Portal. Login With Management Portal - Login With Self Enrolment Portal + Login With SEP-UI ItemDetailHostActivity Items Item Detail