Custom Authentication Help Needed

Options
lifealchemist
edited March 2014 in Photon Server
I'm using the PUN system in Unity3D for my online game and I'm having trouble understanding how to host my own custom server authenticator for player login and verification.

I've looked at this link:
http://doc.exitgames.com/photon-cloud/C ... ntication/

From a complete beginner to this, but familiar with Unity, the client-side seems extremely simple with plenty of details on what needs to be done. I cannot, however, understand a single thing when it comes to the server side. I get that unity calls the photon cloud, cloud calls the authentication server, but I have no clue how a URL comes into it at all.

I've gone to this link:
https://github.com/exitgames/photon.cus ... entication

Downloading the files from the right hand side as a zip, I understand what I'm needing is the src folder, beyond that, however, I'm clueless. By the looks of it, I need microsoft visual studio (I have the 2013 version) and it says the web sample is incompatible, so maybe that isn't the right application to open it. There is absolutely no documentation on how to setup the server using the src folder that I could find, and researching blindly on google doesn't help me understand the program or what I need to do to integrate it to unity.

All I want is to have the player type in a login and password, then start playing my game. Advice for someone who knows nothing about server authentication would be greatly appreciated.

P.S. Do I really have to pay for web hosting for this? Seems kinda pointless when photon transfers information between clients for me anyways. Makes me think creating save files in unity on my own computer (as the server) and passing rpc calls is simpler since I already have file encryption and serialization implemented.

Comments

  • Hi and welcome to Photon!

    What you need for custom authentication is this, basically:

    1. An authentication server. This is just *any* web service - either in .NET, PHP, whatever you are used to. (Details later...)

    2. You add the URL in your application dashboard: https://www.exitgames.com/en/Realtime/Dashboard -> choose "Details" for your application -> "Authentication" tab -> "Custom server".

    On the client side, you can specify the parameters that Photon should pass to that URL. Voila, that's all.

    ---

    Now you need to know how to implement that custom authentication server. The answer is: it's (almost) totally up to you. You can use any language, and host it whereever you want. What is the server-side framework you are most used to? Just use that one and set up a simple service.

    Your service needs to return a JSON object that looks like this:
    {"ResultCode":2,"Message":null}
    

    That's all. ;)

    Here is a very nice, slim PHP example: viewtopic.php?f=17&t=2697 - maybe that is easier to understand?
    The sources from GitHub do the same - one is an example with ASP.NET WebApi the other in ASP.NET MVC. (I can open both of them with VS2013 - not sure what the problem is - sorry!)

    When it comes to hosting, it is again up to you - there are many web hosting providers where you can run a small web service for free (especially for PHP), so there is probably no additional cost involved.

    Let me know if you need more information.
  • I'm guessing the best fit for me would be .NET since I use Unity3D's c# framework, however, I've never created a web server before. I've figured out the "not being able to open" problem since I had Visual Studio 2013 Windows Desktop instead of VS2013 Web. I can now open the project in Visual Studio.

    I am a complete newbie to this stuff, so having things "totally up to me" means I'm completely lost and don't even know where to begin. I don't know any of the code, or what I need to modify to get it what I want. I've looked up a lot of different links like this:

    http://www.asp.net/mvc/tutorials/mvc-5/ ... ng-started
    which tells me how to create things step by step, but doesn't really tell me what the purpose of each thing is supposed to do. Attempting to find a free web hosting service, somee is still "creating a website" after about 30 minutes of loading (which leads me to believe that it's a scam intended to get waiting users to get frustrated and buy the premium package). Going through about 10 other sites for searches, they either require payment, or only last for about 60 days. I settled on Parse.com searching through the forums hoping this will work.

    Am I supposed to upload the folder somehow? From what I've read, I use Debug -> Build ExitGames.Web.Sample to export, but can't find a way to "import" the file into Parse.com whenever I can get past the errors.

    Do I change the RouteConfig.cs routes.MapRoute object url line to (url: "beset.parse.com/{controller}/{action}/{id}",) to go to the correct address?

    With this line of code, it passes it into the authenticate function?
    [code2=csharp]PhotonNetwork.AuthValues.AuthParameters = "username=" + login_userName + "&password=" + login_password + "&gameVersion=" + gameVersion + "";[/code2]

    (Modified 3rd parameter authenticate function)
    [code2=csharp]public ActionResult Authenticate(string userName, string token, string version)[/code2]

    Do I use the ClientAuthenticationService and UserRepository scripts somehow to create the database? Am I using a for loop to iterate through the database? All of these questions may sound stupid, but the most advice I've gotten is "You can do it any way you want" which tells me absolutely nothing about how to get it done. Guides out there tell me about making an MVC but not about using your pre-built one.
  • Markus
    Options
    Hi,

    if you decide to use the .NET ASP.NET stack to build your web service, I am afraid you will have to spend a little more time on getting to know that. There are just so many options of where you can host the site and how the actual deployment takes place, that it is a bit hard to explain that here.

    You can not use parse.com to host your ASP.NET site. They do not provide that.
    You may use Windows Azure Web Sites, however the learning curve may be a bit steep there (as most likely will be with other hosters as well), if you do not know anything about the ASP.NET world. At least, the basics are free there.

    You do not have to adjust the RouteConfig, the mapping of the URL to your app happens outside of the app (via DNS or plain IP ...). RouteConfig just defines the controller class, which handles the incoming request internally.
    E.g. routing in the sample is set up, so that
    http://where-you-host-your-site.com/api ... te/yes/yes
    calls the ClientController.Authenticate and passes userName=yes and token=yes to the method.
    The controller method calls AuthenticationService.Authenticate.
    In that Authenticate method, you would add your logic to verify, if the passed userName and token are valid and set up the response accordingly. In that method, you again have many options of checking your user base. You could store all your users in Parse.com or use a SQL database or MySQL database ... again, many options. Regardless of which storage solution you use, you will have to use some client to connect and query for your user.

    Hope this helps a bit.