Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {StyleSheet, Text, View, Button} from 'react-native';
import {Picker} from '@react-native-picker/picker';
import {GOOGLE, verifierMap} from './config';
import CustomAuth from '@toruslabs/customauth-react-native-sdk';
import auth from '@react-native-firebase/auth';
import {decode as atob} from 'base-64';

export default class App extends React.Component {
state = {selectedVerifier: GOOGLE, loginHint: '', consoleText: ''};
Expand Down Expand Up @@ -55,14 +57,49 @@ export default class App extends React.Component {
}
};

signInWithEmailPassword = async () => {
try {
const res = await auth().signInWithEmailAndPassword(
'[email protected]',
'Testing@123',
);
return res;
} catch (error) {
console.error(error);
}
};

parseToken = token => {
try {
const base64Url = token.split('.')[1];
const base64 = base64Url.replace('-', '+').replace('_', '/');
return JSON.parse(atob(base64 || ''));
} catch (err) {
console.error(err);
return null;
}
};

getTorusKey = async () => {
try {
const loginRes = await this.signInWithEmailPassword();
console.log('Login success', loginRes);
const idToken = await loginRes.user.getIdToken(true);
console.log('idToken', idToken);
const parsedToken = this.parseToken(idToken);

const verifier = 'web3auth-firebase-examples';
const verifierId = parsedToken.sub;

const getTorusKeyDetails = await CustomAuth.getTorusKey(
'torus-direct-mock-ios',
'[email protected]',
{verifier_id: '[email protected]'},
'eyJhbGciOiJSUzI1NiIsImtpZCI6ImY0MTk2YWVlMTE5ZmUyMTU5M2Q0OGJmY2ZiNWJmMDAxNzdkZDRhNGQiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiI2MzYxOTk0NjUyNDItZmQ3dWp0b3JwdnZ1ZHRzbDN1M2V2OTBuaWplY3RmcW0uYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiI2MzYxOTk0NjUyNDItZmQ3dWp0b3JwdnZ1ZHRzbDN1M2V2OTBuaWplY3RmcW0uYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMDkxMTE5NTM4NTYwMzE3OTk2MzkiLCJoZCI6InRvci51cyIsImVtYWlsIjoibWljaGFlbEB0b3IudXMiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiYXRfaGFzaCI6Ik9meERLU2JBUEE5Zjc1SGpQdUh5M3ciLCJub25jZSI6IlM5WmhVenJ1YTMiLCJuYW1lIjoiTWljaGFlbCBMZWUiLCJwaWN0dXJlIjoiaHR0cHM6Ly9saDMuZ29vZ2xldXNlcmNvbnRlbnQuY29tL2EvQUFUWEFKd3NCYjk4Z1NZalZObEJCQWhYSmp2cU5PdzJHRFNlVGYwSTZTSmg9czk2LWMiLCJnaXZlbl9uYW1lIjoiTWljaGFlbCIsImZhbWlseV9uYW1lIjoiTGVlIiwibG9jYWxlIjoiZW4iLCJpYXQiOjE2MzM2NjIyNDAsImV4cCI6MTYzMzY2NTg0MH0.nElQXYUDk-wC1nHJOAJ_JT7ZpkeiD6LPjixWImTm-h7vc2Je5zYbyupMOoIXVIQBploxcG2JMZXPDIhOXn9pXxasjdlOzMvT4a-xdPAvhuW0kQBBSxw2wwqRbzmFKzYnpsfmGRGjBYj8vjieQxiWV4hOgllePEPEn7At-VtTegUZC99Bblu2zhqblAF1I7ML5aKdmAvv2q1FK26i0WC5qQMZk9FFf9sk1DUJzxEp_RTDlgy_G0p7YUS99Olu3WPOIDsb5KKtjYOca006_G-onk6omKaPUklBxSNuhTilKpvQsT609OpsOAFKxaqTlGKfdwkahL_-Bm-rGRtGpoX8pw',
verifier,
verifierId,
{
verifierIdField: 'sub',
},
idToken,
);

console.log(getTorusKeyDetails);
} catch (error) {
console.error(error, 'getTorusKey failed');
Expand Down
1 change: 1 addition & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'

import com.android.build.OutputFile

Expand Down
270 changes: 270 additions & 0 deletions example/android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
{
"project_info": {
"project_number": "461819774167",
"project_id": "web3auth-oauth-logins",
"storage_bucket": "web3auth-oauth-logins.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:4ebbd2bfa882323e5b9c92",
"android_client_info": {
"package_name": "com.example.androidsfaexample"
}
},
"oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCL2uSXiGvQcfZ00IJ1g2uwC-7IcGZGVfQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "461819774167-3ebuiqr1ef4kjbvchpckvl1buqt2mr4c.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.w3arnfirebase"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:4b1a78bf91d324f95b9c92",
"android_client_info": {
"package_name": "com.example.w3aflutter"
}
},
"oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCL2uSXiGvQcfZ00IJ1g2uwC-7IcGZGVfQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "461819774167-3ebuiqr1ef4kjbvchpckvl1buqt2mr4c.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.w3arnfirebase"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:8b802f48df70f9a05b9c92",
"android_client_info": {
"package_name": "com.sbz.web3authdemoapp"
}
},
"oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCL2uSXiGvQcfZ00IJ1g2uwC-7IcGZGVfQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "461819774167-3ebuiqr1ef4kjbvchpckvl1buqt2mr4c.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.w3arnfirebase"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:266db02b56d2f8465b9c92",
"android_client_info": {
"package_name": "com.sbz.web3authdemoauth0"
}
},
"oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCL2uSXiGvQcfZ00IJ1g2uwC-7IcGZGVfQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "461819774167-3ebuiqr1ef4kjbvchpckvl1buqt2mr4c.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.w3arnfirebase"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:28440ba70afe767f5b9c92",
"android_client_info": {
"package_name": "com.tkeyrnexample"
}
},
"oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCL2uSXiGvQcfZ00IJ1g2uwC-7IcGZGVfQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "461819774167-3ebuiqr1ef4kjbvchpckvl1buqt2mr4c.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.w3arnfirebase"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:3c22c536b06b68135b9c92",
"android_client_info": {
"package_name": "com.web3authrnbarefirebase"
}
},
"oauth_client": [
{
"client_id": "461819774167-l7oslag3sa2vllbl1b9ghhcf6e6rhvjj.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.web3authrnbarefirebase",
"certificate_hash": "5e8f16062ea3cd2c4a0d547876baa6f38cabf625"
}
},
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCL2uSXiGvQcfZ00IJ1g2uwC-7IcGZGVfQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "461819774167-3ebuiqr1ef4kjbvchpckvl1buqt2mr4c.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.w3arnfirebase"
}
}
]
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:461819774167:android:aac2a2911fd308555b9c92",
"android_client_info": {
"package_name": "org.torusresearch.customauthexample"
}
},
"oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCL2uSXiGvQcfZ00IJ1g2uwC-7IcGZGVfQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "461819774167-5iv443bdf5a6pnr2drt4tubaph270obl.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "461819774167-3ebuiqr1ef4kjbvchpckvl1buqt2mr4c.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.w3arnfirebase"
}
}
]
}
}
}
],
"configuration_version": "1"
}
2 changes: 1 addition & 1 deletion example/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">customauthexample</string>
<string name="app_name">org.torusresearch.customauthexample</string>
</resources>
1 change: 1 addition & 0 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ buildscript {
}
dependencies {
classpath('com.android.tools.build:gradle:7.2.2')
classpath 'com.google.gms:google-services:4.3.15'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rootProject.name = 'customauthexample'
rootProject.name = 'org.torusresearch.customauthexample'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
36 changes: 36 additions & 0 deletions example/ios/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>461819774167-476pr2hn9dngturugvaum02vp07ko65a.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.461819774167-476pr2hn9dngturugvaum02vp07ko65a</string>
<key>ANDROID_CLIENT_ID</key>
<string>461819774167-l7oslag3sa2vllbl1b9ghhcf6e6rhvjj.apps.googleusercontent.com</string>
<key>API_KEY</key>
<string>AIzaSyAttkINEO4AWRc2jJDHa5fPYp_1EtujcH0</string>
<key>GCM_SENDER_ID</key>
<string>461819774167</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>customauthexample</string>
<key>PROJECT_ID</key>
<string>web3auth-oauth-logins</string>
<key>STORAGE_BUCKET</key>
<string>web3auth-oauth-logins.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:461819774167:ios:6fcb8f600a4360f55b9c92</string>
</dict>
</plist>
Loading