When do GCM Tokens Expire and What is the InstanceID?

后端 未结 3 787
执笔经年
执笔经年 2020-12-08 19:57

Since GCM keeps getting updated, most of the resources I have searched seem outdated or unclear. Basically, I am confused over when the tokens and ID\'s expire. (For referen

3条回答
  •  悲哀的现实
    2020-12-08 20:33

    What is Instance ID?

    Instance ID provides a unique ID per instance of your apps. You can implement Instance ID for Android and iOS apps as well as Chrome apps/extensions.

    In addition to providing unique IDs for authentication, Instance ID can generate security tokens for use with other services.

    Key Features

    • Generate Security Tokens
    • Verify app authenticity
    • Confirm app device is active
    • Identify and track apps

    Instance ID lifecycle

    1. The Instance ID service issues an InstanceID when your app comes online. The InstanceID is backed by a public/private key pair with the private key stored on the local device and the public key registered with the Instance ID service.
    2. Your app can request a fresh InstanceID whenever needed using the getID() method. Your app can store it on your server if you have one that supports your app.
    3. Your app can request tokens from the Instance ID service as needed using the getToken() method, and like InstanceID, your app can also store tokens on your own server. All tokens issued to your app belong to the app's InstanceID.
    4. Tokens are unique and secure, but your app or the Instance ID service may need to refresh tokens in the event of a security issue or when a user uninstalls and reinstalls your app during device restoration. Your app must implement a listener to respond to token refresh requests from the Instance ID service.

    When does Instance ID become invalid?

    • App deletes Instance ID
    • Device is factory reset
    • User uninstalls the app
    • User clears app data

    If Instance ID has become invalid, the app can call getId() to request a new Instance ID. To prove ownership of Instance ID and to allow servers to access data or services associated with the app, call getToken(String, String).

    When to refresh tokens?

    The Instance ID service initiates callbacks periodically (for example, every 6 months), requesting that your app refreshes its tokens. It may also initiate callbacks when:

    There are security issues; for example, SSL or platform issues. Device information is no longer valid; for example, backup and restore. The Instance ID service is otherwise affected.

    All you need to know about Instance ID can be found in the following official links:

    • https://developers.google.com/instance-id/
    • https://developers.google.com/android/reference/com/google/android/gms/iid/InstanceID
    • https://developers.google.com/instance-id/guides/android-implementation#refresh_tokens

提交回复
热议问题