File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
auth/app/src/main/java/com/google/firebase/quickstart/auth Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 66import com .google .android .gms .tasks .OnFailureListener ;
77import com .google .android .gms .tasks .OnSuccessListener ;
88import com .google .android .gms .tasks .Task ;
9+ import com .google .firebase .auth .AuthCredential ;
910import com .google .firebase .auth .AuthResult ;
1011import com .google .firebase .auth .FirebaseAuth ;
1112import com .google .firebase .auth .FirebaseUser ;
@@ -261,4 +262,30 @@ public void onFailure(@NonNull Exception e) {
261262 });
262263 // [END auth_oidc_provider_reauth]
263264 }
265+
266+ public void manuallySignIn (String idToken ) {
267+ // [START auth_oidc_provider_signin_manual]
268+ AuthCredential credential = OAuthProvider
269+ .newCredentialBuilder ("oidc.example-provider" ) // As registered in Firebase console.
270+ .setIdToken (idToken ) // ID token from OpenID Connect flow.
271+ .build ();
272+ FirebaseAuth .getInstance ()
273+ .signInWithCredential (credential )
274+ .addOnSuccessListener (new OnSuccessListener <AuthResult >() {
275+ @ Override
276+ public void onSuccess (AuthResult authResult ) {
277+ // User is signed in.
278+
279+ // IdP data available in:
280+ // authResult.getAdditionalUserInfo().getProfile()
281+ }
282+ })
283+ .addOnFailureListener (new OnFailureListener () {
284+ @ Override
285+ public void onFailure (@ NonNull Exception e ) {
286+ // Handle failure.
287+ }
288+ });
289+ // [END auth_oidc_provider_signin_manual]
290+ }
264291}
Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ package com.google.firebase.quickstart.auth.kotlin
33import androidx.appcompat.app.AppCompatActivity
44import com.google.firebase.auth.FirebaseAuth
55import com.google.firebase.auth.OAuthProvider
6+ import com.google.firebase.auth.ktx.auth
7+ import com.google.firebase.auth.ktx.oAuthCredential
8+ import com.google.firebase.ktx.Firebase
69
710class GenericIdpActivity : AppCompatActivity () {
811
@@ -188,4 +191,24 @@ class GenericIdpActivity : AppCompatActivity() {
188191 }
189192 // [END auth_oidc_provider_reauth]
190193 }
194+
195+ fun manuallySignIn (idToken : String ) {
196+ // [START auth_oidc_provider_signin_manual]
197+ val providerId = " oidc.example-provider" // As registered in Firebase console.
198+ val credential = oAuthCredential(providerId) {
199+ setIdToken(idToken) // ID token from OpenID Connect flow.
200+ }
201+ Firebase .auth
202+ .signInWithCredential(credential)
203+ .addOnSuccessListener { authResult ->
204+ // User is signed in.
205+
206+ // IdP data available in:
207+ // authResult.additionalUserInfo.profile
208+ }
209+ .addOnFailureListener { e ->
210+ // Handle failure.
211+ }
212+ // [END auth_oidc_provider_signin_manual]
213+ }
191214}
You can’t perform that action at this time.
0 commit comments