Skip to main content

Authenticator

When an MQTT client tries to make a connection with an MQTT broker, username and password are sent inside CONNECT packet, which the broker uses to authenticate the client. If username or password is incorrect, broker returns reason code 5.

Courier library uses the Authenticator to refresh the connect options, which contains the username and password, in order to reconnect with the broker successfully.

You can pass your own implementation of Authenticator interface or uses the library provided HttpAuthenticator

Http Authenticator

Courier library provides an implementation of Authenticator, which allows you to fetch the latest connect options by making an HTTP call.

Usage

Add this dependency for using Http Authenticator

dependencies {
implementation "com.gojek.courier:courier-auth-http:x.y.z"
}

An instance of HttpAuthenticator can be created using the factory class.

httpAuthenticator = HttpAuthenticatorFactory.create(
retrofit = retrofit,
apiUrl = TOKEN_AUTH_API,
responseHandler = responseHandler,
eventHandler = eventHandler,
authRetryPolicy = authRetryPolicy
)