如何使用PouchDB安全连接到Cloudant? [英] How can I securely connect to Cloudant using PouchDB?
问题描述
我正在使用Cordova / PhoneGap为Android和iOS创建移动应用程序,并使用IBM的Cloudant数据库进行存储。我正在使用PouchDB javascript库来访问Cloudant数据库。目前我有这个代码来访问它...
I am creating a mobile app for Android and iOS using Cordova/PhoneGap and am using IBM's Cloudant database for storage. I am using the PouchDB javascript library to access the Cloudant database. Currently I have this code to access it...
db = new PouchDB('https://[myaccount].cloudant.com/[mydb]', {
auth: {
username: 'myusername',
password: 'mypassword'
}
});
我知道这是非常不安全的,我想知道是否有更安全的连接方式从应用程序内部到我的数据库?
I am aware that this is extremely insecure, and am wondering if there is a more secure way to connect to my database from within the app?
推荐答案
您可能要考虑的一个选项是实施服务(例如在云端运行) )用于注册您的应用程序的新用户。注册逻辑可能如下所示:
One option you may like to consider is implementing a service (e.g. running in the cloud) for registering new users of your app. Registration logic could look something like this:
- 手机代码与您的应用服务通信,请求注册用户
- 该服务调用 Cloudant创建API密钥将返回到手机代码
- 手机代码会在设备上保存API密钥用户名和密码。然后在
auth:{用户名:'myusername',密码:'mypassword'}
对象中使用这些凭据。
- The handset code communicates with your application service requesting registration of the user
- The service makes a call to Cloudant to create an API key which would is returned to the handset code
- The handset code saves the API key 'username' and 'password' on the device. These credentials are then use in the
auth: { username: 'myusername', password: 'mypassword' }
object.
这篇关于如何使用PouchDB安全连接到Cloudant?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!