1.0.2 • Published 9 years ago

angular-eha.login-service v1.0.2

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
9 years ago

angular-eha.login-service

Build Status

Login service to handle CouchDB auth and auth renewal

Provides an convenience API for handling authentication with CouchDB in AngularJS applications.

Installation

Install with npm:

npm install --save angular-eha.login-service

Or alternatively, Bower:

bower install --save angular-eha.login-service

Usage

Pass in a CouchDB database endpoint to authenticate against via ehaLoginServiceProvider.config:

angular.config(function(ehaLoginServiceProvider) {
  ehaLoginServiceProvider.config('https://couchdb.example.com/mydb')
})

API

ehaLoginService.config

Takes a function that must return a promise that must resolve with an array containing a username and password (in that order).

This is used to prompt user for their credentials (via maybeShowLoginUi). It defaults to window.prompt, but see angular-eha.login-dialog as an example Bootstrap-based implementation.

ehaLoginService.getUserName

Returns the locally stored username, or null.

ehaLoginService.maybeShowLoginUi

If the credentials have already been saved locally, return them. Otherwise, prompt the user for them, save them locally and return them.

ehaLoginService.hasLocalCreds

Returns true if both username and password have been saved locally.

ehaLoginService.login

Takes a username and password, logs into CouchDB (via pouchdb-authentication) and stores the credentials locally.

ehaLoginService.renew

If the credentials have already been saved locally, renew the user's CouchDB session (by calling ehaLoginService.login).

ehaLoginService.logout

Deletes local credentials.

ehaLoginService.storeCredentials

Takes a username and password and saves them locally.

See also

Contributors

License

Released under the Apache 2.0 License.