Mobile support
Mobile applications are considered frontend clients, so most of the concepts and examples for Frontend Client can be applied.
The Vezgo SDK JS can be used in ReactNative apps mostly the same way it is used in web applications. The main difference is that the user.connect().onConnection()
helper that opens the Vezgo Connect process is not available in ReactNative.
The Vezgo Connect process, however, is compatible with oAuth 2.0 Authorization Code flow (https://datatracker.ietf.org/doc/html/rfc6749#section-4.1). Therefore it can be easily added to your mobile application using readily available oAuth mobile libraries.
We recommend the AppAuth oAuth library for integrating Vezgo Connect (or any oAuth 2.0 services) to your mobile application.
iOS/Mac: https://github.com/openid/AppAuth-iOS
Android: https://github.com/openid/AppAuth-Android
ReactNative: https://github.com/FormidableLabs/react-native-app-auth
ReactNative example
import { authorize } from 'react-native-app-auth';
import Vezgo from 'vezgo-sdk-js/dist/vezgo.es5';
import {URL} from 'react-native-url-polyfill';
const clientId = 'YOUR_CLIENT_ID';
const redirectUrl = 'com.yourapp://vezgo'; // need to be registered
const vezgo = Vezgo.init({
clientId,
// Set authEndpoint or authorizer function similar to web app
authEndpoint: '/vezgo/auth',
});
// On button click
const user = vezgo.login();
const token = await user.fetchToken();
// Or build connect URL via 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);
}