Multiple FCM Senders: Programmatically load Sender ID and Server Key on Mobile App

萝らか妹 提交于 2019-12-08 09:48:21

问题


As part of our solution, we deploy an FCM "app server" at each of our customer sites. Each customer site need to generate their own sender id and server id for use with our app.

The default FCM implementation places the Sender ID and Server Key in a plist (iOS) / json (Android) which is integrated into the app code at compile-time. However since we have multiple current customers and will have new customers, our mobile app needs to be able to make a service call to the customer App Server, retrieve the Sender ID and Server Key, and load those into FCM at runtime.

We've seen some documentation around getToken to accomplish registering with multiple senders, but we only need to register with 1 sender and completely bypass the plist/json.

Question: How can we programmatically load Sender ID and Server Key instead of using GoogleService-Info.plist (iOS) / google-services.json (Android).

For more context, here is our recent related question about security for the same workflow.


回答1:


places the Sender ID and Server Key in a plist (iOS) / json (Android) which is integrated into the app code at compile-time

There is nowhere in your client app that the Server Key is included. Like the name implies, the Server Key is kept on the App Server side. The only Sender ID that is included in the json/plist file you get from the Firebase Console is the Sender ID for your project. FCM doesn't use any kind of API key that is in the google-services.json file (see my answer here).

How can we programmatically load Sender ID and Server Key instead of using GoogleService-Info.plist (iOS) / google-services.json (Android).

When registering a new server, you would only need the Sender ID. Then simply call getToken(authorizedEntity, scope). This could be possible, by implementing a function that gets a list of valid senders from your App Server side and then have a copy on the client side, if there is a new Sender included, have your app authorize it as a valid sender.



来源:https://stackoverflow.com/questions/43615484/multiple-fcm-senders-programmatically-load-sender-id-and-server-key-on-mobile-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!