How to implement Google SignIn OAuth2 authentication in your App? - Android Studio Java | API 34

preview_player
Показать описание

It also shows the steps to create a new project in the Google's cloud platform and create OAuth2.0 credentials. Please note that for the implementation to work, one needs to create both web client and Android application type OAuth 2.0 credentials. Though the in the code only web application type client ID would be required for directing the authentication.

Complete source code and other details/ steps of this video are posted in the below link:

However, the main Java code is copied below also for reference:

public class MainActivity extends AppCompatActivity {
private TextView textView;
private SignInClient oneTapClient;
private BeginSignInRequest signInRequest;
private static final int REQ_ONE_TAP = 100;

protected void onCreate(Bundle savedInstanceState) {

.setSupported(true)
.build())
.setSupported(true)
// Your server's client ID, not your Android client ID.
// Only show accounts previously used to sign in.
.setFilterByAuthorizedAccounts(false)
.build())
// Automatically sign in when exactly one credential is retrieved.
.setAutoSelectEnabled(true)
.build();
}
public void buttonGoogleSignIn(View view){

.addOnSuccessListener(this, new OnSuccessListener-BeginSignInResult-() {
@Override
public void onSuccess(BeginSignInResult result) {
try {
startIntentSenderForResult(
null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
}
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
// No saved credentials found. Launch the One Tap sign-up flow, or
// do nothing and continue presenting the signed-out UI.
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
switch (requestCode) {
case REQ_ONE_TAP:
try {
if (idToken != null) {
// Got an ID token from Google. Use it to authenticate
// with your backend.
Log.d(TAG, "Got ID token.");
} else if (password != null) {
// Got a saved username and password. Use them to authenticate
// with your backend.
Log.d(TAG, "Got password.");
}
} catch (ApiException e) {
}
break;
}
}
}

--
Рекомендации по теме
Комментарии
Автор

If I keep watching your tutorials, I'll be a Principal Developer by this October

antoniofuller
Автор

Hey everything works for the most part. However, some methods are deprecated, I was wondering if you have an update on this topic with the non deprecated methods.

nameisanameforaname
Автор

I'm commenting again like I promised, this video helped me. My code is successful

antoniofuller
Автор

its working when WE put Web application" client ID but when putting android client id it throws exception whY SIR please explain..

AmarKumar-vobv
Автор

can you provide github link for this project

SajidShaikh-kn
Автор

Hi! I did all code. The app made in Android Studio works ok. But after publish that version can not sign up. After click the button nothing happens. The options acoount to select do not appers in screen. It s not possivible debug it. Did you ( or someone here) know what is going on?

fernandox
Автор

i have problem sir,

your tutorial is perfectly right,

but when i build in apk mode releasewith keystore/ jks + proguard, it says "developer console is not set up correctly"

can u explain to me sir? thanks before

mangacandota
Автор

If this video helps me, I will comment again

antoniofuller
Автор

Missing Feature{name=auth_api_credentials_begin_sign_in, version=9}

i need help with this error, i followed all of the steps but it turns out google wont appear when i press the google button

zulu
Автор

Sir. I have problem. 10:developer console not set up correctly

gpslocationtrackersasasak