hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
407 stars 51 forks source link

Allow redirects where `Access-Control-Allow-Origin` header is restrictive #327

Open hjhart opened 3 months ago

hjhart commented 3 months ago

Similar issue to https://github.com/hotwired/turbo-android/issues/320, but it is slightly different.

I want to be able to handle external redirects to servers that do not have open Access-Control-Allow-Origin headers. I don't think there is a bug in the code, but I'd like to know where to hook in inside my android app to pop-up a CustomTab or something like that.

Here is an example of what I'm looking for:

https://github.com/hotwired/turbo-android/assets/547981/43c77601-152a-42cb-b2e5-d586512bd1fa

The external redirect works when it goes to https://turbo.hotwired.dev because of it's open Access-Control-Allow-Origin header.

~ ❱ curl -I https://turbo.hotwired.dev                                                                                                                                                                                                                                                                                                                            13:43:19
HTTP/2 200
...
access-control-allow-origin: *
...

The important bit in those headers is that access-control-allow-origin is set to allow all domains. But how should the turbo-android package handle it if we don't have access to set those headers (on, say, a third-party provider)? One option is to set up a proxy, but I'd love to avoid setting up any new infrastructure, as this works perfectly fine in a browser.

I'm working off of main on turbo-android (version 7.1.2), and using this server running locally: https://github.com/hjhart/turbo-native-demo

I think I should be breaking out of turbo, but I don't seem to have the proper hooks firing to do so (shouldNavigateTo doesn't fire, for instance).

Any input?

cc @jayohms I created a new issue since the previous issue was addressed and closed!

hjhart commented 3 months ago

Something I'm playing around with on my project (that is working) right now is having a erb file that does this:

File below: members/formstack/_special_android_redirect.html.erb

Redirecting you to: <%= location %>
<script type="text/javascript">
  window.location = "<%= location %>";
</script>

And instead of redirect_to location in the rails controller I am instead doing:

render partial: "members/formstack/special_android_redirect", locals: {location: location}

Right now there is a problem going back after navigating to the redirect location, but it'll likely be an easier solve for me.

If anyone has any insight into this, it's very welcome!