Cookie based authentication in inappbrowser


#1

I’m trying to make an app that uses the authorization based on cookies. But I have a problem. I can not get cookies from the server in the application. I can see them in the Chrome Dev Tools and I want to use them to authenticate the other pages that open up in inapp browser.
The first thing is I hit an API to login to my app, on the chrome dev tool response I can see the cookie, how can I use it to further authenticate the webpages that I open up in inapp browser???


#2

Can you not just read them with plain 'ole javascript?

I’m sure there’s a better way in Angular, but try this as a band-aid:

https://www.w3schools.com/js/js_cookies.asp

// Read cookie
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0) === ' ') {
            c = c.substring(1,c.length);
        }
        if (c.indexOf(nameEQ) === 0) {
            return c.substring(nameEQ.length,c.length);
        }
    }
    return null;
}

#3

what I’m trying to do is saving the cookie to a local variable so that I can use it for further auth in other link.
I need to know how can I save it from the response I get from a post request.


#4

Read the cookie with the function above, then use the Storage module to keep it for later use.


#5

I tried reading the cookie but got “Null”.