E
E
Eartho Docs
Eartho. Docs - Infrastructure
Search
K
Links

Step 4 - (Optional) Integrating Eartho into your server

If you use Eartho One with an app or site that communicates with a backend server, you can protect your routes easily by our SDK as well. After your users finish logging in with Eartho, they'll be returned to your application at the callback route.
Your Server
Firebase Auth
AWS Cognito
  1. 1.
    On the client, every request that your client make to your server, send with the ID token on client side
e server, check and verify the integrity of the ID token and use it to protect the API routes that you want to protect.
const idToken = await earthoOne.getIdToken();
const response = await fetch('https://api.example.com/products', {
headers: {
Authorization: `Bearer ${idToken}`
}
});
2. On the server, check and verify the integrity of the ID token and use it to protect the API routes that you want to protect.
NODE.JS
npm install @eartho/one-server-node
NODE.JS
const {EarthoOne} = require('@eartho/one-server-node');
const serverEarthoOneOptions = {
clientId: "client id",
clientSecret: "secret key"
}
const serverEarthoOne = new EarthoOne(serverEarthoOneOptions);
//Or check by yourself
getEarthoOne()
.getVerifiedUser(idToken)
.then((decodedToken) => {
const uid = decodedToken.uid;
const displayName = decodedToken.displayName;
const email = decodedToken.email;
const photoURL = decodedToken.photoURL;
// ...
})
.catch((error) => {
// Handle error
});
if you want to store your users on firebase auth and enjoy firebase environment, you can easily do it.

1. Create certificate file in google

Generate a private key file in JSON format from firebase accounts
  1. 1.
    Open this URL Service Accounts
  2. 2.
    Follow this video

2. Tell Eartho that you want use Firebase Auth

Open the our creators dashboard https://creator.eartho.world/ 1. Pick the selected entity 2. Go to security tab 3. Select firebase environment 4. Upload the json file you created 5. Click Save and you done 🎉

3. Authenticate with Firebase on Using a Custom

  • More Info Android
  • More Info Swift
    Login with firebaseAuth.signInWithCustomToken Example:
    earthoOne.connectWithRedirect("V1te8aEqOJNtPseu3VTe",
    onSuccess = { result ->
    firebaseAuth.signInWithCustomToken(result)
    .addOnCompleteListener(this) { task ->
    }
    });