Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add request headers and cookies as new options #1024

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

lubbo
Copy link

@lubbo lubbo commented Sep 22, 2023

Platforms affected

  • iOS
  • Android

Motivation and Context

It's currently not possible to set cookies and request headers when opening the IAB.

Description

I'm adding two new options:

  • headers
    • key/value map json serialized and base64 encoded
  • cookies
    • key/value map json serialized and base64 encoded
    • key is the cookie URL
    • value is the json serialized and base64 encoded header Set-Cookie string

Limitations

  • iOS Cookies are set only if iOS11+

Testing

From JS side open the IAB with following options:

const headers = {
  Authorization: `Bearer exampleAccessToken`,
};
const headersString = JSON.stringify(headers);
//Needed because JS->Native parameters serialization uses = to key/value separator
const headersBase64 = btoa(headersString).replaceAll('=', '@');

const cookieOption: CookieSerializeOptions = {
        domain: 'www.mydomain.com',
        secure: true,
        path: '/',
        sameSite: 'strict',
      };

const serializedCookie = cookie.serialize(
        'TEST_NAME',
        'TEST_VALUE',
        cookieOption,
      );
const cookies = {
        ['https://www.mydomain.com']: serializedCookie,
      };
const cookiesString = JSON.stringify(cookies);
//Needed because JS->Native parameters serialization uses = to key/value separator
const cookiesBase64 = btoa(cookiesString).replaceAll('=', '@');

const options = {
  cookies: cookiesBase64,
  headers: headersBase64,
}
if (options && typeof options !== 'string') {
        options = Object.keys(options)
          .map((key: string) => `${key}=${(options as InAppBrowserOptions)[key]}`)
          .join(',');
      }

var ref = cordova.InAppBrowser.open('https://apache.org', '_blank', options);

Checklist

  • [?] I've run the tests to see all new and existing tests pass ()
  • [?] I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@lubbo lubbo changed the title feat: iOS - add first request headers and cookies as options feat: add request headers and cookies as new options Sep 22, 2023
@lubbo lubbo marked this pull request as draft September 22, 2023 15:35
@lubbo
Copy link
Author

lubbo commented Oct 3, 2023

Hi @janpio, can you take a look at this PR?

@Crylion
Copy link

Crylion commented Feb 29, 2024

Setting headers is a feature that I would also very much like to see :)

@sbl05
Copy link

sbl05 commented Mar 15, 2024

+1 to @Crylion This would be a really great addition! :)

@marcellov7
Copy link

Is it possible to merge this?

@kucki10

This comment was marked as abuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants