FirebaseInstanceId

public class FirebaseInstanceId extends Object

Firebase Instance ID provides a unique identifier for each app instance and a mechanism to authenticate and authorize actions (example: sending FCM messages).

Instance ID is stable except when:

  • App deletes Instance ID
  • App is restored on a new device
  • User uninstalls/reinstall the app
  • User clears app data
In the above cases a new Instance ID is generated and the application needs to recreate the authorization tokens previously generated implementing onTokenRefresh().

To prove ownership of Instance ID and to allow servers to access data or services associated with the app, call getToken(String, String).

Public Method Summary

void
deleteInstanceId()
Resets Instance ID and revokes all tokens.
void
deleteToken(String authorizedEntity, String scope)
Revokes access to a scope (action) for an entity previously authorized by getToken().
long
getCreationTime()
Returns time when instance ID was created.
String
getId()
Returns a stable identifier that uniquely identifies the app instance.
static FirebaseInstanceId
getInstance()
Returns an instance of this class.
synchronized static FirebaseInstanceId
getInstance(FirebaseApp app)
Returns an instance for the given FirebaseApp.
String
getToken(String authorizedEntity, String scope)
Returns a token that authorizes an Entity to perform an action on behalf of the application identified by Instance ID.
String
getToken()
Return the master token for the default Firebase project.

Inherited Method Summary

Public Methods

public void deleteInstanceId ()

Resets Instance ID and revokes all tokens.

Throws
IOException

public void deleteToken (String authorizedEntity, String scope)

Revokes access to a scope (action) for an entity previously authorized by getToken().

This is a blocking function so do not call it on the main thread.

Parameters
authorizedEntity Entity that must no longer have access.
scope Action that entity is no longer authorized to perform.
Throws
IOException if the request fails.

public long getCreationTime ()

Returns time when instance ID was created.

Returns
  • Time when instance ID was created (milliseconds since Epoch).

public String getId ()

Returns a stable identifier that uniquely identifies the app instance.

Returns
  • The identifier for the application instance.

public static FirebaseInstanceId getInstance ()

Returns an instance of this class.

Returns
  • FirebaseInstanceId instance.

public static synchronized FirebaseInstanceId getInstance (FirebaseApp app)

Returns an instance for the given FirebaseApp.

Parameters
app FirebaseApp instance.
Returns
  • FirebaseInstanceId instance.

public String getToken (String authorizedEntity, String scope)

Returns a token that authorizes an Entity to perform an action on behalf of the application identified by Instance ID.

This is similar to an OAuth2 token except, it applies to the application instance instead of a user.

For example, to get a token that can be used to send messages to an application via FirebaseMessaging, set to the sender ID, and set to "FCM".

This is a blocking function so do not call it on the main thread.

Parameters
authorizedEntity Entity authorized by the token.
scope Action authorized for authorizedEntity.
Returns
  • a token that can identify and authorize the instance of the application on the device.
Throws
IOException if the request fails.

public String getToken ()

Return the master token for the default Firebase project.

Returns
  • the master token or null if the token is not yet available

Send feedback about...

Need help? Visit our support page.