Ejemplo n.º 1
0
        public override Bundle GetAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options)
        {
            // Extract the username and password from the Account Manager, and ask
            // the server for an appropriate AuthToken.
            AccountManager am = AccountManager.Get(mContext);

            String authToken = am.PeekAuthToken(account, authTokenType);

            // Lets give another try to authenticate the user
            if (TextUtils.IsEmpty(authToken)) {
                String password = am.GetPassword(account);
                if (password != null) {
                    //var auth = new KiwiServerAuthenticate ();
                    var auth = new KiwiLoginService ();
                    var authTokenResult = auth.Login(account.Name, password);
                    Task.WaitAll(authTokenResult);
                    authToken = authTokenResult.Result.AuthToken;
                }
            }

            // If we get an authToken - we return it
            if (!TextUtils.IsEmpty(authToken)) {
                Bundle result = new Bundle();
                result.PutString(AccountManager.KeyAccountName, account.Name);
                result.PutString(AccountManager.KeyAccountType, account.Type);
                result.PutString(AccountManager.KeyAuthtoken, authToken);
                return result;
            }

            // If we get here, then we couldn't access the user's password - so we
            // need to re-prompt them for their credentials. We do that by creating
            // an intent to display our AuthenticatorActivity.
            Intent intent = new Intent(mContext, typeof(LoginActivity));
            intent.PutExtra(AccountManager.KeyAccountAuthenticatorResponse, response);
            intent.PutExtra("accountType", account.Type);
            intent.PutExtra("authTokenType", authTokenType);
            intent.PutExtra ("accountName", account.Name);
            Bundle bundle = new Bundle();
            bundle.PutParcelable(AccountManager.KeyIntent, intent);
            return bundle;
        }
Ejemplo n.º 2
0
        protected override Java.Lang.Object DoInBackground(params Java.Lang.Object[] @params)
        {
            System.Console.WriteLine ("LoginTask: DoInBackground");

            String authtoken = null;

            //var auth = new KiwiServerAuthenticate ();
            var auth = new KiwiLoginService ();
            var authTokenResult = auth.Login(username, password);
            try{
                Task.WaitAll(authTokenResult);
            } catch (Exception e) {
                Toast.MakeText(Application.Context, "There seems to be a problem with the server. Please try again later.", ToastLength.Long).Show();
            }
            if (authTokenResult.Result.Successful) {
                authtoken = authTokenResult.Result.AuthToken;
            }

            Intent res = new Intent();

            res.PutExtra(AccountManager.KeyAccountName, username);
            res.PutExtra(AccountManager.KeyAccountType, "com.SnapAndGo.auth");
            res.PutExtra(AccountManager.KeyAuthtoken, authtoken);
            res.PutExtra("password", password);

            return res;
        }