Hi guys just wondering if anyone could explain how to setup the blueprint to use vaREST and UMG to create a user login system. Every thread I found pointed me to the plugin but I can’t find any tutorials on how to do it.
This is just a quick guide, not a proper tutorial – I haven’t seen any, yet.
Setup your REST server that will respond to authentication by replying with either Success or Failure (and session key perhaps?). We did this in node.js with mysql back end, but other solutions are as viable (any web service that will serve request will do, even if it only supports GET and POST). Test it that it works when you use browser or any of the browser extensions to help with this. I use Postman for Chrome.
In UnrealEngine Create Widget with username and password fields and a button. Bind OnClicked action to this button, that creates request, and process response. You may want to disable the button after sending the request, until its processed. If request succeeds, you may want to ‘Remove From Parent’ the widget with login fields, and do whatever you plan to do next.
This post has a clear screenshot on how everything hangs together:
It is a little bit out of date since there were new features since the post, but overall principle is the same. Example doesn’t pass any input parameters, but it shows how to handle response. In your widget, this will be triggered from your OnClicked event.
This post from ufna clearly shows how to construct request parameters:
Once you get your OnComplete called, connect Request to GetResponseObject(), and from Response, GetStringField() – (or other types) that you need. Note that ‘OnRequestFail’ is called when there is 404 or 500 error, or timeout. NOT when user successfully typed wrong password. You’ll get OnRequestComplete, hopefully with message that it ‘failed’ – from step 1.
From architecture point of view, you shouldn’t let client talk to your back end directly. If possible, let client connect to Unreal Dedicated Server, then pass login info via RPC’s, and then get Dedicated Server to talk to your web service. That way you can limit only dedicated server to have access to web service (by IP range, or by a fact that service doesn’t even have public IP address).
Your Dedicated Server can throttle password hack attempts, and prevent people without your game from attempting to login in the first place.