I am creating JWT using documentation mentioned here.
Everything is done as mentioned in the documentation.
Here is the code snippet.
When I am returning this token to android client, Android client throws following error.
com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.auth.FirebaseAuthInvalidCredentialsException: The custom token format is incorrect. Please check the documentation.
I am not sure, what am I missing while creating token.
$service_account_email = "abc-123@a-b-c-123.iam.gserviceaccount.com";
$private_key = "-----BEGIN PRIVATE KEY-----VERY LONG KEY-----END PRIVATE KEY-----\n";//See github link for key if needed
$now_seconds = time();
$payload = array(
"iss" => $service_account_email,
"sub" => $service_account_email,
"aud" => "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
"iat" => $now_seconds,
"exp" => $now_seconds+(60*60), // Maximum expiration time is one hour
"uid" => $mobile
);
$token = JWT::encode($payload, $private_key, "HS256");