Authenticate works but doesn't check password correctly

0 votes

Hello.

I've created a user for App42 and I want the user to be authenticated, the below code does work but only when the password or username field is empty, otherwise even if the password is wrong, it doesn't throw an exception. what is the problem of it? I want it to throw an exception when username and/or password is wrong,too.

 

using UnityEngine;
using System.Collections;
using com.shephertz.app42.paas.sdk.csharp;
using com.shephertz.app42.paas.sdk.csharp.user;
using System;

public class LVL0 : MonoBehaviour
{
    void DoThis()
    {

            try
            {
                App42API.Initialize(MyapiKey, MysecretKey);
                UserService userS = App42API.BuildUserService();
                userS.Authenticate("user", "pass", new UnityCallBack());
            }
            catch
            {
                print("Error");
            }
      }
}
public class UnityCallBack : App42CallBack
{
    public void OnSuccess(object response)
    {
        User user = (User)response;
    }
    public void OnException(Exception e)
    {
        App42Log.Console("Exception : " + e);
    }

}




 

asked Aug 24, 2015 in App42 Cloud API-BaaS by d.pichgah (17 points)
edited Aug 24, 2015 by d.pichgah

1 Answer

0 votes

Hello,

Can you print the complete excpetion details while calling authenticate API. Because it seems like something is missing this statment.

 

P.S If it is possible that put the below line of code, just after the intialization of App42 API:

App42Log.SetDebug(true);

The above code snipppet will print the internal logs, kindly share with us.

Thanks,

Himanshu Sharma 

answered Aug 24, 2015 by hs00105 (2,005 points)
I've already done that, the errors came there instead of coming from the exception, Here is the full log, Please note that the " DoThis()" function is named "Play2nd()" in my actual project, And I've changed that to "DoThis()" in this question because of simplicity and clarity.

Configuration Properties https://api.shephertz.com/cloud/
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.Config:.ctor()
com.shephertz.app42.paas.sdk.csharp.Config:GetInstance()
com.shephertz.app42.paas.sdk.csharp.App42API:.cctor()
LVL0:Play2nd() (at Assets/Scripts/L0-LOAD/LVL0.cs:51)
LVL0:Play2nd() (at Assets/Scripts/L0-LOAD/LVL0.cs:33)
<Play>c__Iterator3:MoveNext() (at Assets/Scripts/L0-LOAD/LVL0.cs:21)


apiKey(("lots of Numbers were in here I cut them")){"app42":{"user":{"password":"iuouuio","userName":"[pi[Blah"}}}sessionId(("lots of Numbers were in here I cut them"))timeStamp2015-08-24T19:55:12.058Zversion1.0
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.util.Util:SortAndConvertTableToString(Dictionary`2)
com.shephertz.app42.paas.sdk.csharp.util.Util:Sign(String, Dictionary`2)
com.shephertz.app42.paas.sdk.csharp.user.UserService:Authenticate(String, String, App42CallBack)
LVL0:Play2nd() (at Assets/Scripts/L0-LOAD/LVL0.cs:35)
<Play>c__Iterator3:MoveNext() (at Assets/Scripts/L0-LOAD/LVL0.cs:21)

 GetInstance Null
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:GetInstance()
com.shephertz.app42.paas.sdk.csharp.user.UserService:Authenticate(String, String, App42CallBack)
LVL0:Play2nd() (at Assets/Scripts/L0-LOAD/LVL0.cs:35)
<Play>c__Iterator3:MoveNext() (at Assets/Scripts/L0-LOAD/LVL0.cs:21)



 RESTConnectorWWW :  Awake
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:Awake()
UnityEngine.GameObject:AddComponent()
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:GetInstance()
com.shephertz.app42.paas.sdk.csharp.user.UserService:Authenticate(String, String, App42CallBack)
LVL0:Play2nd() (at Assets/Scripts/L0-LOAD/LVL0.cs:35)
<Play>c__Iterator3:MoveNext() (at Assets/Scripts/L0-LOAD/LVL0.cs:21)



 QueryString is ?
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:ExecutePost(String, Dictionary`2, String, Dictionary`2, Dictionary`2, App42CallBack)
com.shephertz.app42.paas.sdk.csharp.user.UserService:Authenticate(String, String, App42CallBack)
LVL0:Play2nd() (at Assets/Scripts/L0-LOAD/LVL0.cs:35)
<Play>c__Iterator3:MoveNext() (at Assets/Scripts/L0-LOAD/LVL0.cs:21)



POST URI : https://api.shephertz.com/cloud/1.0/user/authenticate?
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:ExecutePost(String, Dictionary`2, String, Dictionary`2, Dictionary`2, App42CallBack)
com.shephertz.app42.paas.sdk.csharp.user.UserService:Authenticate(String, String, App42CallBack)
LVL0:Play2nd() (at Assets/Scripts/L0-LOAD/LVL0.cs:35)
<Play>c__Iterator3:MoveNext() (at Assets/Scripts/L0-LOAD/LVL0.cs:21)


Waiting For Response...
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:ExecutePost(String, Dictionary`2, String, Dictionary`2, Dictionary`2, App42CallBack)
com.shephertz.app42.paas.sdk.csharp.user.UserService:Authenticate(String, String, App42CallBack)
LVL0:Play2nd() (at Assets/Scripts/L0-LOAD/LVL0.cs:35)
<Play>c__Iterator3:MoveNext() (at Assets/Scripts/L0-LOAD/LVL0.cs:21)

errorValue : {"app42Fault":{"httpErrorCode":404,"appErrorCode":2002,"message":"Not Found","details":"UserName/Password did not match. Authentication Failed."}}
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()


 errorCodes :
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:HandleException(String, App42CallBack)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()


 appErrorCode "2002"
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:HandleException(String, App42CallBack)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()


 httpErrorCode "404"
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:HandleException(String, App42CallBack)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()


Exception : com.shephertz.app42.paas.sdk.csharp.App42NotFoundException: {"httpErrorCode":"404", "appErrorCode":"2002", "message":"Not Found", "details":"UserName/Password did not match. Authentication Failed."}
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
UnityCallBack:OnException(Exception) (at Assets/Scripts/L0-LOAD/LVL0.cs:64)
com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW:HandleException(String, App42CallBack)
com.shephertz.app42.paas.sdk.csharp.connection.<Execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()
Any hope to make it right?
Hello,

Apologies for getting late back to you and thanks for sharing the logs with us. Your code is correct, however you need to parse your exception into App42Exception.Kindly use the below code snippet and let me know if it helps:

App42Exception ex =  (App42Exception) e;
Debug.Log ("Exception Code : " + ex.GetAppErrorCode());            Debug.Log ("Exception Message: " + ex.GetMessage());

Just put the above code snippet in OnException method of Unity and let me know if it resolve your issue.

Thanks for your patience.

Regards,
Himanshu Sharma
I put it in the OnException() in here, nothing changed.

public class UnityCallBack : App42CallBack
{
    public void OnSuccess(object response)
    {
        User user = (User)response;
    }
    public void OnException(Exception e)
    {
        //App42Log.Console("Exception : " + e);

        App42Exception ex = (App42Exception)e;
        Debug.Log("Exception CodeHAHAHA : " + ex.GetAppErrorCode());
        Debug.Log("Exception Message: HAHAH" + ex.GetMessage());
    }

}


However if I throw new exception in the function, it will work,though. but this is a workaround.
Hello,

Is that possible that you can share a your sample project because it seems like something went wrong on the application side.

Please share with us, it will help us to provide better support from our end.

Regards,
Himanshu Sharma
Here is the all codes for it, the problem is the statement in the "catch" never executes when an App42exception happens (however, if I put null for the password and/or user name. it will executes the statement in the "catch" block)
but when I throw new system.exception in the "OnException" method of the UnityCallBack() it will throws an exception.

using UnityEngine;
using System.Collections;
using com.shephertz.app42.paas.sdk.csharp;
using com.shephertz.app42.paas.sdk.csharp.user;
using System;

public class LVL0 : MonoBehaviour
{


    public string moviePath = "Final.mp4";
    void Start()
    {
        StartCoroutine(Play());
    }
    IEnumerator Play()
    {
        //PlayerPrefs.SetInt("ValidID", 1);
        Handheld.PlayFullScreenMovie(moviePath, Color.black, FullScreenMovieControlMode.CancelOnInput, FullScreenMovieScalingMode.AspectFit); //Plays a movie
        yield return new WaitForEndOfFrame(); //waits till movie ends
        LeaderBoardConstants cons = new LeaderBoardConstants();
        App42API.Initialize(cons.apiKey, cons.secretKey);
        UserService userS = App42API.BuildUserService();
        try
        {
            userS.Authenticate(PlayerPrefs.GetString("u"), PlayerPrefs.GetString("P"), new UnityCallBack());
            Play2nd();
        }
        catch
        {
            Application.LoadLevel("ErrorScene"); //If user name and password is not true then player should go to this scene
        }
    }
    void Play2nd()
    {
        Application.LoadLevel("L1-cutscene1"); //If username and password is correct then player goes here
    }
}
public class UnityCallBack : App42CallBack
{
    public void OnSuccess(object response)
    {
        
    }
    public void OnException(Exception e)
    {
        App42Exception ex = (App42Exception)e; //This is what you've suggested in your previous comment
    }

}
Hello,

This is Asynchronous call, if method fails due to any cause your catch block will not call. Your method output will come in the onException method of Unity call back. You can print your exception in OnException method of UnityCallBack.

Regards,
Himanshu Sharma
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...