Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endless loop of signin #576

Open
alexplanetart opened this issue Jun 5, 2023 · 2 comments
Open

Endless loop of signin #576

alexplanetart opened this issue Jun 5, 2023 · 2 comments

Comments

@alexplanetart
Copy link

alexplanetart commented Jun 5, 2023

Endless loop when integrating Google Sign-In with two scopes (https://www.googleapis.com/auth/photoslibrary.readonly https://www.googleapis.com/auth/drive.readonly) into My Android App

screen-20230605-173111.mp4

Steps to reproduce:

  1. Launch Google SignIn with two scopes
  2. Only select "View your Google photos library" option and remain "See and download all your Google Drive files" option unselected

Observed Results:

  • Endless loop of signin flow

Expected Results:

  • Account login successfully with only one scope

Relevant Code:

fun initGoogleLogin() {
    val config = GalleryLib.galleryConfig.googleConfig
        ?: throw IllegalArgumentException("Add googleConfig param in GalleryLib.init()")

    val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(
                    Scope("https://www.googleapis.com/auth/photoslibrary.readonly"),
                    Scope("https://www.googleapis.com/auth/drive.readonly")
            )
            .requestEmail()
            .requestServerAuthCode(config.googleId, true)//request refres_token everytime!!!
            .build()

    val client = GoogleSignIn.getClient(requireActivity(), gso)

    googleSignInLauncher.launch(client.signInIntent)

}


private val googleSignInLauncher =
    registerForActivityResult(GoogleSignInResultContract()) { account ->
        val code = account?.serverAuthCode
        if (code.isNullOrEmpty().not()) {
            showLoading(true)
            launch {
                val account = viewmodel.requestToken(code!!)
                showLoading(false)

                if (account != null) {
                    onSignInSuccess()
                } else {
                    onSignInFailure(RuntimeException("Google sign in failed"))
                }
            }
        } else {
            onSignInFailure(RuntimeException("Google sign in canceled"))
        }
    }

class GoogleSignInResultContract : ActivityResultContract<Intent, GoogleSignInAccount?>() {
    override fun createIntent(context: Context, input: Intent): Intent {
        return input
    }

    override fun parseResult(resultCode: Int, intent: Intent?): GoogleSignInAccount? {
        return if (resultCode == Activity.RESULT_OK) {
            val task = GoogleSignIn.getSignedInAccountFromIntent(intent)

            val account = try {
                task.getResult(ApiException::class.java)
            } catch (e: ApiException) {
                null
            }

            account
        } else {
            null
        }

    }
}
@alexplanetart
Copy link
Author

Any replies?
What's even more strange is that when I only request for photo permission and permission page reloads even if the photo permission is granted.

011846-720x1544.mp4

@alexplanetart
Copy link
Author

Endless loop only happens with Samsung Galaxy S23 Pro and signin succeed with other Android phones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant