authenticateIntoTheSdk
A callback to retrieve credentials to interface with the PayMitto API onbehalf of the sender
Overview
+-------------+ +----------+ +------------+
| Customer |----(2)--->| Customer |----(3)--->| PayMitto |
| Application |<---(5)----| API |<---(4)----| API |
+-------------+ +----------+ +------------+
|
| +------------+
<----------(1)----| PayMitto |
-----------(6)--->| SDK |
+------------+- SDK calls back the authenticateIntoTheSdk to request a new authentication token.
- Customer application makes a network request to the Customer API to initiate the creation
of an access token for the PayMitto SDK. - Customer API makes a network request to the PayMitto API to create an access token for
the PayMitto SDK. - PayMitto API returns the access token details or an error.
- Customer API returns the access token details or an error.
- Customer application returns the access token details and makes
authenticateIntoTheSdkcallback return andAuthenticationResultobject (Success or Error).
Expected objects to be sent by the app in the callback response to the sdk
| Type | Description |
|---|---|
| AccessTokenDetails | A credential representing the authorization granted by the resource owner (user) to the PayMitto SDK. |
| PayMittoError | A generic representation of an error for the PayMitto 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(
PayMittoError(
code = response.code().toString(),
message = response.message()
)
)
}
}
}

