使用旧的身份验证令牌将用户迁移到新应用-InstallReferrer自定义参数

时间:2018-07-04 15:30:13

标签: java android kotlin google-play install-referrer

我在Google Play上有两个应用。新旧的。我想对新应用使用旧的身份验证令牌,以使用户更轻松。

  1. 在旧应用上,用户会弹出一个窗口以在Google Play上安装新应用。
  2. 我想将参数中的auth令牌传递给Google Play。
  3. 安装新应用后,我想将令牌保存在新的一个应用中。

我尝试使用Play Install Referrer Library,但没有用。

另一种方法是使用SharedPreferences,但不推荐使用MODE_WORLD_READABLE

旧版应用程序:

try {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.<PACKAGENAME>&token=pokpok&refresh_token=lolol"));
    startActivity(intent);
} catch (Exception e) {
    e.printStackTrace();
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.<PACKAGENAME>?token=pokpok&refresh_token=lolol")));
}

新的APP代码:

    private fun shouldGetTokenFromOldApp() {
        mReferrerClient = InstallReferrerClient.newBuilder(this).build()
        mReferrerClient.startConnection(object : InstallReferrerStateListener {

            override fun onInstallReferrerSetupFinished(responseCode: Int) {
                when (responseCode) {
                    InstallReferrerClient.InstallReferrerResponse.OK -> {
                        // Connection established
                        val response: ReferrerDetails = mReferrerClient.installReferrer
                        val url = "https://play.google.com/store?${response.installReferrer}"
                        Log.d("APP", "Token old app 1 : $url")
                        val uri: Uri = Uri.parse(url)
                        val token = uri.getQueryParameter("token")
                        val refreshToken = uri.getQueryParameter("refresh_token")

                        Log.d("APP", "Token old app 2 : $token - $refreshToken")
                        mReferrerClient.endConnection()
                    }
                    InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
                        // API not available on the current Play Store app
                    }
                    InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
                        // Connection could not be established
                    }
                }
            }

            override fun onInstallReferrerServiceDisconnected() {
                // Try to restart the connection on the next request to
                // Google Play by calling the startConnection() method.
            }
        })
    }

1 个答案:

答案 0 :(得分:2)

对于用户来说,这听起来不错,但似乎非常危险。您正在发送一个Auth令牌-如果有人拥有Auth令牌,则该令牌可以允许他们通过不受信任的系统(例如世界可读文件或URL中的引用参数)以该用户的任何身份登录。

如果您确实需要这样做,建议您在安装应用程序后使用某种形式的应用程序间RPC(IPC)来传达令牌。一种选择是向提供身份验证的服务a binder