【问题标题】:Authentication Context error intent is not resolved身份验证上下文错误意图未解决
【发布时间】:2015-03-17 03:12:18
【问题描述】:

我正在尝试使用示例代码 here 对 Azure Active Directory 的 Android 应用程序进行身份验证,以验证用户并最终获得对 Office 365 托管的 Sharepoint 列表的访问权限。但每次我尝试这样做时,我都会收到com.microsoft.aad.adal.AuthenticationException:活动未解决。验证清单文件中的活动名称。

是否有什么明显的地方我做错了,或者有什么我完全错过了?

这是我的 onCreate 方法代码

protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_dud);

  AuthenticationCallback < AuthenticationResult > callback = new AuthenticationCallback < AuthenticationResult > () {

    @
    Override
    public void onSuccess(AuthenticationResult result) {
      // TODO Auto-generated method stub
      Log.d("Authentication Callback", "onSuccess");
      Toast.makeText(getApplicationContext(), "Success",
        Toast.LENGTH_SHORT).show();

    }

    @
    Override
    public void onError(Exception exc) {
      // TODO Auto-generated method stub
      exc.printStackTrace();
      Log.d("Authentication Callback", "onError");
      Toast.makeText(getApplicationContext(), "Error",
        Toast.LENGTH_SHORT).show();

    }
  };
  try {
    ctx = new AuthenticationContext(DudActivity.this,
      "https://login.windows.net/mydomain.onmicrosoft.com", true);
    ctx.acquireToken(DudActivity.this, resource, clientId, redirectUri,
      PromptBehavior.Auto, callback);
  } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }

}

这是日志

03-13 13:08:10.025: E/AuthenticationContext(8980): DEVELOPER_ACTIVITY_IS_NOT_RESOLVED:2015-03-13 12:08:10-99d5c2bb-f33a-4a47-8f16-b111e528617c-意图未解决 版本:1.1.1 03-13 13:08:10.091:W/System.err(8980): com.microsoft.aad.adal.AuthenticationException:活动不是 解决。验证清单文件中的活动名称 03-13 13:08:10.092:W/System.err(8980):在 com.microsoft.aad.adal.AuthenticationContext.localFlow(AuthenticationContext.java:1274) 03-13 13:08:10.092: W/System.err(8980): 在 com.microsoft.aad.adal.AuthenticationContext.acquireTokenAfterValidation(AuthenticationContext.java:1217) 03-13 13:08:10.092: W/System.err(8980): 在 com.microsoft.aad.adal.AuthenticationContext.acquireTokenLocalCall(AuthenticationContext.java:1119) 03-13 13:08:10.092: W/System.err(8980): 在 com.microsoft.aad.adal.AuthenticationContext.access$5(AuthenticationContext.java:1082) 03-13 13:08:10.092: W/System.err(8980): 在 com.microsoft.aad.adal.AuthenticationContext$4.call(AuthenticationContext.java:1068) 03-13 13:08:10.092: W/System.err(8980): 在 com.microsoft.aad.adal.AuthenticationContext$4.call(AuthenticationContext.java:1) 03-13 13:08:10.092: W/System.err(8980): 在 java.util.concurrent.FutureTask.run(FutureTask.java:237) 03-13 13:08:10.092:W/System.err(8980):在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 03-13 13:08:10.092: W/System.err(8980): 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 03-13 13:08:10.092: W/System.err(8980): 在 java.lang.Thread.run(Thread.java:818) 03-13 13:08:10.092: D/身份验证回调(8980):onError

【问题讨论】:

    标签: android office365 adal


    【解决方案1】:

    错误实际上是要求您将活动放入清单文件中。你可以在https://github.com/AzureAD/azure-activedirectory-library-for-android/blob/master/README.md查看详情

    您的清单中需要有活动:

    <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
      <application
            android:allowBackup="true"
            android:debuggable="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
    
            <activity
                android:name="com.microsoft.aad.adal.AuthenticationActivity"
                android:label="@string/title_login_hello_app" >
            </activity>
      ....
      <application/>
    

    你还需要实现onActivityResult,这样adal才能完成对结果的处理。

    @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
         if (mContext != null) {
             mContext.onActivityResult(requestCode, resultCode, data);
         }
     }
    

    【讨论】:

    • 是的!谢谢它对我有用。我还注意到 acquireToken 方法的重载不需要传递上下文,这对我也有用。
    猜你喜欢
    • 1970-01-01
    • 2013-02-27
    • 2018-02-01
    • 1970-01-01
    • 2018-03-19
    • 2019-07-10
    • 2017-10-28
    • 2015-11-04
    • 1970-01-01
    相关资源
    最近更新 更多