简体   繁体   中英

Passing current session/token of FirebaseAuth from Native Android App to a WebView's Firebase App

Scenario

  • It is a hybrid app (Most of Android Native Java and part html/ javascript in a WebView )
  • FirebaseAuth for authentication/signIn [in Android Native app]
  • Firestore as database
  • Serverless app

I want to
pass the Authentication from Android Native app which was done via FirebaseAuth
TO
html/javascript screens which are being embedded as Webview in my app, so that i can call my Firebase DB without asking user to relogin.

What I Tried
i tried to signIn using signInWithCustomToken and used the token generated from getidtokenresult which throws error "INVALID_CUSTOM_TOKEN"

Any guidance will be helpful

You can use the Firebase Admin SDK in your Native app to generate a valid token for your client app to use with signInWithCustomToken()

Token Generation:

//The uid should uniquely identify the user or device you are authenticating
String uid = "some-uid";

String customToken = FirebaseAuth.getInstance().createCustomToken(uid);
// Send token back to client

Use in client app:

firebase.auth().signInWithCustomToken(token).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...
});

There is further information about this in the Firebase docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM