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.

In order to be able to handle password reset and account validation links, add the intent-filters and Associated Domains as illustrated below:

<platform name="android">
    <edit-config file="AndroidManifest.xml" target="/manifest/application/activity/[@android:name='MainActivity']" mode="merge">
        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="${notificareApplicationId}.applinks.notifica.re"
                android:pathPrefix="/oauth/resetpassword"
                android:scheme="https" />
        </intent-filter>

        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="${notificareApplicationId}.applinks.notifica.re"
                android:pathPrefix="/oauth/validate"
                android:scheme="https" />
        </intent-filter>
    </edit-config>
</platform>
<platform name="ios">
    <config-file target="Entitlements-*.plist" parent="com.apple.developer.associated-domains">
        <array>
            <string>applinks:$(NOTIFICARE_APPLICATION_ID).applinks.notifica.re</string>
        </array>
    </config-file>
</platform>

The Notificare library will automatically process the incoming links and trigger the appropriate events. Make sure you replace ${notificareApplicationId} and $(NOTIFICARE_APPLICATION_ID) with your own ID. You can find it 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, password and name.

await NotificareAuthentication.createAccount(email, password, name);

Validate an Account

By default, a newly created account will receive a validation email. This will contain a link to validate the email address. If you've set up the app as described above, the validation token event will be triggered.

NotificareAuthentication.onValidateUserTokenReceived((token) => {

});

Recover an Account

Provide your users with a way of requesting a new password when they forget it. You will have to acquire an email address from your user and call the following method. Upon success, an email with instructions will be sent to your user.

await NotificareAuthentication.sendPasswordReset(email);

Reset a Password

Provide your users with a way of changing their password upon request. This method will require both a new password and the token received in the email.

NotificareAuthentication.onPasswordResetTokenReceived((token) => {

});

Authenticate an Account

To authenticate the user invoke the following method:

await NotificareAuthentication.login(email, password);

User Details

Once the user is signed in you can easily get their data by calling the following method:

const user = await NotificareAuthentication.fetchUserDetails();

Push Email Address

At any time after they have signed in, you can generate a push email address. Once you call the method below, you can send remote notifications to your users using an email message. Every time this method is invoked a new token/email will be generated.

const user = await NotificareAuthentication.generatePushEmailAddress();

Change a Password

To provide your signed-in users with the means to change their password you can easily invoke the following method.

await NotificareAuthentication.changePassword('');

Sign out

To log out the user invoke the following method:

await NotificareAuthentication.logout();