Autologin with HttpRequest and SWebBrowser

Hi everyone,

I’m developing a game and I have an in-game browser widget. I’m opening a webpage that has a login form and I want to perform seamless authentication (automatically fill it and authenticate or use an already authenticated session).

Right now I’m using IHttpRequest to handle the POST request when I do a manual login. I managed to retrieve a cookie with the session id.

Now my question is, how can I feed the information about the authenticated session to the SWebBrowser to be able to skip the login form?

Try this:

TSharedPtr<IWebBrowserCookieManager> CookieManager = IWebBrowserSingleton::GetCookieManager();

CookieManager->SetCookie(...);

>Code Link<

>Usage<

I like to thank you to spend time with my problem. I wasn’t finding the correct class to set the cookie :slight_smile:

Unfortunately, the IWebBrowserSingleton::GetCookieManager() is non-static, so I can’t just call it like that. I have to find I way to retrieve it.

Do you have any ideas how to do it?

You can grab it like this:

IWebBrowserSingleton* WebBrowserSingleton = IWebBrowserModule::Get().GetSingleton();
WebBrowserSingleton->GetCookieManager();

Here’s an example

Actually that may work. I will try it tomorrow and I will update you.

Thank you.

Something is still missing… or maybe I’m looking at the wrong way to do it.

IWebBrowserSingleton* WebBrowserSingleton = IWebBrowserModule::Get().GetSingleton();

TSharedPtr<IWebBrowserCookieManager> CookieManager = WebBrowserSingleton->GetCookieManager();
	
IWebBrowserCookieManager::FCookie CookieVariable;

//Right now I'm hard coding the cookie into @CookieVariable
//I got the values from the cookie manager of mozilla with a fresh session
CookieVariable.Name = "JSESSIONID";
CookieVariable.Value = "34325DS......";
CookieVariable.bHasExpires = false;
CookieVariable.bHttpOnly = true;
CookieVariable.bSecure = false;
CookieVariable.Domain = "http://...";
CookieVariable.Path = "/**something**";

//@Response is my HttpRequest response.
CookieManager->SetCookie(Response->GetURL(), CookieVariable);

After that, I reload the page but the login form still appears…

Note: That doesn’t happen if I do a manual login and re start the game :frowning:

For debugging, could you try setting this cookie from the computer’s chrome browser in incognito mode and load the page to check if it requires login. If so, your cookies are incorrect

You are right. Probably my cookies are incorrect. I refresh the page and it asks me again for the login credentials.

I will try to see if I find the correct cookies and set them.

I will mark this topic has answered. If I come up with problems again I will re-open it.

Thank you so much for the help Ali.

You’re welcome :slight_smile:

This is exactly what I’m looking for. Do you happen to still have the code you used to implement this?