Skip to content

Can not request firebase function by using Cloud Task #157

@RTae

Description

@RTae

Hi, I have problem requesting a firebase function by using cloud task

this is my code

tasks_client = tasks_v2.CloudTasksClient()

task_queue = tasks_client.queue_path(
                params.PROJECT_ID.value, 
                SupportedRegion.US_CENTRAL1.value,
                DATA_TASK_NAME
            )
    
task = tasks_v2.Task(
            http_request= {
                "http_method": tasks_v2.HttpMethod.POST,
                "url": "https://cloudrune-service-generate-by-cloud-function.a.run.app",
                "headers":{"Content-type": "application/json"},
                "oidc_token": tasks_v2.OidcToken(
                    service_account_email=f"service_account@{settings.PROJECT_NAME}.iam.gserviceaccount.com",
                ),
                "body": json.dumps({"data":{"update_date": data['update_date']}}).encode()
            }
        )

It will raise an error about authentication.

ERROR:root:Error validating token: The Firebase ID token has an incorrect "aud" (audience) claim. Expected "PROJECT_ID" but got "https://cloudrune-service-generate-by-cloud-function.a.run.app". Make sure the ID token comes from the same Firebase project as the service account used to authenticate this SDK. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token.

WARNING: Root:Callable request verification failed: $[('Auth token was rejected.', {'app': 'MISSING', 'auth': 'INVALID', 'logging.googleapis.com/labels': {'firebase-log-type': 'callable-request-verification'}})]

if I add audience in oidc_token with project ID, it will raise another error

The request was not authorized to invoke this service. Read more at https://cloud.google.com/run/docs/securing/authenticating Additional troubleshooting documentation can be found at: https://cloud.google.com/run/docs/troubleshooting#401

From my understanding, both error are about authentication from firebase and cloud run

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions