Beispiel #1
0
    void Start()
    {
        Debug.Log("##### Start Demo");
        string token = PlayerPrefs.GetString("token");

        if (string.IsNullOrEmpty(token))
        {
            KiiUser.RegisterAsPseudoUser(null, (KiiUser user, Exception e) => {
                if (e != null)
                {
                    Debug.Log("##### Failed to register user");
                    return;
                }
                PlayerPrefs.SetString("token", KiiUser.AccessToken);
                ShowLogo();
            });
        }
        else
        {
            KiiUser.LoginWithToken(token, (KiiUser user, Exception e) => {
                if (e != null)
                {
                    Debug.Log("##### Failed to login");
                    return;
                }
                ShowLogo();
            });
        }
    }
        public void Test_0300_LoginWithToken_OK()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            client.AddResponse(200, "{\"userID\":\"cdef\"}");

            // LogIn
            KiiUser user = KiiUser.LoginWithToken("tokenABCD");

            Assert.AreEqual("cdef", user.ID);

            // check AccessTokenDictionary
            Dictionary <string, object> dict = user.GetAccessTokenDictionary();
            string token = (string)dict["access_token"];

            Assert.AreEqual("tokenABCD", token);
            DateTime expiresAt = (DateTime)dict["expires_at"];

            Assert.AreEqual(DateTime.MaxValue, expiresAt);
        }
 public void Test_LoginWithTokenAndExpiresAt_Async_TokenNull()
 {
     Kii.Initialize(APP_ID, APP_KEY, Kii.Site.US);
     KiiUser.LoginWithToken(null, DateTime.MaxValue, (KiiUser user, Exception e) => {
         // do nothing.
     });
     Assert.Fail("Exception has not thrown.");
 }
        public void Test_LoginWithTokenAndExpiresAt_Async()
        {
            Kii.Initialize(APP_ID, APP_KEY, Kii.Site.US);

            // mock http client
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.AsyncHttpClientFactory = factory;
            MockHttpClient client = factory.Client;

            // set refresh response
            client.AddResponse(200,
                               "{" +
                               "\"userID\" : \"dummyID\"," +
                               "\"loginName\" : \"dummyUser\"" +
                               "}");

            // perform login.
            Assert.IsNull(KiiUser.CurrentUser);
            DateTime       expiresAt    = DateTime.UtcNow;
            CountDownLatch cd           = new CountDownLatch(1);
            KiiUser        loggedInUser = null;
            Exception      exp          = null;

            KiiUser.LoginWithToken("dummyToken", expiresAt, (KiiUser user, Exception e) => {
                loggedInUser = user;
                exp          = e;
                cd.Signal();
            });

            if (!cd.Wait())
            {
                Assert.Fail("Callback has not called.");
            }

            Assert.IsNull(exp);
            Assert.IsNotNull(loggedInUser);
            Assert.IsNotNull(KiiUser.CurrentUser);
            Assert.AreEqual(loggedInUser, KiiUser.CurrentUser);

            // verify token dictionary
            Dictionary <string, object> tokenBundle = KiiUser.CurrentUser.GetAccessTokenDictionary();

            Assert.AreEqual("dummyToken", tokenBundle["access_token"]);
            Assert.AreEqual(expiresAt, tokenBundle["expires_at"]);

            // verify refresh request
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", APP_ID, "users", "me");

            Assert.AreEqual(url, client.RequestUrl[0]);
            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod[0]);
            MockHttpHeaderList headerList = client.RequestHeader[0];

            Assert.AreEqual(APP_ID, headerList["X-Kii-AppID"]);
            Assert.AreEqual(APP_KEY, headerList["X-Kii-AppKey"]);
            Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv="));
        }
Beispiel #5
0
        public void Test_0302_LoginWithToken_failed()
        {
            this.mockClient.AddResponse(new CloudException(400, "{}"));

            KiiUser   target = null;
            Exception exp    = null;

            KiiUser.LoginWithToken("tokenABCD", (KiiUser user, Exception e) => {
                target = user;
                exp    = e;
            });
            Assert.IsNull(target);
            Assert.IsInstanceOfType(typeof(CloudException), exp);
        }
Beispiel #6
0
        public void Test_0301_LoginWithToken_null()
        {
            this.setStandardResponse();

            KiiUser   target = null;
            Exception exp    = null;

            KiiUser.LoginWithToken(null, (KiiUser user, Exception e) => {
                target = user;
                exp    = e;
            });
            Assert.IsNull(target);
            Assert.IsInstanceOfType(typeof(ArgumentException), exp);
        }
        public void Test_0302_LoginWithToken_failed()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            client.AddResponse(new CloudException(400, "{}"));

            // LogIn
            KiiUser.LoginWithToken("tokenABCD");
        }
        public void Test_0301_LoginWithToken_null()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.setStandardResponse(client);

            // LogIn
            KiiUser.LoginWithToken(null);
        }
Beispiel #9
0
 /// <summary>
 /// アクセストークンでログインする
 /// </summary>
 /// <param name="action"></param>
 static void LoginWithToken(Action <KiiUser> action)
 {
     KiiUser.LoginWithToken(AccessToken, (user, e) =>
     {
         if (e == null)
         {
             AccessToken = KiiUser.AccessToken;
             action(user);
         }
         else
         {
             action(null);
         }
     });
 }
Beispiel #10
0
    static public void AutoLogin( )
    {
        string token = PlayerPrefs.GetString("access token");

        LoginUI.instance.Wait();
        KiiUser.LoginWithToken(token, (KiiUser loginedUser, Exception e) =>
        {
            LoginUI.instance.StopWait();
            if (e == null)
            {
                LoginUI.instance.OnLoginSuccess();
            }
            else
            {
                HandlerLoginException(e);
            }
        });
    }
        public void Test_LoginWithTokenAndExpiresAt()
        {
            Kii.Initialize(APP_ID, APP_KEY, Kii.Site.US);

            // mock http client
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;
            MockHttpClient client = factory.Client;

            // set refresh response
            client.AddResponse(200,
                               "{" +
                               "\"userID\" : \"dummyID\"," +
                               "\"loginName\" : \"dummyUser\"" +
                               "}");

            // perform login.
            Assert.IsNull(KiiUser.CurrentUser);
            DateTime expiresAt = DateTime.UtcNow;

            KiiUser.LoginWithToken("dummyToken", expiresAt);
            Assert.IsNotNull(KiiUser.CurrentUser);

            // verify token dictionary
            Dictionary <string, object> tokenBundle = KiiUser.CurrentUser.GetAccessTokenDictionary();

            Assert.AreEqual("dummyToken", tokenBundle["access_token"]);
            Assert.AreEqual(expiresAt, tokenBundle["expires_at"]);

            // verify refresh request
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", APP_ID, "users", "me");

            Assert.AreEqual(url, client.RequestUrl[0]);
            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod[0]);
            MockHttpHeaderList headerList = client.RequestHeader[0];

            Assert.AreEqual(APP_ID, headerList["X-Kii-AppID"]);
            Assert.AreEqual(APP_KEY, headerList["X-Kii-AppKey"]);
            Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv="));
        }
Beispiel #12
0
        public void Test_0101_RemoveMyself_FromGroupMember()
        {
            // Create KiiUser for group member
            long    milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            string  memberName   = "kiiGroupMember-" + milliseconds;
            KiiUser member       = KiiUser.BuilderWithName(memberName).Build();

            member.Register("pass1234");
            string memberToken = KiiUser.AccessToken;

            // Create KiiUser for group member
            string  ownerName = "kiiGroupOwner-" + milliseconds;
            KiiUser owner     = KiiUser.BuilderWithName(ownerName).Build();

            owner.Register("pass1234");

            // Create group
            KiiGroup group = Kii.Group("testGroup");

            // Add member and save
            group.AddUser(member);
            group.Save();

            // Auth as member
            KiiUser.LogOut();
            KiiUser.LoginWithToken(memberToken);

            // Try to remove myself from the group
            group.RemoveUser(KiiUser.CurrentUser);
            group.Save();

            // Check value
            HashSet <KiiUser> addUsers    = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers");
            HashSet <KiiUser> removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers");

            Assert.AreEqual(0, addUsers.Count);
            Assert.AreEqual(0, removeUsers.Count);
        }
Beispiel #13
0
        public void Test_0300_LoginWithToken_OK()
        {
            // set response
            this.mockClient.AddResponse(200, "{\"userID\":\"cdef\"}");

            KiiUser   target = null;
            Exception exp    = null;

            // LogIn
            KiiUser.LoginWithToken("tokenABCD", (KiiUser user, Exception e) => {
                target = user;
                exp    = e;
            });
            Assert.AreEqual("cdef", target.ID);
            Assert.IsNull(exp);
            // check AccessTokenDictionary
            Dictionary <string, object> dict = target.GetAccessTokenDictionary();
            string token = (string)dict["access_token"];

            Assert.AreEqual("tokenABCD", token);
            DateTime expiresAt = (DateTime)dict["expires_at"];

            Assert.AreEqual(DateTime.MaxValue, expiresAt);
        }
 public void Test_LoginWithTokenAndExpiresAt_Async_CallBackNull()
 {
     Kii.Initialize(APP_ID, APP_KEY, Kii.Site.US);
     KiiUser.LoginWithToken("abcd1234", DateTime.MaxValue, null);
     Assert.Fail("Exception has not thrown.");
 }
 public void Test_LoginWithTokenAndExpiresAt_TokenNull()
 {
     Kii.Initialize(APP_ID, APP_KEY, Kii.Site.US);
     KiiUser.LoginWithToken(null, DateTime.MaxValue);
 }