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 6
6
import com .google .android .gms .tasks .OnFailureListener ;
7
7
import com .google .android .gms .tasks .OnSuccessListener ;
8
8
import com .google .android .gms .tasks .Task ;
9
+ import com .google .firebase .auth .AuthCredential ;
9
10
import com .google .firebase .auth .AuthResult ;
10
11
import com .google .firebase .auth .FirebaseAuth ;
11
12
import com .google .firebase .auth .FirebaseUser ;
@@ -261,4 +262,30 @@ public void onFailure(@NonNull Exception e) {
261
262
});
262
263
// [END auth_oidc_provider_reauth]
263
264
}
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
+ }
264
291
}
Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ package com.google.firebase.quickstart.auth.kotlin
3
3
import androidx.appcompat.app.AppCompatActivity
4
4
import com.google.firebase.auth.FirebaseAuth
5
5
import 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
6
9
7
10
class GenericIdpActivity : AppCompatActivity () {
8
11
@@ -188,4 +191,24 @@ class GenericIdpActivity : AppCompatActivity() {
188
191
}
189
192
// [END auth_oidc_provider_reauth]
190
193
}
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
+ }
191
214
}
You can’t perform that action at this time.
0 commit comments