0

I'm using signedUrl in a PHP App Engine on Goolge Cloud to get the https:// link of stored files in firebase storage using the following code snippet:

$url = $object->signedUrl(
    new \DateTime('15 min'),
    [
        'version' => 'v4',
    ]
);

So the generated url is valid for 15 minutes. Calling this url after 15 minutes shows the following message in the browser:

<Error>
<Code>ExpiredToken</Code>
<Message>The provided token has expired.</Message>
<Details>Request signature expired at: 2021-07-16T11:29:51+00:00</Details>
</Error>

Is there a possibility to provide a custom error html page for this case? I've tried using

error_handlers:
  - file: default_error.html

in my app.yaml file but it doesn't work.

hannes
  • 83
  • 5
  • 1
    That error is generated by Google. I am not aware of any method to change the Google error with a custom message. I solve this same issue by generating links that go to a custom route in my webserver. I verify the client (session cookies) and then create the Signed URL and redirect the client to the Signed URL. – John Hanley Jul 16 '21 at 16:31

1 Answers1

0

Setting an error in app.yaml does not work, because the error is being generated by GCS, not GAE.

GCS does not provide a way to customize 403 error. If you need this, you will need something in front of GCS to provide the error to users. For example check signature & redirect as John suggests or create a GAE endpoint that does a GCS fetch and then either streams the result to the client or displays a 403.

David
  • 9,288
  • 1
  • 20
  • 52
  • OK - Thank you. Are there any Docs or Tutorials how to create a GAE endpoint that does a GCS fetch? I have to handle the case when a user refreshes a link like https://storage.googleapis.com/app.appspot.com/foo/bar/report.pdf?GoogleAccessId=getreport@app.iam.gserviceaccount.com&Expires=1626434991&Signature=XYZ in his browser after the link has expired. In this case we want to get a custom error message. – hannes Jul 23 '21 at 11:12