Docs
  • What We Do
  • Supported Countries, Payment Methods, and Cryptocurrencies
  • Getting Started
  • Integration Guides
    • API
      • Required Headers
      • Create a User
      • Assign a Deposit Address
      • KYC
      • Link and Verify a Bank Account
        • Re-link Bank Account
        • Update Bank Account
        • Delete Bank Account
      • Transaction Limits
      • Buy Crypto (ACH)
      • Transaction Monitoring
      • Transaction History
    • React Native
      • Installation
      • Session Token and Wallet Signing
      • Preset Order Details
      • Example
      • Reference
      • Release History
      • User experience
        • Sign up
        • Sign in
        • Buy crypto
        • Settings & activity
    • React JS (Beta)
      • Installation
      • Session Token and Wallet Signing
      • Preset Orders
      • Callbacks
      • Theming
      • Example
      • Reference
      • Release History
  • API Reference
    • Endpoints
      • Auth
        • Crypto Wallet
        • Email OTP
        • SMS OTP
      • Activity
      • Bank
      • Client
      • Config
      • Crypto
      • Users
      • Wallets
      • Webhook Registrations
    • Custom Headers
    • Error Codes
    • Types Glossary
    • Postman
    • Open API Specification
    • Webhooks
  • Design Reference
    • UI/UX Starter kit
    • UI Requirements
  • Guides
    • Sandbox Testing
    • User Authentication
    • Link a new Signing Wallet to an Existing User
    • Plaid Bank Linking
      • Plaid OAuth Support
    • Client Dashboard (Alpha)
  • User Support Reference
    • User Account Flags
      • KYC Review
      • Transaction Processing
      • NSFs and Returned Payments
      • Fraud
    • Transactional Emails
Powered by GitBook
On this page

Was this helpful?

  1. Integration Guides
  2. React JS (Beta)

Session Token and Wallet Signing

Fetch Session Token and Auth with Wallet

PreviousInstallationNextPreset Orders

Last updated 1 year ago

Was this helpful?

Fetching a Session

In order to start the authentication process with Ratio you must provide the library with a function that will call Ratio's API.

fetchSessionToken

An async function that calls your backend to return the session token from the /v1/clients/session API.

The Ratio API uses client authentication which requires a client_id and client_secret. This client secret should be treated securely and should be protected within your backend.

const fetchSessionToken = async () => {
  try {
    let sessionTokenResponse = await fetch(
      'https://your.api.com/clients/session',
      {
        method: 'POST',
        body: JSON.stringify({
          signingAddress: walletAddress,
          depositAddress: walletAddress,
          signingNetwork: walletNetwork,
        }),
      }
    );

    let data = await sessionTokenResponse.json();
    return data.id;
  } catch (e) {
    console.error(e);
  }
  return null;
};
  
<RatioButton 
  fetchSessionToken={async () => {
            return await fetchSessionToken();
          }}/>
TYPE
REQUIRED

function

Yes

Wallet Signing

Ratio uses wallet authentication in order to link your client wallet to a Ratio user's account. To set up this authentication method you must provide the Ratio React Native Library with a signingCallback.

The return value from this function is of type string.

For example, using the Web3.js library

<RatioButton 
  signingCallback={async (challenge: string) => {
    let sign = web3.eth.accounts.sign(challenge, privateKey);

    return Promise.resolve(sign.signature);
  }}/>

The signing callback is an async function that accepts a string that contains the challenge that is returned from the Ratio /v1/auth/cryptoWallet:start call (). This will allow you to perform asynchronous activities, such as a biometrics check, during the signing.

documentation