Fetch Access Token Details

Provide authentication to the SDK

Overview

    +-------------+           +----------+           +------------+
    |  Customer   |----(1)--->| Customer |----(2)--->| ReadyRemit |
    | Application |<---(4)----|   API    |<---(3)----|    API     |
    +-------------+           +----------+           +------------+
           |
           |                  +------------+
            -----------(5)--->| ReadyRemit |
                              |    SDK     |
                              +------------+
  1. Customer application makes a network request to the Customer API to initiate the creation of an access token for the ReadyRemit SDK
  2. Customer API makes a network request to the ReadyRemit API to create an access token for the ReadyRemit SDK
  3. ReadyRemit API returns the access token details or an error
  4. Customer API returns the access token details or an error
  5. Customer application returns the access token details or throws an error

Contract


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>
  );
}