Custom Authentication Help.

Options
So i'm just a little confused on the Custom Authentication Process. Here is my setup:

I am trying to use my wordpress website as the authenticator.
(for instance you would register on my website, then use that usernamer and password to login to my game)

So far i have setup my custom authentication with the login URL for my website (http://trollywogglers.com/login/) , the keys are the values from the database, and the values are my variables in game.

(this is the part that confuses me the most, for one not sure if http://trollywogglers.com/login/ would even be the correct way to have photon authenticate through my website, and i assume the keys should match what is in my user database for the site (which I have full access too, and double checked that they are right), and I guess the values are the variables i use in my script again not sure what else i would put there.)

Then i took a look at this page https://doc.photonengine.com/en/realtime/current/reference/custom-authentication, and got to this point:

PhotonNetwork.AuthValues = new AuthenticationValues(); PhotonNetwork.AuthValues.AuthType = CustomAuthenticationType.Custom; PhotonNetwork.AuthValues.AddAuthParameter("user", loginUser); PhotonNetwork.AuthValues.AddAuthParameter("pass", loginPass);

I had to change the LBClient part I assume i was supposed too since this was made universal.

So if everything i have is correctly setup my question is where should i put the code above, basically my code to connect is the following:

void Connect() { PhotonNetwork.ConnectUsingSettings ("MyServerIP"); PhotonNetwork.automaticallySyncScene = true; }

and that is just called from Start(), so i assume i would authenticate before I try to connect to the server, but i'm not sure.

Now i'm not a complete novice on this I have been working with PUN for a while now. Just the first time trying to setup some custom authentication, and i have no desire to use FaceBook to login.

So any help will be greatly appreciated, I also tried the whole load from PHP script, but that is a question for a different topic.

Comments

  • Mrslayer01
    Options
    Still no luck finding a good user friendly tutorial for this subject, not very much information about custom authentication out there :neutral:
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
  • Mrslayer01
    edited October 2016
    Options
    Thank you for the fast comment (Honestly expected if i put photon in the title no one would actually respond to it) So taking your advice i looked in to adding some type of client authentication into my website, and i found this. Not quite sure how to use this, but i will if this is something Photon will actually see since it sends JSON responses, but again if this will work then i will learn how to use it.

    I also looked at the post about php alot and it just comes down to my lack of knowledge with PHP Scripting, but i found a old Highscores php script that i was able to link to my database, and pull every user to my unity client (just as an output, and it was encrypted with what i assume is Wordpress standard encryption found here) So what it really comes down too is if that OAuth1 plugin will not work for photon I will have to put together my own PHP script. Just need to learn how to do it really so here is what I got so far (Will blank out my server information ofc):
    
    <?php
        // Send variables for the MySQL database class.
        $database = mysql_connect('My Address', 'My Address', 'My DB Password') or die('Could not connect: ' . mysql_error());
        mysql_select_db('DB Name') or die('Could not select database');
     
        $query = "SELECT `ID`, `user`, `pwd` FROM `User Database` WHERE 1";
        $result = mysql_query($query) or die('Query failed: ' . mysql_error());
     
        $username = $_GET["loginUser"]; //My Unity Variables just like in the tutorial.
        $password = $_GET["loginPass"]; //the password is comming in plain text, it is trully NOT RECOMMENDED to keep it that way
     
      //Start Decryption for Wordpress
        $wp_hasher = new PasswordHash(8, TRUE);
     
        $password_hashed = 'My Encrypted password passed from the DB';
        $plain_password = 'The password the user input from unity';
     
        if($wp_hasher->CheckPassword($plain_password, $password_hashed)) {
            echo "YES, Matched";
        } else {
            echo "No, Wrong Password";
     
        }
       
       /* //This just displays all the users in my database, and this works just fine for me.
        for($i = 0; $i < $num_results; $i++)
        {
     
             $row = mysql_fetch_array($result);
             echo $row['ID'] . "," . $row['user'] . "," .  $row['pwd'];
        }
        */
    ?>
    Now the problem is more than likely coming from:
    
      //Start Decryption for Wordpress
        $wp_hasher = new PasswordHash(8, TRUE);
     
        $password_hashed = 'My Encrypted password passed from the DB';
        $plain_password = 'The password the user input from unity';
     
        if($wp_hasher->CheckPassword($plain_password, $password_hashed)) {
            echo "YES, Matched";
        } else {
            echo "No, Wrong Password";
     
        }
    So that is about as far as I have gotten on the PHP side of things. So my main question is should I use something like this PHP script, and try to learn it, or if possible use the OAuth1 plugin since it is obviously more secure. Either way I would need to do some digging to learn both.

    I posted both on photon forums, and unity to maybe get some more help from the photon community as well.
  • Mrslayer01
    Options
    John helped me with this over here.
  • Himloia
    Options
    that's so complicated, I have the same question
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Himloia,

    What's so complicated? You have code samples and docs.
  • Markus
    Options
    @Himloia
    please read through
    1. general doc at https://doc.photonengine.com/en-us/realtime/current/reference/custom-authentication
    2. example custom auth service at https://github.com/exitgames/photon.custom-authentication
    3. post detailed remaining questions

    In the end, what you need to do is
    1. pass player credentials used for authentication in the client (-> set as AuthValues)
    2. configure the URL of your HTTP-auth-service in the Photon app dashboard (custom auth provider)
    2.1. optional - add any additionally needed (HTTP) parameters for your authentication service in the Photon app dashboard (e.g. access control for your auth-service)
    3. build a HTTP-auth-service that returns JSON in a defined format (see our docs). Which HTTP-technology you use here and how you authenticate your players is totally up to you.