android-browser-helper icon indicating copy to clipboard operation
android-browser-helper copied to clipboard

Custom headers with TWALauncher

Open tobiasharle opened this issue 4 years ago • 3 comments

Hi,

I have built a TWA app that uses the TwaLauncher to launch.

I'm currently in a position where I need to send a token that was stored in a previous version of the native app to the web site which I'm starting. I thought the most suitable way to do this was to send it as a custom header.

So I took a look at the Custom Headers Demo and eventually got it working in my app.

However, the only way forward I could see was to copy the code from TwaLauncher into my own app and modify it. Besides adding the handle_all_urls relationship to my asset statements, it seems as if client.warmup is always required as well as mSession.validateRelationship(CustomTabsService.RELATION_USE_AS_ORIGIN, URL, null)

To avoid having to "own" all the TwaLauncher code, I guess I'm requesting some way to tell it to set up the extra validation for me. Or am I missing something?

Best Regards Tobias

tobiasharle avatar Aug 31 '21 10:08 tobiasharle

Looks like there isn't an easy way to invoke validateRelationship() from TwaLauncher. This seems like a valid feature request.

andreban avatar Aug 31 '21 14:08 andreban

So this means there is no way at present to add any extra headers using TwaLauncher?

It looks like this is where the intent gets picked up, TrustedWebActivityIntent.build:

Intent intent = mIntentBuilder.build().intent;

And we don't have access to the CustomTabsIntent.Builder, so there is no way to, for example to: headers.putString("bearer-token", "Some token")?

Does that then mean the only solution, if I am needing to add a Cookie header, is to use a chrome custom tab solution outlined in the CCT Custom Headers demo, rather than a TwaLauncher?

Or am I misinterpreting?

pmurrowanz avatar Dec 07 '21 06:12 pmurrowanz