The input is not a valid Base64 string as it contains a non-base 64 character

Viewed 6873

I am receiving below token to my asp.net core api from flutter mobile app , which I need to send to firebase api to verify my token and get firebase uid. My code in .net core is

   FirebaseToken decodedToken = await FirebaseAuth.DefaultInstance.VerifyIdTokenAsync(token);
   string uid = decodedToken.Uid;

I get the error as

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

I tried adding '=' at the end to make the length divisible by 4 . But didnt work . Can anyone help ?

token = "eyJhbGciOiJSUzI1NiIsImtpZCI6IjZjZmMyMzViZDYxMGZhY2FlYzVlYjBhZGU5NTg5ZGE5NTI4MmRlY2QiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoiUHJhYmhha2FyIiwiYWRtaW4iOnRydWUsImlzcyI6Imh0dHBzOi8vc2VjdXJldG9rZW4uZ29vZ2xlLmNvbS9ydXRodW1hbmEtYXBwIiwiYXVkIjoicnV0aHVtYW5hLWFwcCIsImF1dGhfdGltZSI6MTU5NTE3MTE4MCwidXNlcl9pZCI6IjVVTUVoY1pGUklQUVRZSXYyUkt4Tk01cTdHbzIiLCJzdWIiOiI1VU1FaGNaRlJJUFFUWUl2MlJLeE5NNXE3R28yIiwiaWF0IjoxNTk1MzYxNDQyLCJleHAiOjE1OTUzNjUwNDIsImVtYWlsIjoicHJhYmhha2FyYmhhdEBsaXZlLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJwaG9uZV9udW1iZXIiOiIrOTE4NTUzNzUyNzQyIiwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJwaG9uZSI6WyIrOTE4NTUzNzUyNzQyIl0sImVtYWlsIjpbInByYWJoYWthcmJoYXRAbGl2ZS5jb20iXX0sInNpZ25faW5fcHJvdmlkZXIiOiJwaG9uZSJ9fQ.N-fFCQHnJkdVcSqRQQ7XetEPQEeLCjOofjv3UogJlehLlUiJZhoKO6UWnb_liNxuTaFQ7tzvl03rHbm12na6KkhMup0J_UkC7HCyG6EtZmCgc8KmFRoYtHbztiCNI9v26QLPI_5C-KCnMDJdnvmGfuhh5NmmR5gC1LVuXMxZxaQFzcs1fkuA_8mCY1t4s0x0mQyeBUdrLVZnWdVSzM9-g1WZ0xrCrcsf7WTdWpuWeRmSIJSmNagP_l7R-uYUnTtwNISgFVn4mhSz4O1dqav7167TK2Z1PQD1QDhMA3FTIoYsc9izdlXQvmkbLxkq8dvhgxYVY"
2 Answers

A possible cause of this issue is that the idToken you received was truncated in the console output, resulting in an invalid token. This is a reported issue, see here, Flutter's print() method seems to only print a maximum of 1024-bit so a idToken is likely to be truncated. If you wish to get the token to appear fully, either:

  • With debug mode, inspect the idToken value
  • Without debug mode, use the log(token) method by import 'dart:developer'; instead of print()
Related