Couchdb external authentication
I am developing a family of utility apps where each app could be available on desktop, mobile and the web. After some research I decided to go with pouchdb on the client and couchdb on the server to provide offline sync.
A user would be able to create an account on the web (A Laravel Spark app) to manage their app subscriptions/payments and also access the web versions of the apps. On mobile and desktop the user would sign into each app using their credentials to unlock functionality.
I am planning on taking a database per user approach in couchdb with filtered replication (based on the app the files belong to). The basic requirement is for the user can sign in once in the apps and then securely replicate to couchdb forevermore (until sign out).
What would be the best approach to take for authentication with couchdb given the use case outlined below?
In the end I found the best approach to proxy all requests to CouchDB through Laravel, utilising the Passport package for API authentication.
To do this I hooked into the Spark::createUsersWith()
function in the SparkServiceProvider
to set up a CouchDB database on user registration via the following steps:
The user can then log into the app using their username and password to receive an OAuth2 password grant token.
All syncing requests are then made with the auth token to my sync proxy controller detailed in this gist.
To save a search PouchDB can be set up to send the OAuth token automatically as follows:
this._remoteDB = new PouchDB(url, {
ajax : {
headers : {
"Authorization" : "Bearer " + localStorage.getItem("token")
}
}
});
链接地址: http://www.djcxy.com/p/81152.html
上一篇: 使用第二台服务器的Couchdb认证
下一篇: Couchdb外部认证