Firebase Token Authentication Error

Firebase Token Authentication error

I think you didn't sign before uploading files. In onCreate() of launcher activity, try this code

FirebaseAuth mAuth = FirebaseAuth.getInstance(); 

Then in onStart(),

FirebaseUser user = mAuth.getCurrentUser();
if (user != null) {
// do your stuff
} else {
signInAnonymously();
}

signInAnonymously()

private void signInAnonymously() {
mAuth.signInAnonymously().addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
// do your stuff
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e(TAG, "signInAnonymously:FAILURE", exception);
}
});
}

This may solve your problem

Note: Initially enable anonymous sign-in in your firebase project. Authentication -> Sign-in method

Firebase authentication error with custom token

It seems that the token returns by kakaoService.getAccessToken() is not a valid custom token for Firebase Authentication. In fact, given the error message, it doesn't even seem to be a JWT.

Custom tokens for Firebase Authentication must have a specific format, that is documented in creating custom tokens. You'll typically want to follow this process to get a valid token for Firebase Authentication:

  1. Sign the user in to the identity provider (KakaoTalk in your case).
  2. Decode the token from the provider, to get the verified information about the user.
  3. Create a custom token for the user with the Firebase Authentication Admin SDK.
  4. Use that token to sign in to Firebase on the client.

Steps 2 and 3 must happen in a trusted environment, such as your development machine, a server you control, or Cloud Functions.

Flutter Firebase Auth - INVALID_REFRESH_TOKEN (Firebase Emulator)

There can be multiple reasons for this error. I am just listing some pointers for you to check :

Enable :

  1. This can be caused by a disabled Email/Password sign in, which is
    disabled by default. Enable the Authentication section in the
    Firebase console as shown below or you can temporarily try the
    "anonymously" / guest sign in in Firebase Console.

  2. Enable the Token Services API in Google Cloud Console

  3. Enable Cloud Firestore API

Sample Image

If you are using the local Authentication emulator, then it is possible to let your app talk to it by connecting to this using the useAuthEmulator method. In Flutter libraries, this has landed in version 0.20 and later of the firebase_auth package.

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();

// Ideal time to initialize
await FirebaseAuth.instance.useAuthEmulator('localhost', 9099);
//…
}

If you are using the local Firestore emulators, then it is possible to let your app talk to it by connecting to this using the useFirestoreEmulator method.

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();

// Ideal time to initialize
FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080);
//...
}
  • Try upgrading to the latest version of firebase.
  • Ensure you pass the correct port on which the emulator is running on.
  • Ensure you have enabled network connections to the emulators in your
    apps following the emulator usage instructions in the general
    FlutterFire installation notes for each operating system.

Update :

For anyone visiting this question, these pointers above did not help our OP for her case, what helped her was, compare current google-services.json from the project with the one that the Firebase console generates, after you generate the SHA-1 Key (to create an OAuth2 client and API key for your app. Check this stackoverflow thread it explains how you can add SHA-1 Key. If you want to do this using terminal, have a look at this article) And it turned out they were not quite the same. So adding the new google-service.json to project under android/app and executing flutter clean was the trick.

Firebase - Auth custom token error auth/network-request-failed

This error arises because the Auth object takes time to initialise. Though you are using a timeout but that does not guarantee the successful initialisation.

According to Firebase docs here the recommeded way to check whether sign in is successful and get the current user is to set an observer on the Auth object. So to resolve this error do the redirection window.location.href inside the onAuthStateChanged observer.

Hope this helps!!

Android firebase throws authentication error while trying to access storage

Paste this in your google.json:

service firebase.storage {
// The {bucket} wildcard indicates we match files in all storage buckets
match /b/{bucket}/o {
// Match filename
match /filename {
allow read: if true;
allow write: if true;
}
}
}


Related Topics



Leave a reply



Submit