# Autologin with HttpRequest and SWebBrowser

**URL:** <https://forums.unrealengine.com/t/autologin-with-httprequest-and-swebbrowser/416587>\
**Category:** Platform & Builds\
**Tags:** browser, httprequest, unreal-engine, http, web-browser, question\
**Created:** [February 6, 2018, 4:23pm UTC](https://forums.unrealengine.com/t/autologin-with-httprequest-and-swebbrowser/416587 "2018-02-06T16:23:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![TagoWill](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TagoWill](https://forums.unrealengine.com/u/TagoWill)\
**Post date:** [February 6, 2018, 4:23pm UTC](https://forums.unrealengine.com/t/autologin-with-httprequest-and-swebbrowser/416587/1 "2018-02-06T16:23:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Ali\_Akbar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ali_akbar/32/1008648_2.png) [@Ali\_Akbar](https://forums.unrealengine.com/u/Ali_Akbar)\
**Post date:** [February 6, 2018, 5:23pm UTC](https://forums.unrealengine.com/t/autologin-with-httprequest-and-swebbrowser/416587/2 "2018-02-06T17:23:42Z")

</div>

Try this:

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

CookieManager->SetCookie(...);

```

[\>Code Link\<](https://github.com/EpicGames/UnrealEngine/blob/76085d1106078d8988e4404391428252ba1eb9a7/Engine/Source/Runtime/WebBrowser/Public/IWebBrowserCookieManager.h#L55)

[\>Usage\<](http://cdn-image.foodandwine.com/sites/default/files/styles/4_3_horizontal_-_1200x900/public/the-joy-of-cookies-cookie-monster-blog0817.jpg)

---

<div class="post-metadata">

**Author:** ![TagoWill](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TagoWill](https://forums.unrealengine.com/u/TagoWill)\
**Post date:** [February 7, 2018, 11:48am UTC](https://forums.unrealengine.com/t/autologin-with-httprequest-and-swebbrowser/416587/3 "2018-02-07T11:48:28Z")

</div>

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

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?

---

<div class="post-metadata">

**Author:** ![Ali\_Akbar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ali_akbar/32/1008648_2.png) [@Ali\_Akbar](https://forums.unrealengine.com/u/Ali_Akbar)\
**Post date:** [February 7, 2018, 2:47pm UTC](https://forums.unrealengine.com/t/autologin-with-httprequest-and-swebbrowser/416587/4 "2018-02-07T14:47:15Z")

</div>

You can grab it like this:

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

```

Here’s an [example](https://github.com/EpicGames/UnrealEngine/blob/dbced2dd59f9f5dfef1d7786fd67ad2970adf95f/Engine/Plugins/Online/OnlineFramework/Source/LoginFlow/Private/LoginFlowManager.cpp#L97)

---

<div class="post-metadata">

**Author:** ![TagoWill](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TagoWill](https://forums.unrealengine.com/u/TagoWill)\
**Post date:** [February 7, 2018, 10:14pm UTC](https://forums.unrealengine.com/t/autologin-with-httprequest-and-swebbrowser/416587/5 "2018-02-07T22:14:12Z")

</div>

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

Thank you.

---

<div class="post-metadata">

**Author:** ![TagoWill](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TagoWill](https://forums.unrealengine.com/u/TagoWill)\
**Post date:** [February 8, 2018, 3:00pm UTC](https://forums.unrealengine.com/t/autologin-with-httprequest-and-swebbrowser/416587/6 "2018-02-08T15:00:03Z")

</div>

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 ☹

---

<div class="post-metadata">

**Author:** ![Ali\_Akbar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ali_akbar/32/1008648_2.png) [@Ali\_Akbar](https://forums.unrealengine.com/u/Ali_Akbar)\
**Post date:** [February 8, 2018, 6:46pm UTC](https://forums.unrealengine.com/t/autologin-with-httprequest-and-swebbrowser/416587/7 "2018-02-08T18:46:53Z")

</div>

For debugging, could you try setting this [cookie](https://chrome.google.com/webstore/detail/editthiscookie/fngmhnnpilhplaeedifhccceomclgfbg?hl=en) 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

---

<div class="post-metadata">

**Author:** ![TagoWill](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@TagoWill](https://forums.unrealengine.com/u/TagoWill)\
**Post date:** [February 9, 2018, 9:58am UTC](https://forums.unrealengine.com/t/autologin-with-httprequest-and-swebbrowser/416587/8 "2018-02-09T09:58:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ali\_Akbar](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ali_akbar/32/1008648_2.png) [@Ali\_Akbar](https://forums.unrealengine.com/u/Ali_Akbar)\
**Post date:** [February 9, 2018, 10:49am UTC](https://forums.unrealengine.com/t/autologin-with-httprequest-and-swebbrowser/416587/9 "2018-02-09T10:49:08Z")

</div>

You’re welcome 🙂

---

<div class="post-metadata">

**Author:** ![markcham](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@markcham](https://forums.unrealengine.com/u/markcham)\
**Post date:** [October 19, 2022, 5:13pm UTC](https://forums.unrealengine.com/t/autologin-with-httprequest-and-swebbrowser/416587/10 "2022-10-19T17:13:29Z")

</div>

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