Ejemplo n.º 1
0
        private void getExistingAccountAuthToken(Account account, String authTokenType)
        {
            IAccountManagerFuture future = mAccountManager.GetAuthToken(account, authTokenType, null, this, null, null);

            var bnd = future.GetResult(5L, Java.Util.Concurrent.TimeUnit.Seconds);

            bnd.Wait();
            //String authtoken = bnd.GetString(AccountManager.KEY_AUTHTOKEN);

            /*new Thread(new Runnable() {
             * @Override
             * public void run()
             * {
             *  try
             *  {
             *      Bundle bnd = future.getResult();
             *
             *      final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN);
             *      showMessage((authtoken != null) ? "SUCCESS!\ntoken: " + authtoken : "FAIL");
             *      Log.d("udinic", "GetToken Bundle is " + bnd);
             *  }
             *  catch (Exception e)
             *  {
             *      e.printStackTrace();
             *      showMessage(e.getMessage());
             *  }
             *  }
             * }).start();*/
        }
Ejemplo n.º 2
0
        public void Run(IAccountManagerFuture future)
        {
            var authTokenBundle = future.GetResult(5L, TimeUnit.Seconds).JavaCast <Bundle>();
            var authToken       = authTokenBundle.GetString(AccountManager.KeyAuthtoken);

            //var authToken = future.GetString(AccountManager.KEY_AUTHTOKEN);
        }
        public AuthenticationResultEx GetAuthTokenInBackground(AuthenticationRequest request, Activity callerActivity)
        {
            AuthenticationResultEx authResult = null;

            VerifyNotOnMainThread();

            // if there is not any user added to account, it returns empty
            Account targetAccount = null;

            Account[] accountList = mAcctManager
                                    .GetAccountsByType(BrokerConstants.BrokerAccountType);

            if (!string.IsNullOrEmpty(request.BrokerAccountName))
            {
                targetAccount = FindAccount(request.BrokerAccountName, accountList);
            }
            else
            {
                try
                {
                    UserInfo[] users        = GetBrokerUsers();
                    UserInfo   matchingUser = FindUserInfo(request.UserId, users);
                    if (matchingUser != null)
                    {
                        targetAccount = FindAccount(matchingUser.DisplayableId, accountList);
                    }
                }
                catch (Exception e)
                {
                    CallState.Logger.Error(null, e);
                }
            }

            if (targetAccount != null)
            {
                Bundle brokerOptions = GetBrokerOptions(request);

                // blocking call to get token from cache or refresh request in
                // background at Authenticator
                IAccountManagerFuture result = null;
                try
                {
                    // It does not expect activity to be launched.
                    // AuthenticatorService is handling the request at
                    // AccountManager.
                    //
                    result = mAcctManager.GetAuthToken(targetAccount,
                                                       BrokerConstants.AuthtokenType, brokerOptions, false,
                                                       null /*
                                                             * set to null to avoid callback
                                                             */, new Handler(callerActivity.MainLooper));

                    // Making blocking request here
                    CallState.Logger.Verbose(null, "Received result from Authenticator");
                    Bundle bundleResult = (Bundle)result.GetResult(10000, TimeUnit.Milliseconds);
                    // Authenticator should throw OperationCanceledException if
                    // token is not available
                    authResult = GetResultFromBrokerResponse(bundleResult);
                }
                catch (OperationCanceledException e)
                {
                    CallState.Logger.Error(null, e);
                }
                catch (AuthenticatorException e)
                {
                    CallState.Logger.Error(null, e);
                }
                catch (Exception e)
                {
                    // Authenticator gets problem from webrequest or file read/write

                    /*                    Logger.e(TAG, "Authenticator cancels the request", "",
                     *                          ADALError.BROKER_AUTHENTICATOR_IO_EXCEPTION);*/

                    CallState.Logger.Error(null, e);
                }

                CallState.Logger.Verbose(null, "Returning result from Authenticator");
                return(authResult);
            }
            else
            {
                CallState.Logger.Verbose(null, "Target account is not found");
            }

            return(null);
        }