1

I'm building a Web.API to send notifications to iOS application via Firebase. I have integrated the Firebase admin SDK in .net project. As per the https://firebase.google.com/docs/reference/admin/dotnet, I implemented the below code. However I get an error when I call "VerifyIdTokenAsync". The error is "Incorrect number of segments in $ID token."

 var defaultApp = FirebaseApp.Create(new AppOptions()
            {
                Credential = GoogleCredential.FromFile(strFilePath),
            });

            // Retrieve services by passing the defaultApp variable...
            var defaultAuth = FirebaseAuth.GetAuth(defaultApp);

            FirebasVerifyIdTokenAsynceToken decodedToken = await defaultAuth.(deviceToken);
            string uid = decodedToken.Uid;

I checked several post and documentation online but all refer to the same code with no much further troubleshooting information. Please help.

2 Answers 2

1

An ID token (which is a type of JWT) must have exactly 3 segments, separated by periods: header.body.signature. The above error message is saying that the string you're passing as the ID token has some other number of segments. So your input string is not an ID token at all.

0

Thank you Hiranya Jayathilaka. You are right. I was using the APNS token instead of the registration token ID. I followed this article to fetch the registration token ID. We need to make a post request to

https://iid.googleapis.com/iid/v1:batchImport

Set headers to

Content-Type:application/json Authorization:key=YOUR_SERVER_KEY

And the body will contain the below

{ "application": YOUR_APPLICATION_BUNDLE_ID, "sandbox":false, "apns_tokens":[ YOUR_APNS_TOKEN, ] }

Also, when you make a call to the https://fcm.googleapis.com/fcm/send and you are sending push notification to a single device you should use the below JSON

string json = "{\"to\": \"" + regID + "\",\"notification\": {\"title\": \"New deal\",\"body\": \"20% deal!\"},\"priority\":10}";

If you are sending push notification to multiple devices, use the below JSON

string json = "{\"registration_ids\": [\"" + regID1 + "\", \"" + regID2 + "\" \"" + regIDN + "\"],\"notification\": {\"title\": \"New deal\",\"body\": \"20% deal!\"},\"priority\":10}";

Finally, I have my push notifications on my phone!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.