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 following item to your Associated Domains as illustrated below:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.developer.associated-domains</key>
    <array>
        <string>applinks:$(NOTIFICARE_APPLICATION_ID).applinks.notifica.re</string>
    </array>
</dict>
</plist>

This will allow your app to take control of the password and account activation processes when after users click the corresponding links from an automated email message. Make sure you replace $(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.

Notificare.shared.authentication().createAccount(email: email, password: password, name: name) { result in

}

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 handling a universal link, you will receive the event in your AppDelegate. You can handle it as illustrated below:

func application(_: UIApplication, continue userActivity: NSUserActivity, restorationHandler _: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    guard let url = userActivity.webpageURL else { return false }

    if let token = Notificare.shared.authentication().parseValidateUserToken(url) {
        Notificare.shared.authentication().validateUser(token: token) { result in

        }

        return true
    }

    // more code ...
}

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.

Notificare.shared.authentication().sendPasswordReset(email: "") { result in

}

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. If you set up the delegate method in your AppDelegate to handle universal links, you can parse the token from the incoming URL.

func application(_: UIApplication, continue userActivity: NSUserActivity, restorationHandler _: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    guard let url = userActivity.webpageURL else { return false }

    if let token = Notificare.shared.authentication().parsePasswordResetToken(url) {
        Notificare.shared.authentication().resetPassword(password, token: token) { result in

        }

        return true
    }

    // more code ...
}

Authenticate an Account

To authenticate the user invoke the following method:

Notificare.shared.authentication().login(email: "", password: "") { result in

}

User Details

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

Notificare.shared.authentication().fetchUserDetails { result in

}

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.

Notificare.shared.authentication().generatePushEmailAddress {

}

Change a Password

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

Notificare.shared.authentication().changePassword("newPassword") {

}

Sign out

To log out the user invoke the following method:

Notificare.shared.authentication().logout {

}