Fetch Access Token Details
Provide authentication to the SDK
Overview
+-------------+ +----------+ +------------+
| Customer |----(1)--->| Customer |----(2)--->| ReadyRemit |
| Application |<---(4)----| API |<---(3)----| API |
+-------------+ +----------+ +------------+
|
| +------------+
-----------(5)--->| ReadyRemit |
| SDK |
+------------+- Customer application makes a network request to the Customer API to initiate the creation of an access token for the ReadyRemit SDK
- Customer API makes a network request to the ReadyRemit API to create an access token for the ReadyRemit SDK
- ReadyRemit 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 or throws an error
Contract
- Called when the SDK requests authentication.
- Must resolve to ReadyRemitTokenResponse on success or ReadyRemitError on failure.
Return Type
See ReadyRemitTokenResponse and ReadyRemitError for detailed type documentation.
export interface ReadyRemitTokenResponse {
accessToken: string;
expiresIn: number;
scope: string;
tokenType: string;
}
export interface ReadyRemitError {
code: string;
message: string;
}Sample Implementation
import type { ReadyRemitTokenResponse, ReadyRemitError } from 'react-native-ready-remit-sdk';
export const fetchAccessTokenDetails = async (): Promise<ReadyRemitTokenResponse | ReadyRemitError> => {
const url = 'https://example.com/v1/oauth/token';
const response = await fetch(url, { method: 'POST' });
if (!response.ok) {
return { code: 'UNSUCCESSFUL_RESPONSE', message: String(response.status) };
}
return (await response.json()) as ReadyRemitTokenResponse;
};
...
import React from 'react';
import { Button, View } from 'react-native';
import {
startSDK,
ReadyRemitEnvironment
} from 'react-native-ready-remit-sdk';
export default function App() {
const onPress = () => {
startSDK({
configuration: { environment: ReadyRemitEnvironment.Sandbox },
fetchAccessTokenDetails: fetchAccessTokenDetails,
...
};
return (
<View style={{ padding: 24 }}>
<Button title="Start ReadyRemit" onPress={onPress} />
</View>
);
}
Updated 4 days ago
