NTP-50953 | granted scopes changes (#16474)

Co-authored-by: mohit-rajput <mohit.rajput@navi.com>
This commit is contained in:
Mehul Garg
2025-06-09 20:12:46 +05:30
committed by GitHub
parent 4d35587eb1
commit 4554df97fa
12 changed files with 38 additions and 4 deletions

View File

@@ -123,6 +123,7 @@ const val AB_TESTING_PROJECT_ORIGIN_EMAIL_SUB_EXPERIMENT_NAME = "NaviBBPS-Projec
const val NAVI_BBPS_REWARD_BANNER = "reward"
const val NAVI_BBPS_CROSS_SELL_BANNER = "cross-sell"
const val ERROR_CODE_ORIGIN_NOTIFY_LATER = "ORIGIN_NOTIFY_LATER"
const val ERR_NO_READ_ONLY_GMAIL_SCOPE = "ERR_NO_READ_ONLY_GMAIL_SCOPE"
// Order Details Screen redirection
const val NAVI_BBPS_TSTORE_ORDER_DETAILS_REDIRECTION = "naviPay/NAVI_PAY_ORDER_DETAILS"

View File

@@ -26,4 +26,5 @@ data class GoogleUserProfileData(
@SerializedName("givenName") val givenName: String? = null,
@SerializedName("idToken") val idToken: String? = null,
@SerializedName("photoUrl") val photoUrl: String? = null,
@SerializedName("grantedScopes") val grantedScopes: String?,
)

View File

@@ -120,6 +120,7 @@ class GmailAccessSignInManager @Inject constructor(@ActivityContext val context:
return try {
val task = GoogleSignIn.getSignedInAccountFromIntent(intent)
val taskResult = task.getResult(ApiException::class.java)
GmailAccessResponse(
authCode = taskResult.serverAuthCode,
emailId = taskResult.account?.name,
@@ -131,6 +132,7 @@ class GmailAccessSignInManager @Inject constructor(@ActivityContext val context:
givenName = taskResult.givenName,
idToken = taskResult.idToken,
photoUrl = taskResult.photoUrl?.toString().orEmpty(),
grantedScopes = taskResult.grantedScopes.joinToString(",") { it.scopeUri },
),
signInAccount = taskResult,
account = taskResult.account,
@@ -141,7 +143,7 @@ class GmailAccessSignInManager @Inject constructor(@ActivityContext val context:
}
companion object {
private const val GMAIL_READ_ONLY_SCOPE = "https://www.googleapis.com/auth/gmail.readonly"
const val GMAIL_READ_ONLY_SCOPE = "https://www.googleapis.com/auth/gmail.readonly"
private const val USER_PROFILE_SCOPE = "https://www.googleapis.com/auth/userinfo.profile"
private const val USER_EMAIL_SCOPE = "https://www.googleapis.com/auth/userinfo.email"
}

View File

@@ -333,9 +333,9 @@ fun BottomSheetContentWithIconHeaderPrimarySecondaryButton(
NaviText(
text = header,
fontSize = 18.sp,
fontSize = 16.sp,
fontFamily = naviFontFamily,
fontWeight = getFontWeight(FontWeightEnum.NAVI_HEADLINE_REGULAR),
fontWeight = getFontWeight(FontWeightEnum.NAVI_BODY_DEMI_BOLD),
color = NaviBbpsColor.textPrimary,
)
@@ -346,7 +346,7 @@ fun BottomSheetContentWithIconHeaderPrimarySecondaryButton(
fontSize = 14.sp,
fontFamily = naviFontFamily,
fontWeight = getFontWeight(FontWeightEnum.NAVI_BODY_REGULAR),
color = NaviBbpsColor.textSecondary,
color = NaviBbpsColor.textTertiary,
)
if (!primaryButton.isNullOrBlank() || !secondaryButton.isNullOrBlank()) {

View File

@@ -18,7 +18,9 @@ import com.navi.bbps.common.ADDING_BILLS_SUCCESS_LOTTIE
import com.navi.bbps.common.ADDING_DETECTED_BILLS_LOTTIE
import com.navi.bbps.common.DEFAULT_RETRY_COUNT
import com.navi.bbps.common.ERROR_CODE_ORIGIN_NOTIFY_LATER
import com.navi.bbps.common.ERR_NO_READ_ONLY_GMAIL_SCOPE
import com.navi.bbps.common.RETRY_INTERVAL_IN_SECONDS
import com.navi.bbps.common.gmail.signin.GmailAccessSignInManager.Companion.GMAIL_READ_ONLY_SCOPE
import com.navi.bbps.common.mapper.DetectedBillsMapper
import com.navi.bbps.common.model.config.NaviBbpsDefaultConfig
import com.navi.bbps.common.model.network.BillDetectionRequest
@@ -98,6 +100,7 @@ constructor(
coroutineScope: CoroutineScope,
permission: String,
googleToken: String? = null,
grantedEmailScopes: String? = null,
email: String? = null,
naviBbpsDefaultConfig: NaviBbpsDefaultConfig,
updateOpenBottomSheet: suspend (Boolean) -> Unit,
@@ -114,6 +117,19 @@ constructor(
updateBottomSheetCancellable(true)
}
if (
permission == DetectedBillSource.EMAIL.name &&
GMAIL_READ_ONLY_SCOPE !in (grantedEmailScopes.orEmpty())
) {
updateOpenBottomSheet(false)
val errorConfig =
naviBbpsBaseVM
.getGenericErrorConfig()
.copy(code = ERR_NO_READ_ONLY_GMAIL_SCOPE, tag = ERR_NO_READ_ONLY_GMAIL_SCOPE)
naviBbpsBaseVM.notifyError(errorConfig)
return
}
updateBottomSheetCancellable(false)
resetLoadingIndicatorProgress()

View File

@@ -485,6 +485,7 @@ constructor(
detectedBillSource: DetectedBillSource = DetectedBillSource.SMS,
googleToken: String? = null,
email: String? = null,
grantedEmailScopes: String? = null,
) {
viewModelScope.launch(dispatcherProvider.io) {
originBillDetectionHandler.startDetectingBills(
@@ -492,6 +493,7 @@ constructor(
coroutineScope = viewModelScope,
permission = detectedBillSource.name,
googleToken = googleToken,
grantedEmailScopes = grantedEmailScopes,
email = email,
naviBbpsDefaultConfig = naviBbpsDefaultConfig,
updateOpenBottomSheet = { isOpen -> updateOpenBottomSheet(isOpen) },

View File

@@ -720,6 +720,8 @@ fun BillCategoryScreenRenderer(
detectedBillSource = DetectedBillSource.EMAIL,
googleToken = gmailAccessState.signInResponse.authCode,
email = gmailAccessState.signInResponse.emailId,
grantedEmailScopes =
gmailAccessState.signInResponse.profileData?.grantedScopes,
)
}

View File

@@ -267,6 +267,7 @@ constructor(
detectedBillSource: DetectedBillSource = DetectedBillSource.SMS,
googleToken: String? = null,
email: String? = null,
grantedEmailScopes: String? = null,
) {
viewModelScope.launch(dispatcherProvider.io) {
originBillDetectionHandler.startDetectingBills(
@@ -274,6 +275,7 @@ constructor(
coroutineScope = viewModelScope,
permission = detectedBillSource.name,
googleToken = googleToken,
grantedEmailScopes = grantedEmailScopes,
email = email,
naviBbpsDefaultConfig = naviBbpsDefaultConfig,
updateOpenBottomSheet = { isOpen -> updateOpenBottomSheet(isOpen) },

View File

@@ -303,6 +303,8 @@ fun DetectedBillsScreen(
detectedBillSource = DetectedBillSource.EMAIL,
googleToken = gmailAccessState.signInResponse.authCode,
email = gmailAccessState.signInResponse.emailId,
grantedEmailScopes =
gmailAccessState.signInResponse.profileData?.grantedScopes,
)
}

View File

@@ -828,6 +828,7 @@ constructor(
detectedBillSource: DetectedBillSource = DetectedBillSource.SMS,
googleToken: String? = null,
email: String? = null,
grantedEmailScopes: String? = null,
) {
viewModelScope.launch(dispatcherProvider.io) {
originBillDetectionHandler.startDetectingBills(
@@ -835,6 +836,7 @@ constructor(
coroutineScope = viewModelScope,
permission = detectedBillSource.name,
googleToken = googleToken,
grantedEmailScopes = grantedEmailScopes,
email = email,
naviBbpsDefaultConfig = naviBbpsDefaultConfig,
updateOpenBottomSheet = { isOpen -> updateOpenBottomSheet(isOpen) },

View File

@@ -352,6 +352,8 @@ fun MyBillsScreen(
detectedBillSource = DetectedBillSource.EMAIL,
googleToken = gmailAccessState.signInResponse.authCode,
email = gmailAccessState.signInResponse.emailId,
grantedEmailScopes =
gmailAccessState.signInResponse.profileData?.grantedScopes,
)
}

View File

@@ -9,6 +9,7 @@ package com.navi.bbps.common.viewmodel
import com.navi.base.utils.NaviNetworkConnectivity
import com.navi.base.utils.ResourceProvider
import com.navi.bbps.common.gmail.signin.GmailAccessSignInManager.Companion.GMAIL_READ_ONLY_SCOPE
import com.navi.bbps.common.model.config.NaviBbpsDefaultConfig
import com.navi.bbps.common.model.network.BillDetectionResponse
import com.navi.bbps.common.model.network.DetectedBillsResponse
@@ -230,6 +231,7 @@ class OriginBillDetectionHandlerTest {
naviBbpsBaseVM = naviBbpsBaseVM,
coroutineScope = testScope,
permission = "EMAIL", // Using EMAIL permission
grantedEmailScopes = GMAIL_READ_ONLY_SCOPE,
naviBbpsDefaultConfig = config,
updateOpenBottomSheet = testCallbacks.updateOpenBottomSheet,
updateBottomSheetCancellable = testCallbacks.updateBottomSheetCancellable,