4️⃣Step 4 - Integrating Eartho into your server

1. Before we start, you need to import Eartho into your app.

2️⃣pageStep 2 - Import Eartho into your app

2. Integrating Eartho into your backend environment with code

If you use Eartho One with an app or site that communicates with a backend server, you can protect your routes easily with our SDK as well. After your users finish logging in with Eartho, they'll be returned to your application at the callback route.

On the client side

Every request that your client makes to your server, send with the ID token on the client side

const idToken = await earthoOne.getIdToken();
const response = await fetch('https://api.example.com/products', {
headers: {
      Authorization: `Bearer ${idToken}`
    }
  });

On the backend side

Check and verify the integrity of the ID token and use it to protect the API routes that you want to protect.

Step 1: Installing Required Packages

npm install @eartho/one-server-node

Step 2: Protecting Your Routes

Use the Eartho SDK to protect routes that require user authentication. For example, to protect a route that fetches user data, you would verify the user's ID token sent with the request.

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 don't have a backend environment, you can use no-code solution

If you don't have a backend, you can use Eartho in non-code environments as well.

The integration with Firebase empowers you to utilize Eartho to generate a valid authentication token to be sent to Firebase Auth. This integration allows you to harness Eartho's prebuilt components, authentication provider options, and additional functionalities, all while accessing Firebase products such as Firestore with a session authenticated by Firebase Auth.

1. Create a certificate file in Google

Generate a private key file in JSON format from Firebase accounts

  1. Open this URL Service Accounts

  2. Follow this video

2. Tell Eartho that you use Firebase Auth

Open our creators' dashboard https://creator.eartho.world/ 1. Pick the selected entity 2. Go to the security tab 3. Select Firebase environment 4. Upload the JSON file you created 5. Click Save and you're 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 ->
                 
                }
        });
        

Last updated