Beispiel #1
0
        private void TwitterAuthComplete(object sender, AuthenticatorCompletedEventArgs e)
        {
            Log.Debug(Tag, "TwitterAuthComplete:" + e.IsAuthenticated);

            if (e.IsAuthenticated)
            {
                var token  = e.Account.Properties["oauth_token"];
                var secret = e.Account.Properties["oauth_token_secret"];

                AuthCredential credential = TwitterAuthProvider.GetCredential(token, secret);
                mAuth.SignInWithCredential(credential);
            }
        }
 public void SignInWithTwitter(string token, string secret, Action <FirebaseUserResult> callback)
 {
     if ((Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) && !Application.isEditor)
     {
         Credential credential = TwitterAuthProvider.GetCredential(token, secret);
         targetBehaviour.StartCoroutine(ProcessFirebaseUserTaskRoutine(auth.SignInWithCredentialAsync(credential), callback));
     }
     else
     {
         WWWForm form = new WWWForm();
         form.AddField("token", token);
         form.AddField("secret", secret);
         WWW www = new WWW(serviceUrl + "/signInWithTwitter", form);
         targetBehaviour.StartCoroutine(ProcessWebServiceUserRoutine(www, callback));
     }
 }
Beispiel #3
0
        protected override void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);
            // check if the user is signed in
            FirebaseAuth mAuth2      = FirebaseAuth.Instance;
            FirebaseUser currentUser = mAuth2.CurrentUser;

            if (currentUser != null)
            {
                silentSignIn = true;
                // signed into Firebase, so get the token and save it in user object
                if (AppManager.User == null)
                {
                    AppManager.User        = new UserDetails();
                    AppManager.User.UserId = currentUser.Uid;
                    var tokenResult = currentUser.GetToken(false);
                    tokenResult.AddOnSuccessListener(this);
                }
                else
                {
                    if (!publishLoginDone)
                    {
                        Xamarin.Forms.MessagingCenter.Send("NavigateToNextPage", "LoginDone");
                        publishLoginDone = true;
                    }

                    AppManager.GetFavoritesFromFirebase(AppManager.User.UserId);
                }
            }
            else
            {
                try
                {
                    var                    credential   = TwitterAuthProvider.GetCredential(App.token, App.tokensecret);
                    FirebaseAuth           mAuth        = FirebaseAuth.Instance;
                    Android.Gms.Tasks.Task signedInTask = mAuth.SignInWithCredential(credential);
                    signedInTask.AddOnCompleteListener(this);
                }
                catch (Exception ex)
                {
                    string j = ex.Message;
                }
            }
        }
        /// <summary>
        /// Attaches the given Twitter credentials to the user. This allows the user to sign in to this account in the future with credentials for such provider.
        /// </summary>
        /// <param name="token">The Twitter OAuth token.</param>
        /// <param name="secret">The Twitter OAuth secret.</param>
        /// <returns>Updated current account</returns>
        public IObservable <IFirebaseAuthResult> LinkWithTwitter(string token, string secret)
        {
            AuthCredential credential = TwitterAuthProvider.GetCredential(token, secret);

            return(LinkWithCredentialAsync(credential).ToObservable());
        }
        /// <summary>
        /// Attaches the given Twitter credentials to the user. This allows the user to sign in to this account in the future with credentials for such provider.
        /// </summary>
        /// <param name="token">The Twitter OAuth token.</param>
        /// <param name="secret">The Twitter OAuth secret.</param>
        /// <returns>Task of IUserWrapper</returns>
        public async Task <IFirebaseAuthResult> LinkWithTwitterAsync(string token, string secret)
        {
            AuthCredential credential = TwitterAuthProvider.GetCredential(token, secret);

            return(await LinkWithCredentialAsync(credential));
        }
Beispiel #6
0
        /// <inheritdoc/>
        public IObservable <Unit> SignInWithTwitter(string token, string secret)
        {
            AuthCredential credential = TwitterAuthProvider.GetCredential(token, secret);

            return(SignInAsync(credential).ToObservable().Select(_ => Unit.Default));
        }
Beispiel #7
0
    /// <summary>
    /// Login using an auth method. Note: Only 1 auth type can be linked at a time! You'll need to call UnLinkAuth if you want to UnLink an auth type
    /// </summary>
    /// <returns><c>true</c>, if login was successful, <c>false</c> otherwise.</returns>
    /// <param name="type">Auth type</param>
    public static void AuthLogin(AuthType type)
    {
        Credential credential = default(Credential);                 // For some reason if this is null instead of default Unity will just crash (even though the default seems to be null anyway ??)

        if (auth != null)
        {
            ProjectManager.Log("[Firebase AuthLogin] " + type.ToString());

            switch (type)
            {
            case AuthType.Google:
                                                #if google
                if (Social.localUser == null || !Social.localUser.authenticated)
                {
                    GoogleLogin();
                    return;
                }
                else
                {
                    credential = GoogleAuthProvider.GetCredential(PlayGamesPlatform.Instance.GetIdToken(), PlayGamesPlatform.Instance.GetServerAuthCode());
                }
                                                #else
                Debug.LogError("Google auth login called but the Google Play Games Services plugin is now active in this project!");
                                                #endif
                break;

            case AuthType.Facebook:
                                                #if facebook
                if (!FB.IsLoggedIn || staticRef.activeFacebookAccessToken == null)
                {
                    FacebookLogin();                                              // We need to wait for the facebook login callback before trying to auth again
                    return;
                }
                else
                {
                    credential = FacebookAuthProvider.GetCredential(staticRef.activeFacebookAccessToken.TokenString);
                }
                                                #else
                Debug.LogError("Facebook auth login called but the facebook plugin in not active in this project!");
                                                #endif
                break;

            case AuthType.Twitter:
                                                #if twitter
                if (Twitter.Session == null || Twitter.Session.authToken == null)
                {
                    TwitterLogin();                                             // We need to wait for the twitter login callback before trying to auth again
                    return;
                }
                else
                {
                    credential = TwitterAuthProvider.GetCredential(Twitter.Session.authToken.token, Twitter.Session.authToken.secret);
                }
                                                #else
                Debug.LogError("Twitter auth login called but the twitter plugin is not active in this project!");
                                                #endif
                break;
            }

            if (credential != null)
            {
                auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
                    if (task.IsCanceled)
                    {
                        Analytics.LogError("Firebase AuthLogin " + type.ToString(), "AuthLogin was canceled!");
                        return;
                    }

                    if (task.IsFaulted)
                    {
                        // Firebase for Unity is pretty undocumented for doing more than simply adding the plugins into projects..
                        // Error handling doesn't seem great either, as of building this there's no error enum or error codes
                        // So we just have strings to work with if we want to do actions on specific errors happening
                        foreach (Exception e in task.Exception.InnerExceptions)
                        {
                            Analytics.LogError("Firebase AuthLogin", e.Message);                                     // This string only includes the firebase error, no information about the exception type

                            OnLoginFailed(ConvertToAuthError(e.Message));
                        }
                        return;
                    }

                    // Auth login was successful
                    if (task.IsCompleted)
                    {
                        staticRef.OnLogin();

                        // Attempt to link these auth'd credentials with firebase

                        /*task.Result.LinkWithCredentialAsync (credential).ContinueWith (linkTask => {
                         *      if (linkTask.IsCanceled) {
                         *              Analytics.LogError ("Firebase Credential Link " + type.ToString (), "Link with credentials was canceled!");
                         *              return;
                         *      }
                         *
                         *      if (linkTask.IsFaulted) {
                         *              Analytics.LogError ("Firebase Credential Link " + type.ToString (), "Error: " + task.Exception);
                         *              return;
                         *      }
                         *
                         *      // Link with credentials was a success, firebase will now keep track of this auth across games >:0
                         * });*/
                    }
                });
            }
        }
        else
        {
            Analytics.LogError("Firebase AuthLogin", "Auth was null!");
        }
    }
Beispiel #8
0
        public IAuthCredential GetCredential(string token, string secret)
        {
            var credential = TwitterAuthProvider.GetCredential(token, secret);

            return(new AuthCredentialWrapper(credential));
        }