获取的Microsoft Exchange的身份验证令牌通过Android的的AccountManager [英] Get Microsoft Exchange Authentication token through Android's AccountManager

查看:277
本文介绍了获取的Microsoft Exchange的身份验证令牌通过Android的的AccountManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作在Android 3.0的程序,可以连接到SSL'd PHP Web服务(以JSON输出的数据,我可以修改服务器)。被连接到该服务的平板电脑有一个企业Microsoft动态(交流2010)帐户,只有那个帐户(没有谷歌账户,FB等)。我想编写一个程序,可以使用保存在平板电脑的 android.accounts凭据.AccountManager ,以使在该PHP Web服务的安全要求。我尝试以下一些谷歌的例子,但我想,当我使用该行的问题在于:
AccountManagerFuture<群组>数据= am.getAuthToken(二,智威汤逊的选项,这一点,OTA,NULL);
该应用程序只是挂起和我没有得到任何结果。
事实上,在OnTokenAcquired类中的任何行设置一个断点,并没有做任何事情。 AKA OnTokenRequired从未被执行

任何意见或方向?我敢肯定,这可以用于获取有助于公司的Andr​​oid客户端软件

 进口android.accounts.Account;
进口android.accounts.AccountManager;
进口android.accounts.AccountManagerFuture;
进口android.app.Activity;
进口android.os.Bundle;
进口android.widget.EditText;
公共类AcctestActivity延伸活动{
    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        上午的AccountManager = AccountManager.get(本);
        等的EditText =(EditText上)findViewById(R.id.editText1);
        OnTokenAcquired OTA =新OnTokenAcquired(等);
        帐户交换= NULL;
        捆绑选项=新包();
        对于(帐户:am.getAccounts()){
              如果(a.type.equals(com.android.exchange)及与放大器; a.name.endsWith(@ domain.com))
                     交换=一;
        }
        AccountManagerFuture<群组>数据= am.getAuthToken(交流,智威汤逊的选项,这一点,OTA,NULL);
    }
}


 进口android.accounts.AccountManager;
进口android.accounts.AccountManagerCallback;
进口android.accounts.AccountManagerFuture;
进口android.accounts.AuthenticatorException;
进口android.accounts.OperationCanceledException;
进口android.os.Bundle;
进口android.widget.EditText;
进口android.widget.Toast;
进口java.io.IOException异常;
进口java.util.concurrent.TimeUnit中;
公共类OnTokenAcquired实现AccountManagerCallback<群组> {
       私人的EditText等;
       公共OnTokenAcquired(的EditText等){
              this.et =等;
       }
       公共无效的run(AccountManagerFuture<群组>的结果){
              捆束;
              尝试{
                     Toast.makeText(NULL,开始!,Toast.LENGTH_LONG).show();
                     捆绑= result.getResult(1,TimeUnit.SECONDS);
                     字符串标记= bundle.getString(AccountManager.KEY_AUTHTOKEN); et.append(\\ nToken:+令牌);
                     Toast.makeText(NULL,令牌,Toast.LENGTH_LONG).show();
              }赶上(OperationCanceledException E){
                     e.printStackTrace();
              }赶上(AuthenticatorException E){
                     e.printStackTrace();
              }赶上(IOException异常五){
                     e.printStackTrace();
              }
       }
}


解决方案

研究几个小时的来源,我发现这个code之后:

 公开捆绑getAuthToken(AccountAuthenticatorResponse响应,客户账户,串authTokenType,捆绑loginOptions)抛出NetworkErrorException {
     返回null;
}

这意味着,Android的交换验证器与Exchange Server不提供Tokenbased认证......

I am working on an Android 3.0 program that can connect to a SSL'd php webservice (outputs data in JSON, I can modify the server). The tablets that are connecting to this service have a corporate Microsoft ActiveSync (exchange 2010) account, and only that account (no google accounts,FB, etc). I would like to write a program that can use the credentials saved in the tablet's android.accounts.AccountManager to make secure requests on that PHP webservice. I tried following some google examples but I think the problem lies when I use the line: AccountManagerFuture<Bundle> data = am.getAuthToken(b, "JWT", options, this, ota, null); The application just hangs and I get no results. In fact, setting a breakpoint at any line in the OnTokenAcquired class, doesn't do anything. AKA OnTokenRequired never gets executed

Any advice or direction? I'm sure this could be helpful for getting corporate android client software

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();
              }            
       }
}

解决方案

After some hours of research in the sources I've found this code:

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

This means, the android exchange Authenticator doesn't provide the Tokenbased Authentication for Exchange-Server...

这篇关于获取的Microsoft Exchange的身份验证令牌通过Android的的AccountManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆