Firebase icon

Firebase

Interact with Firebase Admin SDK

Overview

This node integrates with the Firebase Admin SDK to manage Firebase Authentication features programmatically. Specifically, the "Create Custom Token" operation allows you to generate a custom authentication token for a specified user UID, optionally including additional custom claims in the token payload.

This is useful in scenarios where you want to create secure, custom authentication tokens for users to sign in to your Firebase-powered applications, especially when integrating external authentication systems or implementing advanced access control.

Practical example:
You have an external user management system and want to allow those users to authenticate with your Firebase app without using Firebase's default authentication methods. You can create a custom token for a user UID with specific claims (e.g., roles or permissions) and then use that token on the client side to sign in.

Properties

Name Meaning
User UID The unique identifier (UID) of the user for whom the custom token will be created.
Custom Claims Additional custom claims to embed in the token as a JSON object. These claims can include any key-value pairs relevant to your application's authorization logic.

Output

The node outputs a JSON object containing:

  • customToken: The generated Firebase custom authentication token string.
  • uid: The user UID for whom the token was created.
  • customClaims: The parsed JSON object of custom claims included in the token.
  • message: A success message indicating the token creation status.

Example output JSON:

{
  "customToken": "<firebase_custom_token_string>",
  "uid": "user123",
  "customClaims": {
    "role": "admin",
    "subscriptionLevel": "premium"
  },
  "message": "Custom token created successfully for user user123"
}

No binary data is produced by this operation.

Dependencies

  • Requires a valid Firebase service account JSON credential with appropriate permissions to manage authentication.
  • The node depends on the Firebase Admin SDK (firebase-admin/auth) to perform operations.
  • Proper configuration of the Firebase API credentials within n8n is necessary before using this node.

Troubleshooting

  • Invalid service account JSON format:
    If the provided Firebase service account JSON is malformed or invalid, the node will throw an error indicating the JSON parsing issue. Ensure the JSON is correctly formatted and complete.

  • Invalid custom claims JSON format:
    When specifying custom claims, if the JSON string is not valid, the node will raise an error. Verify that the custom claims input is a valid JSON object.

  • Permission errors:
    If the service account lacks sufficient permissions to create custom tokens, the operation will fail. Confirm that the service account has the required Firebase Authentication admin privileges.

  • General initialization failures:
    Errors during Firebase app initialization may occur due to incorrect credentials or network issues. Check credentials and connectivity.

  • Handling errors gracefully:
    If "Continue On Fail" is enabled, the node will output error messages per item instead of stopping execution.

Links and References

Discussion