livedigital Chat SDK usage: authentication
After integrating and implementing a basic chat flow, you need to setup appropriate authentication scheme. There are two of them currently available: external and password-based. You may implement your own auth flow by adoping Authenticator
protocol.
Dummy authenticators
There is a HardcodedAuthenticator
class declared in Chat SDK that implements Authenticator
protocol. You initialize an instance with a given token and this token value will be passed into fetchToken
completion closure each time the method is called. You may use HardcodedAuthenticator
during development or for unit testing; this class should not be used in production.
External authentication
To use external authentication flow, you should have user authentication mechanism inside your application and integrate with livedigital Chat M2M API on your app server.
External authentication scheme is implemented in ExternalAuthenticator
class. You may optionally pass initial token value during instantiation. To make it work, you must set a delegate for the authenticator object. Each time chat core needs a token to make a server request, token is fetched from Authenticator. If Authenticator doesn’t have a valid token, it fetches fresh token from its delegate. Delegate object fetches chat token from application server.
Password-based authentication
Password-based authentication may be appropriate if you build a chat app around livedigital SDK, or when you building a general purpose app where you don’t need to authorize user in the app itself, or you don’t have app-specific server to integrate with Chat M2M API.
User enters his name and password, which are passed into PasswordAuthenticator
entity. After that you don’t participate in authentication flow from the application side. Authenticator fetches chat_token from Chat server when needed and uses it to sign subsequent server requests.