• I’m working on a mobile app in Flutterflow to serve as a front-end for my site. Flutterflow supports a JWT authentication method, which creates a user in a Firebase database. Basically, you use your site’s API to authenticate the user via username/password and to return a Firebase-friendly JWT, then the app stores that JWT in the Firebase database for your app.

    Is there any way to use a filter with a custom REST endpoint to support creating a JWT like below?

    Per the Firebase documentation, the code/payload to spit out a compliant JWT is

    // Requires: composer require firebase/php-jwt
    use Firebase\JWT\JWT;
    
    // Get your service account's email address and private key from the JSON key file
    $service_account_email = "[email protected]";
    $private_key = "-----BEGIN PRIVATE KEY-----...";
    
    function create_custom_token($uid, $is_premium_account) {
      global $service_account_email, $private_key;
    
      $now_seconds = time();
      $payload = array(
        "iss" => $service_account_email,
        "sub" => $service_account_email,
        "aud" => "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
        "iat" => $now_seconds,
        "exp" => $now_seconds+(60*60),  // Maximum expiration time is one hour
        "uid" => $uid,
        "claims" => array(
          "premium_account" => $is_premium_account
        )
      );
      return JWT::encode($payload, $private_key, "RS256");
    }

  • The topic ‘Modify to spit out Firebase-friendly JWT?’ is closed to new replies.