android - 通过 Android 的 AccountManager 获取 Microsoft Exchange Authentication token

标签 android authentication exchange-server single-sign-on activesync

我正在开发一个 Android 3.0 程序,它可以连接到 SSL'd php 网络服务(以 JSON 格式输出数据,我可以修改服务器)。连接到此服务的平板电脑有一个公司 Microsoft ActiveSync (exchange 2010) 帐户,并且只有该帐户(没有谷歌帐户、FB 等)。我想编写一个程序,可以使用保存在平板电脑 android.accounts.AccountManager 中的凭据。对该 PHP 网络服务发出安全请求。我尝试按照一些谷歌示例进行操作,但我认为问题出在我使用该行时: AccountManagerFuture<Bundle> data = am.getAuthToken(b, "JWT", options, this, ota, null); 该应用程序只是挂起,我没有得到任何结果。 事实上,在 OnTokenAcquired 类中的任何行设置断点不会执行任何操作。 AKA OnTokenRequired 永远不会被执行

有什么建议或方向吗?我确信这对获取企业 android 客户端软件很有帮助

import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerFuture;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
public class AcctestActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        AccountManager am = AccountManager.get(this);
        EditText et = (EditText) findViewById(R.id.editText1);
        OnTokenAcquired ota = new OnTokenAcquired(et);
        Account exchange = null;
        Bundle options = new Bundle();
        for(Account a : am.getAccounts()){
              if(a.type.equals("com.android.exchange") && a.name.endsWith("@domain.com"))
                     exchange = a;
        }
        AccountManagerFuture<Bundle> data = am.getAuthToken(exchange, "JWT", options, this, ota, null);
    }
}

import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.Toast;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class OnTokenAcquired implements AccountManagerCallback<Bundle> {
       private EditText et;
       public OnTokenAcquired(EditText et){
              this.et = et;
       }
       public void run(AccountManagerFuture<Bundle> result) {
              Bundle bundle;
              try {
                     Toast.makeText(null, "Start!", Toast.LENGTH_LONG).show();
                     bundle = result.getResult(1, TimeUnit.SECONDS);
                     String token = bundle.getString(AccountManager.KEY_AUTHTOKEN);                         et.append("\nToken: " + token);
                     Toast.makeText(null, token, Toast.LENGTH_LONG).show();
              } catch (OperationCanceledException e) {
                     e.printStackTrace();
              } catch (AuthenticatorException e) {
                     e.printStackTrace();
              } catch (IOException e) {
                     e.printStackTrace();
              }            
       }
}

最佳答案

经过几个小时的研究,我找到了这段代码:

public Bundle  getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) throws NetworkErrorException {
     return null;
}

这意味着,android exchange Authenticator 不为 Exchange-Server 提供基于 token 的身份验证...

关于android - 通过 Android 的 AccountManager 获取 Microsoft Exchange Authentication token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10803774/

相关文章:

java - 安卓谷歌地图 : Combine scrollBy with zoomBy for simultaneous pan & zoom

Android JNI 函数在主线程上运行?

windows - IIS 站点不断提示输入 Windows 身份验证方法的凭据

exchange-server - 如何使用 Exchange Web 服务 (EWS) 检索全局联系人?

android:关于 Android 单元测试的新手问题?

android - Flask 到 android studio

如果检测到暴力尝试,PHP 使用 reCAPTCHA

php - 验证当前 ssl 是否是服务器的 ssl

plugins - Outlook Web Access 插件开发

c# - EWS : Calendar Sharing Invitation and Extended Properties