vendredi 2 février 2018

Laravel 5 Login 401 from Unity WWW request Unauhorized JWT (Works in browser & Postman)

Notes:

  • JWT Auth
  • Nginx
  • Laravel 5
  • Unity (request fails)
  • Postman: works.
  • Chrome: works.

I've done a lot of searching trying to find answers to this but to no avail.

I'm trying to create a script in unity which logs into my Laravel application and returns the auth token so I can use it to make API requests. The token is returned correctly.

C# Code:

private IEnumerator SendLogin(string user, string pass, Action<bool, string> callback)
{
    // Build login Submission form.
    WWWForm formData = new WWWForm();
    formData.AddField("email", user);
    formData.AddField("password", pass);
    formData.AddField("_token", "W4d7JugbWRg4ZASe4qAPinJVgg35OeaYStgeE7dm");

    // Checking Username and password were read correctly (they are)
    Debug.Log("Username: " + user + " Password: " + pass);

    // Create Request
    WWW www = new WWW(loginServerUrl, formData);
    Debug.Log("Sending Login Info To Server.");

    // Wait for request to finish
    yield return www;

    // just incase?
    while (!www.isDone)
    {
        yield return new WaitForSecondsRealtime(0.15f);
        Debug.Log("Waiting for download to finish.");
    }

    // Check for errors
    if (www.error != null)
    {
        foreach (KeyValuePair<string, string> header in www.responseHeaders)
        {
            Debug.Log(header.Key.ToString() + " Value: " + header.Value.ToString());
        }
        Debug.Log("Error On Request. To string:" + www.error.ToString());
        StopCoroutine(login_coroutine);
    }

    // Get Response
    string response = www.text;
    Debug.Log(response);

    // Parse JSON
    var json = JSON.Parse(www.text);
    Debug.Log("Json: " + json.ToString());
    Debug.Log("Response: " + response);


    if (callback != null)
    {
        callback(true, response);
    }
    StopCoroutine(login_coroutine);
}

Chrome Screenshots: https://i.imgur.com/jMAmpbg.png (before) https://i.imgur.com/ewsZST8.png (after login pressed)

Postman Screenshot: https://i.imgur.com/jwvEvpv.png

Unity Screenshots (inc. Console Logs): https://i.imgur.com/1lldOGk.png



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2nBd2WD
via IFTTT

Aucun commentaire:

Enregistrer un commentaire