authenticateIntoTheSdk

A callback to retrieve credentials to interface with the ReadyRemit API onbehalf of the sender

Overview

    +-------------+           +----------+           +------------+
    |  Customer   |----(2)--->| Customer |----(3)--->| ReadyRemit |
    | Application |<---(5)----|   API    |<---(4)----|    API     |
    +-------------+           +----------+           +------------+
           |
           |                  +------------+
            <----------(1)----| ReadyRemit |
            -----------(6)--->|    SDK     |
                              +------------+
  1. SDK calls back the authenticateIntoTheSdk to request a new authentication token.
  2. Customer application makes a network request to the Customer API to initiate the creation of an access token for the ReadyRemit SDK.
  3. Customer API makes a network request to the ReadyRemit API to create an access token for the ReadyRemit SDK.
  4. ReadyRemit API returns the access token details or an error.
  5. Customer API returns the access token details or an error.
  6. Customer application returns the access token details and makes authenticateIntoTheSdk callback return and AuthenticationResult object (Success or Error).

Expected objects to be sent by the app in the callback response to the sdk

TypeDescription
AccessTokenDetailsA credential representing the authorization granted by the resource owner (user) to the ReadyRemit SDK.
ReadyRemitErrorA generic representation of an error for the ReadyRemit SDK.

Sample Implementation


private val authenticateIntoTheSdk = suspend {
    withContext(Dispatchers.IO) {
        val authRequest = AuthRequest(
            clientId = "client_id",
            clientSecret = "client_secret",
            audience = "audience",
            grantType = "grant_type",
            senderId = "sender_id"
        )
        val response = oAuthApi.requestAuth(authURL, authRequest)
        val accessTokenResponse = response.body()
        if (response.isSuccessful && accessTokenResponse != null) {
            tokenValue = accessTokenResponse.accessToken
            AuthenticationResult.Success(
                AccessTokenDetails(
                    accessToken = accessTokenResponse.accessToken,
                    expiresIn = accessTokenResponse.expiresInSeconds,
                    scope = accessTokenResponse.scope,
                    tokenType = accessTokenResponse.tokenType
                )
            )
        } else {
            AuthenticationResult.Error(
                ReadyRemitError(
                    code = response.code().toString(),
                    message = response.message()
                )
            )
        }
    }
}