OAuth2.0 while using YouTube v3 api authentication Invalid Credentials - android

I spent several days on how to implement a "simple" Google sign-in through Google api console and Firebase api. As I don't have a server, I would like to have access to user's account only when he uses the application. My goal is to be able to get user's channels id's so I could load all of his uploaded videos.
In order to do that I created a new project in the google console api, linked it to Firebase and used this tutorial link to integrate it in my app. I got to the point where a user can choose a Gmail account and login, the app also prompt series of YouTube permissions that the user need to permit.
After that I get accountUid of the user (the same one that is shown in the Firebase console).
From this point I got confused because some of the tutorials were mentioning token access, refresh tokens, client id, client secret which I don't have and not sure if those credentials are necessary for my application.
After the user sign in successfully I'm using this API call to obtain his channels of his YouTube account:
#GET("channels")
fun getChannelsList(#Query("part") part :String = "contentDetails,snippet",#Query("mine") mine : Boolean = true, #Header("Authorization") accessToken : String) : Single<ChannelResponse>
But I'm getting this error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
from this link I also tried to put "Bearer " as part of the header value with the same result.
I also tried googleSignInAccount.idToken but it did not help either.
This is the code of my LoginActivity:
class LoginActivity : BaseActivity(), View.OnClickListener,OnCompleteListener<AuthResult>{
var idTokenString = ""
val TAG = "LoginActivity"
val mAuth = FirebaseAuth.getInstance()
private var mAuthListener: FirebaseAuth.AuthStateListener? = null
var googleAccount : GoogleSignInAccount?=null
override fun layoutRes(): Int {
return app.globe.com.youtubeplaylist.R.layout.activity_login
}
override fun initUI() {
login.setOnClickListener(this)
logout.setOnClickListener(this)
}
companion object {
const val RC_SIGN_IN = 1000
}
private var googleSignInClient : GoogleSignInClient?=null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(app.globe.com.youtubeplaylist.R.string.default_web_client_id))
.requestEmail()
.requestScopes(Scope("https://www.googleapis.com/auth/youtube.readonly"),
Scope("https://www.googleapis.com/auth/youtube.force-ssl"))
.build()
googleSignInClient = GoogleSignIn.getClient(this,gso)
googleSignInClient!!.signInIntent
}
override fun onStart() {
super.onStart()
val currentUser = mAuth.currentUser
checkAccount(currentUser)
}
override fun onClick(v: View) {
when (v.id) {
app.globe.com.youtubeplaylist.R.id.login -> {
signIn()
}
app.globe.com.youtubeplaylist.R.id.logout ->{
signOut()
}
}
}
private fun signOut()
{
FirebaseAuth.getInstance().signOut()
checkAccount(null)
}
private fun signIn() {
val signInIntent = googleSignInClient!!.signInIntent
startActivityForResult(signInIntent, RC_SIGN_IN)
}
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
try {
// Google Sign In was successful, authenticate with Firebase
googleAccount = task.getResult(ApiException::class.java)
firebaseAuthWithGoogle(googleAccount!!)
} catch (e: ApiException) {
// Google Sign In failed, update UI appropriately
Log.w(TAG, "Google sign in failed", e)
// ...
}
}
}
private fun firebaseAuthWithGoogle(acct : GoogleSignInAccount)
{
Log.d(TAG, "firebaseAuthWithGoogle:" + acct.id)
val credential = GoogleAuthProvider.getCredential(acct.idToken, null)
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, this)
}
override fun onComplete(task: Task<AuthResult>) {
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success")
var user = mAuth.currentUser
checkAccount(user)
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.exception)
Snackbar.make(main_layout, "Authentication Failed.", Snackbar.LENGTH_SHORT).show()
checkAccount(null)
}
}
private fun checkAccount(account : FirebaseUser?)
{
if(account!=null)
{
val mainIntent = Intent(this,MainActivity::class.java)
startActivity(mainIntent)
}
else
{
login.visibility = View.VISIBLE
logout.visibility = View.GONE
}
}
}
Thank you!

That default_web_client_id might be wrong.
Whatever app.globe.com.youtubeplaylist.R.string.default_web_client_id might be.
see GoogleSignInOptions.Builder.requestIdToken (String serverClientId):
Specifies that an ID token for authenticated users is requested.
Requesting an ID token requires that the server client ID be specified.
serverClientId The client ID of the server that will verify the integrity of the token.
Goto console.firebase.google.com, select the project, then click
Authentication > Sign-In method > Google > Web SDK configuration.
There you find the "Web client ID" and "Web client secret" to use.
Also on the Google Cloud API credentials page, as "Client ID for Web application
".
Scope https://www.googleapis.com/auth/youtube.force-ssl might require scope https://www.googleapis.com/auth/youtube (these both are for managing the YouTube account). For viewing the content, scope https://www.googleapis.com/auth/youtube.readonly suffices.

Related

Android App Google OAuth2 Fails returning Code 10

I am using Google OneTap SignIn in my app.
I am getting this error when no user is found and when I click my google profile to login:
error message
So it seems to be working with the signIn function, but not the signUp function? Why?
// USE one tap sign in client to do login.
oneTapClient = Identity.getSignInClient(this)
First I have a SignIn Request to sign in any previously signed in user.
signInRequest = BeginSignInRequest.builder()
.setPasswordRequestOptions(
BeginSignInRequest.PasswordRequestOptions.builder()
.setSupported(true)
.build()
)
.setGoogleIdTokenRequestOptions(
BeginSignInRequest.GoogleIdTokenRequestOptions.builder()
.setSupported(true)
// Your server's client ID, not your Android client ID.
.setServerClientId(Constants.OAUTH_CLIENT_ID_WEB)
// Only show accounts previously used to sign in.
.setFilterByAuthorizedAccounts(true)
.build()
)
// Automatically sign in when exactly one credential is retrieved.
.setAutoSelectEnabled(true)
.build()
Then I have a SignUp Request to sign the user up for OneTap if there are no credentials found.
// Sign up OneTap if no credentials found:
signUpRequest = BeginSignInRequest.builder()
.setGoogleIdTokenRequestOptions(
BeginSignInRequest.GoogleIdTokenRequestOptions.builder()
.setSupported(true)
// Your server's client ID, not your Android client ID.
.setServerClientId(Constants.OAUTH_CLIENT_ID_WEB)
// Show all accounts on the device.
.setFilterByAuthorizedAccounts(false)
.build()
)
.build()
Here are both functions I have that call the One Tap request:
// launch the OneTap sign in request
private fun signIn() {
println("Attempting One Tap...")
oneTapClient.beginSignIn(signInRequest)
.addOnSuccessListener(this) { result ->
try {
startIntentSenderForResult(
result.pendingIntent.intentSender, REQ_ONE_TAP,
null, 0, 0, 0, null
)
} catch (e: IntentSender.SendIntentException) {
Log.e(TAG, "Couldn't start One Tap UI: ${e.localizedMessage}")
}
}
.addOnFailureListener(this) { e ->
println("No saved credentials found")
// No saved credentials found. Launch the One Tap sign-up flow, or
// do nothing and continue presenting the signed-out UI.
e.localizedMessage?.let { Log.d(TAG, it) }
signUp()
}
}
// launch the OneTap sign up request
private fun signUp() {
oneTapClient.beginSignIn(signUpRequest)
.addOnSuccessListener(this) { result ->
try {
startIntentSenderForResult(
result.pendingIntent.intentSender, REQ_ONE_TAP,
null, 0, 0, 0
)
} catch (e: IntentSender.SendIntentException) {
Log.e(TAG, "Couldn't start One Tap UI: ${e.localizedMessage}")
}
}
.addOnFailureListener(this) { e ->
// No Google Accounts found. Just continue presenting the signed-out UI.
e.localizedMessage?.let { Log.d(TAG, it) }
}
}
And this is the onResultListener
#Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
REQ_ONE_TAP -> {
try {
val credential = oneTapClient.getSignInCredentialFromIntent(data)
val idToken = credential.googleIdToken
when {
idToken != null -> {
// Got an ID token from Google. Use it to authenticate
// with your backend.
Log.d(TAG, "Got ID token: $idToken")
}
else -> {
// Shouldn't happen.
Log.d(TAG, "No ID token or password!")
}
}
} catch (e: ApiException) {
when (e.statusCode) {
CommonStatusCodes.CANCELED -> {
Log.d(TAG, "One-tap dialog was closed.")
// Don't re-prompt the user.
showOneTapUI = false
}
CommonStatusCodes.NETWORK_ERROR -> {
Log.d(TAG, "One-tap encountered a network error.")
// Try again or just ignore.
}
else -> {
Log.d(
TAG, "Couldn't get credential from result." +
" (${e.localizedMessage})"
)
}
}
Log.e("Error", e.message.toString())
}
}
}
}
I've tried to make sure the package name is good on my Google Console and that my AndroidManifest.xml has the same package name. I also got the debug keystore from Android Studio, and that made the first signIn function work, but the signUp function still gets the error code 10.
For what its worth, I'm using Kotlin Multiplatform Mobile to try and make this a cross-platform app, but right now I'm having these issues on the Android side of things.

Firebase Google login pop up not showing in android

I'm implementing Google Sign by following Firebase offical docs. But the below codes do not show any google account when I click on the button to start google login.
Looks like the problem is with BeginSignInRequest.
binding.btnGoogleSignIn.setOnClickListener {
signInTest()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
REQUEST_CODE_SIGN_IN -> {
try {
val credential = Identity.getSignInClient(requireContext())
.getSignInCredentialFromIntent(data)
val idToken = credential.googleIdToken
when {
idToken != null -> {
// Got an ID token from Google. Use it to authenticate
// with Firebase.
Log.d(TAG, "Got ID token.")
val firebaseCredential = GoogleAuthProvider.getCredential(idToken, null)
auth.signInWithCredential(firebaseCredential)
.addOnCompleteListener() { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success")
val user = auth.currentUser
// updateUI(user)
findNavController().navigate(R.id.action_authFragment_to_homeFragment)
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.exception)
}
}
}
else -> {
// Shouldn't happen.
Log.d(TAG, "No ID token!")
}
}
} catch (e: ApiException) {
Log.d(TAG, "onActivityResult: ${e.message}")
}
}
}
}
private fun signInTest() {
BeginSignInRequest.builder()
.setGoogleIdTokenRequestOptions(
BeginSignInRequest.GoogleIdTokenRequestOptions.builder()
.setSupported(true)
// Your server's client ID, not your Android client ID.
.setServerClientId(getString(R.string.your_web_client_id))
// Only show accounts previously used to sign in.
.setFilterByAuthorizedAccounts(false)
.build()
)
.build()
}

FirebaseAuthInvalidCredentialsException:The supplied auth credential is malformed or has expired. [ Remote site 5XX from facebook.com for USER_INFO ]

In facebook login callback return success but firebase auth.signInWithCredential is return task is not successfull with exception; FirebaseAuthInvalidCredentialsException:The supplied auth credential is malformed or has expired. [ Remote site 5XX from facebook.com for USER_INFO ]
My facebook developer app type is Gaming services. When i looking on the web for solution, some say change apptype is work but imposibble due to app is live. Any suggestion?
binding.btnFacebookMan.registerCallback(callbackManager,object :
FacebookCallback<LoginResult> {
override fun onCancel() {
Log.d("log","facebook login cancelled")
}
override fun onError(error: FacebookException) {
Log.d("log","facebook ${error.message}")
}
override fun onSuccess(result: LoginResult) {
val credential = FacebookAuthProvider.getCredential(result.accessToken.token)
auth.signInWithCredential(credential).addOnCompleteListener(act) {task->
if(task.isSuccessful) {
Log.d("log","taskSuccess")
val mail = task.result.user?.email
val uid = task.result.user?.uid
} else {
Log.d("log","taskFail")
Log.d("log","${task.exception}")
loader.dismiss()
}
}
}
})

I am not able to sign in google play services. I am getting this exception "com.google.android.gms.common.api.ApiException: 4: 4:"

I am trying to add google play services in my android game. I have followed all the steps shown in https://developers.google.com/games/services/console/enabling this link.
I have added the app id in AndroidManifest.xml file.
Then, I followed the steps shown in this https://developers.google.com/games/services/android/signin link.
I am still getting this exception "com.google.android.gms.common.api.ApiException: 4: 4:" everytime. I guess the status code I am getting as a result is SIGN_IN_REQUIRED.
Do I have to release it for testing on the google play console. Can not I just test it by running on a physical device by using android studio?
class MainActivity : AppCompatActivity() {
var googleLogInResult =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
// There are no request codes
val result = Auth.GoogleSignInApi.getSignInResultFromIntent(result.data)
if (result.isSuccess) {
// The signed in account is stored in the result.
val signedInAccount = result.signInAccount
} else {
var message = result.status.statusMessage
if (message == null || message.isEmpty()) {
message = "signin_other_error"
}
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN
)
}
private fun signInSilently() {
val signInOptions = GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN
val account = GoogleSignIn.getLastSignedInAccount(this)
if (GoogleSignIn.hasPermissions(account, *signInOptions.scopeArray)) {
// Already signed in.
// The signed in account is stored in the 'account' variable.
val signedInAccount = account
Log.d("MainActivity", "Account is already signed in")
} else {
// Haven't been signed-in before. Try the silent sign-in first.
val signInClient = GoogleSignIn.getClient(this, signInOptions)
signInClient
.silentSignIn()
.addOnCompleteListener(
this
) { task ->
if (task.isSuccessful) {
// The signed in account is stored in the task's result.
val signedInAccount = task.result
Log.d("MainActivity", "sign in successful")
} else {
// Player will need to sign-in explicitly using via UI.
// See [sign-in best practices](http://developers.google.com/games/services/checklist) for guidance on how and when to implement Interactive Sign-in,
// and [Performing Interactive Sign-in](http://developers.google.com/games/services/android/signin#performing_interactive_sign-in) for details on how to implement
// Interactive Sign-in.
startSignInIntent()
/*Log.d("dsds", "sign in failed: " + (task.exception as ApiException).statusCode)*/
Log.d("MainActivity", "sign in failed: " + task.exception)
}
}
}
}
private fun startSignInIntent() {
val signInClient = GoogleSignIn.getClient(
this,
GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN
)
val intent = signInClient.signInIntent
googleLogInResult.launch(intent)
}
override fun onResume() {
super.onResume()
signInSilently()
}
}
Finally, I found my problem. I was logged in from different google account and it was not my tester account.

Google OneTap SignIn Pass or Error codes: 10 / 16

I'm trying to set up a Google OneTap SignIn button to my developed App (I'm not using Firebase to sign in) guiding by this source:
https://developers.google.com/identity/one-tap/android/get-started
I've created both OAuth & Web credentials on Cloud Console. To generate OAuth Id I took SHA1 which was provided by Android Studio in signing-in report (I took develop SHA-1, but they are all the same anyway).
I've put to R.string.default_web_client_id the Client Id from WebAuth (Not an Android Id from OAuth).
As I use Firebase RTDB for storing some data, I set this SHA-1 there as well. The project name in Manifest, Cloud Console and Firebase Console are the same. From Firebase I downloaded "google-services.json" and put it in app root. On Firebase I also set valid service email.
This is how I implemented OneTap on login activity:
class LoginActivity : AppCompatActivity() {
...
private lateinit var oneTapClient: SignInClient
private lateinit var signUpRequest: BeginSignInRequest
...
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
oneTapClient = Identity.getSignInClient(this)
signUpRequest = BeginSignInRequest.builder()
.setPasswordRequestOptions(BeginSignInRequest.PasswordRequestOptions.builder()
.setSupported(false)
.build())
.setGoogleIdTokenRequestOptions(BeginSignInRequest.GoogleIdTokenRequestOptions.builder()
.setSupported(true)
// Your server's client ID, not your Android client ID.
.setServerClientId(getString(R.string.default_web_client_id))
// Only show accounts previously used to sign in.
.setFilterByAuthorizedAccounts(false)
.build())
// Automatically sign in when exactly one credential is retrieved.
.setAutoSelectEnabled(false)
.build()
}
// THIS CALLED FROM FRAGMENT WHEN GOOGLE BUTTON IS CLICKED
fun onGoogleClick() {
when (GoogleApiAvailability().isGooglePlayServicesAvailable(applicationContext)) {
0 -> {
beginGoogleSignIn()
}
1 -> {
toaster.show("Google services required")
}
2 -> {
toaster.show("Google services update required")
}
}
}
private fun beginGoogleSignIn() {
val tag = "$atag-beginGoogleSignIn"
oneTapClient.beginSignIn(signUpRequest)
.addOnSuccessListener(this) { result ->
try {
startIntentSenderForResult(
result.pendingIntent.intentSender, library.GOOGLE_SIGNIN_REQUEST_CODE,
null, 0, 0, 0)
} catch (e: IntentSender.SendIntentException) {
logg.d(atag, "Couldn't start One Tap UI: ${e.localizedMessage}")
}
}
.addOnFailureListener(this) { e ->
// No Google Accounts found. Just continue presenting the signed-out UI.
toaster.show("Please sign in to your google account on your phone")
logg.d(tag, e.localizedMessage)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
val tag = "$atag-onActivityResult"
super.onActivityResult(requestCode, resultCode, data)
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == library.GOOGLE_SIGNIN_REQUEST_CODE) {
try {
val credential = oneTapClient.getSignInCredentialFromIntent(data)
token = credential.googleIdToken
when {
token != null -> {
// Got an ID token from Google. Use it to authenticate
// with your backend.
login = credential.id
name = credential.displayName
avatarUrl = credential.profilePictureUri.toString()
tryToLogin()
}
else -> {
// Shouldn't happen.
logg.d(atag, "No ID token!")
}
}
} catch (e: ApiException) {
when (e.statusCode) {
CommonStatusCodes.CANCELED -> {
toaster.show("Please sign in to your google account on your phone")
logg.d(tag, "One-tap dialog was closed.")
// Don't re-prompt the user.
}
CommonStatusCodes.NETWORK_ERROR -> {
logg.d(tag, "One-tap encountered a network error.")
// Try again or just ignore.
}
else -> {
logg.d(tag, "Couldn't get credential from result." +
" (${e.localizedMessage})")
}
}
}
}
}
}
The main problem is that on some of AVD it works well, on other AVD id gives an Error:
16: Cannot find a matching credential.
However on this AVD Google Services is up to date, and user is logged in to Google Play
On real device I got this error:
10: Caller not whitelisted to call this API.
Google services is also up to date here and user is logged in to Play Store.
Everywhere I used my real gmail address.
What can be wrong?
UPDATE
Spending a lot of time trying to solve this I have just figured out that OneTap is working on some devices, and is not working on other. Also tried to re-create credentials several times.
Not having very much time to solve this I just use both OneTap way and alternate way to sign in with Google credentials.
// In activity
lateinit var oneTapClient: SignInClient
lateinit var signUpRequest: BeginSignInRequest
private lateinit var gso: GoogleSignInOptions
lateinit var mGoogleSignInClient: GoogleSignInClient
private fun initApp() {
oneTapClient = Identity.getSignInClient(this)
signUpRequest = BeginSignInRequest.builder()
.setPasswordRequestOptions(
BeginSignInRequest.PasswordRequestOptions.builder()
.setSupported(false)
.build()
)
.setGoogleIdTokenRequestOptions(
BeginSignInRequest.GoogleIdTokenRequestOptions.builder()
.setSupported(true)
// Your server's client ID, not your Android client ID.
.setServerClientId(getString(R.string.default_web_client_id))
// Only show accounts previously used to sign in.
.setFilterByAuthorizedAccounts(false)
.build()
)
// Automatically sign in when exactly one credential is retrieved.
.setAutoSelectEnabled(false)
.build()
gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestProfile()
.requestEmail()
.requestIdToken(getString(R.string.default_web_client_id))
.build()
mGoogleSignInClient = GoogleSignIn.getClient(this, gso)
}
// Somewhere else in fragment, 'parent' is reference to activity
// Call this when button clicked
private fun beginGoogleSignIn() {
parent.oneTapClient.beginSignIn(parent.signUpRequest)
.addOnSuccessListener(parent) { result ->
try {
startIntentSenderForResult(
result.pendingIntent.intentSender, state.library.GOOGLE_SIGNIN_REQUEST_CODE,
null, 0, 0, 0, null)
} catch (e: IntentSender.SendIntentException) {
stopSignIn("Couldn't start One Tap UI: ${e.localizedMessage}")
}
}
.addOnCanceledListener(parent) {
stopSignIn("Cancelled")
}
.addOnFailureListener(parent) { e ->
// Use alternate sign in
val signInIntent = parent.mGoogleSignInClient.signInIntent
startActivityForResult(signInIntent, state.library.GOOGLE_ALT_SIGNIN_REQUEST_CODE)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == state.library.GOOGLE_SIGNIN_REQUEST_CODE) {
try {
handleOneTapSignIn(data)
} catch (e: ApiException) {
val message: String
when (e.statusCode) {
CommonStatusCodes.CANCELED -> {
message = "Please sign in to your google account on your phone"
// Don't re-prompt the user.
}
CommonStatusCodes.NETWORK_ERROR -> {
// Try again or just ignore.
message = "One-tap encountered a network error."
}
else -> {
message = "Couldn't get credential from result." +
" (${e.localizedMessage})"
}
}
stopSignIn(message)
}
} else if (requestCode == state.library.GOOGLE_ALT_SIGNIN_REQUEST_CODE) {
try {
handleAlternateSignIn(data)
} catch (e: ApiException) {
if (e.statusCode == 12501) {
// Dismissed
stopSignIn()
} else {
stopSignIn("${e.statusCode}")
}
}
}
}
private fun handleOneTapSignIn(data: Intent?) {
val credential = parent.oneTapClient.getSignInCredentialFromIntent(data)
val token = credential.googleIdToken
when {
token != null -> {
// Got an ID token from Google. Use it to authenticate
// with your backend.
login = credential.id
avatarUrl = credential.profilePictureUri?.toString() ?: ""
tryToLogin()
}
else -> {
// Shouldn't happen.
stopSignIn("No ID token!")
}
}
}
private fun handleAlternateSignIn(data: Intent?) {
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
try {
val account = task.getResult(ApiException::class.java)
// Signed in successfully, show authenticated UI.
login = account.email!!
token = account.idToken ?: ""
avatarUrl = account.photoUrl?.toString() ?: ""
tryToLogin()
} catch (e: ApiException) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
val message = when (e.statusCode) {
CommonStatusCodes.NETWORK_ERROR -> {
"Could not reach network"
}
else -> {
"SignIn failed with exception $e"
}
}
stopSignIn(message)
}
}
UPDATE 2
It seems 16: Cannot find a matching credential on Android Emulators is related not to user credentials attempting to sign in, but an app credential in Google Cloud Console.
The issue is not reproduced in my case when I filled consent page at Google Cloud Console as described at Get started with One Tap sign-in and sign-up
(I have left empty fields for links to EULA, etc.). Then I have changed package name (for another reasons), then double check that this package name was the same in both credentials configs on Google Cloud Console and in google-services.json. Also I checked that google-services.json is located under [project_root]/app directory.
I will check this on real device in a few days.

Categories

Resources