6

I am using cordova inappbrowser Plugin.

When I opened URL in any mobile browser below popup come but when same url I tried to open through inappbrowser I am not getting this authentication popup. Its showing 401 authentication error directly.

enter image description here

Why this behavioral change? IS there anything I have to provide to get same behavior like browser?

Or is there I can directly pass username and password? So how can I implement basic authentication?

I have tried with form submission way also.

<form name="frm" id="frm" method="POST" action="http://sample.xyz/test">
   <input type="hidden" name="username" id="username" value="abc" />
   <input type="hidden" name="password" id="password" value="xyz" />
</form> 

Also I have tried below also which I got by googling.

window.open("http://abc:xyz@sample.xyz/test");

help me out.

Suhas Gosavi
  • 2,170
  • 19
  • 40
  • 1
    Does it work if you remove the single quotes from your URL? ie. window.open("http://abc:xyz@sample.xyz/test"); You should be able to pass auth credentials this way using the inappbrowser. – Jordan Burnett Jun 23 '17 at 13:28
  • @JordanBurnett Please see my updated question. yah I tried without single quotes getting same error. – Suhas Gosavi Jun 23 '17 at 13:30
  • @Suhas Check the answer and let me know if you have any problem. If you still face the 401, add a a screenshot of the error message too – Sagar V Jun 26 '17 at 13:20
  • @SagarV normal 401 error saying access is denied due to invalid credentials. Even is come even I didnt passed credential in window.open – Suhas Gosavi Jun 26 '17 at 13:51
  • Just open a test page which contains `alert("ABC");` and let me know what happens – Sagar V Jun 26 '17 at 14:01
  • Does it happen on iOS, Android or both? – jcesarmobile Jun 26 '17 at 17:54
  • @jcesarmobile i didnt checked on iOS. Will check nd confirm. Checked only on android. – Suhas Gosavi Jun 26 '17 at 17:55
  • I now that it is a long time ago but are there any updates on that issue? I am currently facing similar problems, especially because I have special characters in my usernames and passwords and therefore I am searching for a solution/workaround... – Daniel05 Apr 08 '20 at 08:59
  • Have you found a solution to this? – antimatter Dec 09 '20 at 09:37
  • Yes. Before url just include username:pwd@url this wil work – Suhas Gosavi Dec 09 '20 at 09:39

2 Answers2

-1

That is not a login form from any page. It is an htaccess(or similar) authentication.

So, you can't simply supply credentials via a login form.

There is a discussion regarding this in Google Groups

The method you tried

window.open("http://'abc':'xyz'@sample.xyz/test");

Change it to

window.open("http://abc:xyz@sample.xyz/");

Or

window.open("http://abc:xyz@sample.xyz/test");

This will authenticate you to the site.

Sagar V
  • 12,158
  • 7
  • 41
  • 68
-1

InAppBrowser by default works with url only.

If your link require sending parameters via POST you should try this approche:

            var postParams = {
                "param1": param,
                "param2": param2
            };

            var pageContent = '<html><head></head><body><form id="loginForm" action="' + siteAddress + '" method="post">' +
                '<input type="hidden" name="postParams" value="' + encodeURI(JSON.stringify(postParams)) + '">' +
                '</form> <script type="text/javascript">document.getElementById("loginForm").submit();</script></body></html>';
            var pageContentUrl = 'data:text/html;base64,' + btoa(pageContent);

            ref = window.open(pageContentUrl, '_blank', 'location=no,zoom=no,hidden=yes,disallowoverscroll=no,toolbar=no,clearcache=no,clearsessioncache=no');
fatalica
  • 117
  • 9