Why InstanceID always returns a token despite of wrong senderId?

159 Views Asked by At

I'm using Google Cloud Messaging api to implement an Android client. To get a token, I do:

   InstanceID ex = InstanceID.getInstance(this.getApplicationContext());
   String regId = ex.getToken(senderId, "GCM", null);

And regId always contains a token, despite of I put on senderId. If I set senderId with "123", InstanceID returns a token! (But the, I don't receive notifications with this token). Why I always get a token? I expect an exception, or a null value maybe...

1

There are 1 best solutions below

0
On

You may always get a token but you will not be able to use it to establish the full gcm lifecycle since instanceId is tied to your app server's senderId.

From the google documentation

Use the getToken method to prove the ownership of the InstanceID and to allow servers to access data or services associated with the app. The method follows the patterns of OAuth2, and requires an authorizedEntity and scope. The authorizedEntity can be a project ID or another InstanceID, and it determines the services that are authorized to use the generated token. The scope determines the specific service or data to which the token allows access.

To understand more of the lifecycle, refer to the documentation