Esempio n. 1
0
    public void UnLinkWithAuthDataAsyncTwitter()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.AuthData = twitterParams.param;

        // authData登録
        user.LogInWithAuthDataAsync((NCMBException e) => {
            Assert.Null(e);
        });
        NCMBTestSettings.AwaitAsync();

        Assert.True(user.IsLinkWith("twitter"));

        // authData削除
        user.UnLinkWithAuthDataAsync("twitter", (NCMBException e1) => {
            Assert.Null(e1);
            NCMBTestSettings.CallbackFlag = true;
        });
        NCMBTestSettings.AwaitAsync();

        // 削除成功の確認
        Assert.False(user.IsLinkWith("twitter"));
        Assert.True(NCMBTestSettings.CallbackFlag);
        NCMBUser.LogOutAsync();
    }
Esempio n. 2
0
    public void UnLinkFacebookLinkTwitter()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.AuthData = facebookParams.param;

        // authData登録
        user.LogInWithAuthDataAsync((NCMBException e) => {
            Assert.Null(e);
        });
        NCMBTestSettings.AwaitAsync();

        // authData追加
        user.LinkWithAuthDataAsync(twitterParams.param, (NCMBException e1) => {
            Assert.Null(e1);
        });
        NCMBTestSettings.AwaitAsync();
        Assert.True(user.IsLinkWith("twitter"));

        // authData削除
        user.UnLinkWithAuthDataAsync("facebook", (NCMBException e2) => {
            Assert.Null(e2);
            NCMBTestSettings.CallbackFlag = true;
        });
        NCMBTestSettings.AwaitAsync();

        // 削除成功の確認
        Assert.IsNotEmpty(NCMBUser._getCurrentSessionToken());
        Assert.True(user.IsLinkWith("twitter"));
        Assert.False(user.IsLinkWith("facebook"));
        Assert.True(NCMBTestSettings.CallbackFlag);
        NCMBUser.LogOutAsync();
    }
Esempio n. 3
0
    public void LogInWithAuthDataAsyncTwitter()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.AuthData = twitterParams.param;

        // authData登録
        user.LogInWithAuthDataAsync((NCMBException e) => {
            Assert.Null(e);
            NCMBTestSettings.CallbackFlag = true;
        });
        NCMBTestSettings.AwaitAsync();

        Assert.AreEqual("dummyObjectId", user.ObjectId);

        // twitterパラメータ確認
        Dictionary <string, object> authData = user.GetAuthDataForProvider("twitter");

        Assert.AreEqual("twitterDummyId", authData["id"]);
        Assert.AreEqual("twitterDummyScreenName", authData["screen_name"]);
        Assert.AreEqual("twitterDummyConsumerKey", authData["oauth_consumer_key"]);
        Assert.AreEqual("twitterDummyConsumerSecret", authData["consumer_secret"]);
        Assert.AreEqual("twitterDummyAuthToken", authData["oauth_token"]);
        Assert.AreEqual("twitterDummyAuthSecret", authData["oauth_token_secret"]);

        // 登録成功の確認
        Assert.NotNull(NCMBUser._getCurrentSessionToken());
        Assert.True(user.IsLinkWith("twitter"));
        Assert.True(NCMBTestSettings.CallbackFlag);
        NCMBUser.LogOutAsync();
    }
Esempio n. 4
0
    public void LinkWithAuthDataAsyncInvalidTwitter()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.AuthData = facebookParams.param;

        // authData登録
        user.LogInWithAuthDataAsync((NCMBException e) => {
            Assert.Null(e);
        });
        NCMBTestSettings.AwaitAsync();

        // authData追加
        user.LinkWithAuthDataAsync(invalidTwitterParams.param, (NCMBException e) => {
            Assert.AreEqual(NCMBException.OAUTH_ERROR, e.ErrorCode);
            NCMBTestSettings.CallbackFlag = true;
        });
        NCMBTestSettings.AwaitAsync();

        // 追加失敗の確認
        Assert.IsNotEmpty(NCMBUser._getCurrentSessionToken());
        Assert.True(user.IsLinkWith("facebook"));
        Assert.False(user.IsLinkWith("twitter"));
        Assert.True(NCMBTestSettings.CallbackFlag);
        NCMBUser.LogOutAsync();
    }
 /// <summary>
 /// 非同期処理でauthDataを用いて、ユーザを登録します。<br/>
 /// 既存会員のauthData登録はLinkWithAuthDataAsyncメソッドをご利用下さい。<br/>
 /// 通信結果が必要な場合はコールバックを指定するこちらを使用します。
 /// </summary>
 /// <returns>登録したユーザ</returns>
 public static IObservable <NCMBUser> LogInWithAuthDataAsyncAsStream(this NCMBUser user)
 {
     return(Observable.Create <NCMBUser>(observer =>
     {
         var gate = new object();
         var isDisposed = false;
         user.LogInWithAuthDataAsync(error =>
         {
             lock (gate)
             {
                 if (isDisposed)
                 {
                     return;
                 }
                 if (error == null)
                 {
                     observer.OnNext(user);
                     observer.OnCompleted();
                 }
                 else
                 {
                     observer.OnError(error);
                 }
             }
         });
         return Disposable.Create(() =>
         {
             lock (gate)
             {
                 isDisposed = true;
             }
         });
     }));
 }
Esempio n. 6
0
    public void LogInWithAuthDataAsyncFacebook()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.AuthData = facebookParams.param;

        // authData登録
        user.LogInWithAuthDataAsync((NCMBException e) => {
            Assert.Null(e);
            NCMBTestSettings.CallbackFlag = true;
        });
        NCMBTestSettings.AwaitAsync();

        Assert.AreEqual("dummyObjectId", user.ObjectId);

        // facebookパラメータ確認
        Dictionary <string, object> authData = user.GetAuthDataForProvider("facebook");

        Assert.AreEqual("facebookDummyId", authData["id"]);
        Assert.AreEqual("facebookDummyAccessToken", authData["access_token"]);
        Assert.AreEqual("2017-02-07T01:02:03.004Z", authData["expiration_date"]);

        // 登録成功の確認
        Assert.IsNotEmpty(NCMBUser._getCurrentSessionToken());
        Assert.True(user.IsLinkWith("facebook"));
        Assert.True(NCMBTestSettings.CallbackFlag);
        NCMBUser.LogOutAsync();
    }
Esempio n. 7
0
    public IEnumerator UnLinkWithAuthDataAsyncFacebook()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.AuthData = facebookParams.param;

        // authData登録
        user.LogInWithAuthDataAsync((NCMBException e) => {
            Assert.Null(e);
            NCMBTestSettings.CallbackFlag = true;
        });
        yield return(NCMBTestSettings.AwaitAsync());

        NCMBTestSettings.CallbackFlag = false;

        Assert.True(user.IsLinkWith("facebook"));

        // authData削除
        user.UnLinkWithAuthDataAsync("facebook", (NCMBException e1) => {
            Assert.Null(e1);
            NCMBTestSettings.CallbackFlag = true;
        });
        yield return(NCMBTestSettings.AwaitAsync());

        // 削除成功の確認
        Assert.False(user.IsLinkWith("facebook"));
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Esempio n. 8
0
    public IEnumerator LinkWithAuthDataAsyncTwitter()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.AuthData = facebookParams.param;

        // authData登録
        user.LogInWithAuthDataAsync((NCMBException e) => {
            Assert.Null(e);
            NCMBTestSettings.CallbackFlag = true;
        });
        yield return(NCMBTestSettings.AwaitAsync());

        NCMBTestSettings.CallbackFlag = false;

        // authData追加
        user.LinkWithAuthDataAsync(twitterParams.param, (NCMBException e1) => {
            Assert.Null(e1);
            NCMBTestSettings.CallbackFlag = true;
        });
        yield return(NCMBTestSettings.AwaitAsync());

        // 追加成功の確認
        Assert.IsNotEmpty(NCMBUser._getCurrentSessionToken());
        Assert.True(user.IsLinkWith("facebook"));
        Assert.True(user.IsLinkWith("twitter"));
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Esempio n. 9
0
    public IEnumerator LogInWithAuthDataAsyncFacebookStatus200()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.AuthData = facebookParams200.param;

        // authData登録
        user.LogInWithAuthDataAsync((NCMBException e1) => {
            Assert.Null(e1);
            NCMBUser currentUser = NCMBUser.CurrentUser;
            Assert.NotNull(currentUser);
            Assert.AreEqual("dummyObjectId", currentUser.ObjectId);

            // facebookパラメータ確認
            Dictionary <string, object> authData = currentUser.GetAuthDataForProvider("facebook");
            Assert.AreEqual("facebookDummyId200", authData ["id"]);
            Assert.AreEqual("facebookDummyAccessToken200", authData ["access_token"]);
            Assert.AreEqual("2017-02-07T01:02:03.004Z", authData ["expiration_date"]);

            // 登録成功の確認
            Assert.IsNotEmpty(NCMBUser._getCurrentSessionToken());
            Assert.True(currentUser.IsLinkWith("facebook"));
            NCMBTestSettings.CallbackFlag = true;
        });
        yield return(NCMBTestSettings.AwaitAsync());

        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Esempio n. 10
0
        /// <summary>
        /// 非同期処理でauthDataを用いて、ユーザを登録します。<br/>
        /// 既存会員のauthData登録はLinkWithAuthDataAsyncメソッドをご利用下さい。<br/>
        /// </summary>
        public static Task <NCMBUser> LogInWithAuthDataTaskAsync(this NCMBUser user)
        {
            var tcs = new TaskCompletionSource <NCMBUser>();

            user.LogInWithAuthDataAsync(error =>
            {
                if (error != null)
                {
                    tcs.SetException(error);
                }
                else
                {
                    tcs.SetResult(user);
                }
            });
            return(tcs.Task);
        }
Esempio n. 11
0
    public IEnumerator LogInWithAuthDataAsyncInvalidTwitter()
    {
        // テストデータ作成
        NCMBUser user = new NCMBUser();

        user.AuthData = invalidTwitterParams.param;

        // authData登録
        user.LogInWithAuthDataAsync((NCMBException e) => {
            Assert.AreEqual(NCMBException.OAUTH_ERROR, e.ErrorCode);
            NCMBTestSettings.CallbackFlag = true;
        });
        yield return(NCMBTestSettings.AwaitAsync());

        // 登録失敗の確認
        Assert.IsEmpty(NCMBUser._getCurrentSessionToken());
        Assert.False(user.IsLinkWith("twitter"));
        Assert.True(NCMBTestSettings.CallbackFlag);
    }
Esempio n. 12
0
    private void LoginCallback(ILoginResult result)
    {
        if (FB.IsLoggedIn)
        {
            // facebook ログインの情報を使って NCMB にログインする
            var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
            NCMBFacebookParameters parameters = new NCMBFacebookParameters(aToken.UserId, aToken.TokenString, aToken.ExpirationTime);
            NCMBUser user = new NCMBUser();
            user.AuthData = parameters.param;

            user.LogInWithAuthDataAsync((NCMBException e) =>
            {
                if (e != null)
                {
                    Debug.LogError("Failed to login: "******"Failed to fetch: " + ex.ErrorMessage);
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(user.Email))
                            {
                                Dictionary <string, string> formData = new Dictionary <string, string>()
                                {
                                };
                                FB.API("/me?fields=id,email", HttpMethod.GET, (IGraphResult r) =>
                                {
                                    if (r.Error != null)
                                    {
                                        Debug.Log(r.Error);
                                    }
                                    else
                                    {
                                        Debug.Log(r.ResultDictionary.ToJson());
                                        string email = r.ResultDictionary["email"].ToString();
                                        user.Email   = email;
                                        user.SaveAsync((NCMBException exc) =>
                                        {
                                            if (exc != null)
                                            {
                                                Debug.LogError("Failed to save: " + ex.ErrorMessage);
                                            }
                                            else
                                            {
                                                Debug.Log("Saved email data successfully.");
                                            }
                                        });
                                    }
                                }
                                       , formData);
                            }
                        }
                    });
                }
            });
        }
        else
        {
            Debug.Log("User cancelled login");
        }
    }