SDK

Authentication

This is an add-on feature of the Notificare library. You will need to subscribe to the Users & Authentication add-on and configure this service as described here. With this feature your application can provide creation, authentication and management of user accounts.

In this page we will dive deeper into this functionality. This functionality is built based on the OAuth2 standard, providing your application with the means to create accounts, authenticate users, send email activations, recover and change passwords and refresh access tokens when needed.

First, make sure you declare the following URL Schemes in your app's .plist file:

ios oauth2 url scheme

Make sure you replace {{APP_ID_HERE}} with your app's own ID. You can find the ID in your app's configuration page, as described here.

Create an Account

You are able to create an account by simply invoking the method below and providing three required parameters: email, name and password.

Notificare.createAccount(email, name, password).then((result) => {
  //Handle success
}).catch((e) => {
  //Handle error
});

Validate an Account

By default, a newly created account will receive a validation email. This will contain a link to validate the email address. When users click in that email, it will open your app and trigger the following event which you should use to validate the account:

Notificare.on('activationTokenReceived', function(data) {
  Notificare.validateAccount(data.token, function(result) {
    //Handle success
  }, function(error) {
    //Handle error
  });
});

Recover an Account

Provide your users with a way of requesting a new password when they forget it. You will have to request the email address from your user and call the following method:

Notificare.sendPassword(email, function(result) {
  //Handle success
}, function(error) {
  //Handle error
});

Upon success, an email with instructions will be sent to your user containing a link that allows the user to complete the password reset process. When a user clicks in that link, your app will open and a token will be passed to your code via the following event:

Notificare.on('resetPasswordTokenReceived', function(data) {
  //Keep a reference of the data.token
});

Keep a reference to that token and build UI to be able to capture the new password. Then, with the token received previously and the new password provided by the user, you can use the following method to complete this operation:

Notificare.resetPassword(password, token, function(result) {
  //Handle success
}, function(error) {
  //Handle error
});

After this point, you user will be able to sign in using the new password.

Authenticate an Account

To authenticate the user invoke the following method:

Notificare.login(email, password, function(result) {
  //Handle success
}, function(error) {
  //Handle error
});

User Details

When a user is authenticated, you can easily get their data by calling the following method. On success it will return the user object.

Notificare.fetchAccountDetails(function(user) {
  //Handle success
}, function(error) {
  //Handle error
});

Access Token

At any time after the user is signed in you can generate a access token. This will also create a Push Mail address. Once you generate an access token, you can send push remote notifications to your users via email. Every time this method is invoked a new token/email will be generated.

Notificare.generateAccessToken(function(result) {
  //Handle success
}, function(error) {
  //Handle error
});

Change a Password

To provide your authenticated in users with the means to change their password you could build UI that requires the user to insert a new password and then invoke the following method:

Notificare.changePassword(password, function(result) {
  //Handle success
}, function(error) {
  //Handle error
});

Sign out

To end a user session invoke the following method:

Notificare.logout(function(result) {
  //Handle success
}, function(error) {
  //Handle error
});