如何将AndroidDebugkey添加到Google Cloud API密钥限制

发布于 2025-02-12 08:57:37 字数 551 浏览 4 评论 0原文

我开发了一个使用一些Google的APIS API(例如Firebase Cloud Messaging API,位置API ...)。 API键应仅限于我的特定应用程序以及该应用程序使用的所有Google API子集。因此,只需从我的应用程序就可以呼叫API,也应该只能调用一组定义的API,而不是全部。

选择API的子集很容易。也可以添加允许调用API的Android应用程序:我需要添加软件包名称和SHA1指定。所有这些都可以使用发布。但是调试构建使用使用AndroidDebugkey,它将自动创建。因此,每个开发人员都有自己的AndroidDebugkey。这与API限制如何相互作用?这是否意味着我必须将每个开发人员的每个证书都添加到控制台中?还是默认忽略了AndroidDebugkey?

请参阅下面的(德语)屏幕截图。

I develop an Android App, that uses some of Googles APIs (e.g. Firebase Cloud Messaging API, Places API...). The API Keys should be restricted to my specific App and to the subset of all Google APIs, that the app uses. So calls to the API should be possible just from my app and it should also be possible to call just a set of defined APIs, not all of them.

It is easy to select the subset of APIs. It was also possible to add the Android App, that is allowed to call the APIs: I needed to add the package-name and the SHA1-fingerprint. All of that is fine for release builds. But debug builds use the AndroidDebugKey, that gets automatically created. So every developer has her/his own AndroidDebugKey. How does this interplay with the API restrictions? Does this mean I would have to add every certificate of every developer to the console? Or gets the AndroidDebugKey ignored by default?

See my (german) screenshot below.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故人爱我别走 2025-02-19 08:57:37

最简单的方法是在开发人员之间共享调试密钥库,只是在团队成员(或从头开始创建一个)并将其投入到应用程序的存储库之间。

然后,您只需要更改Gradle文件即可指向此调试密钥库,以进行调试构建。例如,如果您选择使用AS生成的产品,则可以拥有类似的东西:

android {
    ...
    signingConfigs {
        debug {
            storeFile file("../local-build/debug.keystore")
            storePassword "android"
            keyAlias "androiddebugkey"
            keyPassword "android"
        }
    }
    ...
    buildTypes {
        debug {
            ....
            signingConfig signingConfigs.debug
        }
    }
}

debug.keystore足够安全,可以提交,因为PlayStore不接受与此密钥库签名的APK。

通过这种方式,您可以将他们正在处理的开发人员/机器解次,您只需要在Google控制台中添加一个SHA-1即可进行本地测试并确保API。

请注意不要在您的存储库中提交任何用于签署Play商店接受的产品和/或测试应用程序的数据(密钥库和密码)。

另一种方法可能是拥有经过身份验证的遥控器
签名当地构建代替开发人员的服务是
更安全,但设置更为复杂。

The easiest way is to share the debug keystore between developers, just choosing 1 keystore between your team members (or creating one from scratch) and committing it into the repository of your app.

Then you just need to change your gradle file to point to this debug keystore for debug builds. For example if you choose to use the AS generated one you can have something like:

android {
    ...
    signingConfigs {
        debug {
            storeFile file("../local-build/debug.keystore")
            storePassword "android"
            keyAlias "androiddebugkey"
            keyPassword "android"
        }
    }
    ...
    buildTypes {
        debug {
            ....
            signingConfig signingConfigs.debug
        }
    }
}

The debug.keystore is safe enough to commit because PlayStore does not accept an APK signed with this keystore.

In this way you decouple the developers/machines they are working on and you just need to add one SHA-1 in Google Console for local testing and for securing the API.

Be careful to not commit in your repo any data (keystore and passwords) that is used to sign your PROD and/or TEST app accepted by Play Store.

An alternative way could be to having an authenticated remote
service which signs your local builds in place of developers, it is
more secure but it is more complex to setup.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文