Authentication module - GeoSmartCity-CIP/gsc-client GitHub Wiki

The gsc.user module implements login methods and a user interface widget for authentication of users of GSC applications. It provides means to login, logout and send password reminders for users who remembers their usernames, typically an e-mail address, but has forgotten their passwords. This may be used as a building block in any application that requires authentication.

The library can be used both to authenticate users programmatically as well as interactively through the dialogue widget. Unless used with an encrypted (https) end-point, authentication details will be transmitted as clear-text and may be vulnerable to interception.

Dependencies

jQuery and Bootstrap libraries are required to use the functionality. The service also relies on an instance of the GSC Datacatalogue for handling the requests from the JavaScript library.

User accounts are isolated into groups so that the same web server can power many applications and user domains. Each group is called an organization and prior to using the library, it is necessary for the developer to register an organization (and thus receive an organization ID) to isolate his/her users.

##API API is available at GitHub src/user/user.js.

Examples

The following sections exemplify user registration, login, update and deletion, gradually. All of them implement Promise pattern, which enables to specify method then applying callbacks: the first called on success, the second on failure.

###User registration

gsc.user.register('[email protected]', 'runarbe2', 'pwd', 'pwd', [{'organization': 1}])
    .then(function(res) {
        // Success
        console.log('Success: ' + res.description);
        var userId = res.id;
        ...
    }, function(res) {
        // Failure
        console.log('Failure: ' + res.description);
        ...
    })

###User login

gsc.user.login('runarbe2', 'pwd')
    .then(function(res) {
        console.log(res.description);
        ...

###User update

gsc.user.update(userId, '[email protected]', 'runarbe2', [{'organization': 1}])
    .then(function(res) {
        console.log(res.description);
        ...

###User deletion

gsc.user.delete('runarbe2', 'pwd')
    .then(function(res) {
        console.log(res.description);
        ...