React Native
A mobile app is a frontend client: it gets each user token from your own backend, and never holds your client secret. See Authentication.
Vezgo Connect is compatible with the OAuth 2.0 Authorization Code flow (RFC 6749), so it can be added to a mobile app with readily available OAuth libraries. We recommend AppAuth. The flow is the same on every platform:
- Register a custom-scheme redirect URI for your app, for example
com.yourapp://vezgo. Redirect URIs must be registered with Vezgo. - Get a Vezgo user token from your backend.
- Open the Connect URL as the authorization endpoint, with your client ID, the redirect URI, and the user token as an additional
tokenparameter. Skip the code exchange: there is no token endpoint to call. - When the user finishes, Vezgo redirects back to your app. The authorization
codeit returns is the Vezgo account ID: send it to your backend and store it.
Open Connect
The Vezgo JS SDK works in React Native much as it does in a web app, except for opening Connect: user.connect() is not available, so open Connect with react-native-app-auth instead.
import { authorize } from 'react-native-app-auth';
import Vezgo from 'vezgo-sdk-js/dist/vezgo.es';
import { URL } from 'react-native-url-polyfill';
const clientId = 'YOUR_CLIENT_ID';
const redirectUrl = 'com.yourapp://vezgo'; // must be registered with Vezgo
const vezgo = Vezgo.init({
clientId,
// Set authEndpoint or an authorizer function, as in a web app
authEndpoint: '/vezgo/auth',
});
// On button click
const user = vezgo.login();
const token = await user.fetchToken();
// Or build the Connect URL with user.getConnectUrl()
const authorizeUrl = 'https://connect.vezgo.com/connect/coinbase';
// Now start the Vezgo Connect process
try {
const result = await authorize({
serviceConfiguration: {
authorizationEndpoint: authorizeUrl,
tokenEndpoint: authorizeUrl, // required by AppAuth
},
clientId,
redirectUrl,
additionalParameters: { token, lang: 'es' },
skipCodeExchange: true,
});
const accountId = result.authorizationCode;
sendToServer(accountId);
const account = await user.accounts.getOne(accountId);
displayAccount(account);
} catch (err) {
if (err.message !== 'Connection closed by the user') showError(err);
}