2017-03-18 78 views
0

我正在將Azure集成到我的應用程序中。我在Active Directory的Azure門戶中創建了應用程序,並使用ADAL庫進行了集成,但是當我運行獲取Microsoft登錄屏幕的應用程序時, 。在目錄中找不到標識符

i am getting this error

對於登錄創建的按鈕和的onclick按鈕調用此

if (mResult != null) { 
     // logout 
     CookieManager cookieManager = CookieManager.getInstance(); 
     cookieManager.removeAllCookie(); 
     CookieSyncManager.getInstance().sync(); 
     authenticationContext.getCache().removeAll(); 
    } else { 
     // login 
     authenticationContext.acquireToken(LoginActivity.this,Constant.CLIENT_ID, 
       Constant.CLIENT_SECRETE_KEY, Constant.REDIRECT_URL, "", PromptBehavior.Auto, "", 
       callback);//CLIENT_ID=my appid at the of app registration //CLIENT_SECRETE_KEY=secret key of registered app in Active Directory //REDIRECT_URL=passing valid url 
    } 

和回調的OnCreate LoginActivity

authenticationContext = new AuthenticationContext(LoginActivity.this, 
       Constant.AUTHORITY_URL, true);// Authority_URL=https://login.windows.net/mydirectoryname.onmicrosoft.com 

的初始化authenticationcontext()

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    authenticationContext.onActivityResult(requestCode, resultCode, data); 
} 

private void showInfo(String msg) { 
    Log.e("", msg); 
} 

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


     @Override 
     public void onError(Exception exc) { 
      showInfo("getToken Error:" + exc.getMessage()); 
     } 

     @Override 
     public void onSuccess(AuthenticationResult result) { 
      mResult = result; 
      startActivity(new Intent(LoginActivity.this, SecondActivity.class)); 


      if (mResult.getUserInfo() != null) { 
       Log.v("", "User info userid:" + result.getUserInfo().getUserId() 
         + " displayableId:" + result.getUserInfo().getDisplayableId()); 

      } 
     } 
    }; 

和Azure Portal在應用程序註冊中獲得了KEYVAULT和MicrosoftAzureActiveDirectory的許可(登錄並閱讀用戶配置文件許可) 我做錯了什麼?

回答

0

您的參數可能是錯誤的。在GitHub上檢查這個例子:https://github.com/Azure-Samples/active-directory-android/blob/master/TaskApplication/src/main/java/com/microsoft/aad/test/todoapi/ToDoActivity.java#L188

在那裏,它與完成:

mAuthContext.acquireToken(ToDoActivity.this, Constants.RESOURCE_ID, 
        Constants.CLIENT_ID, Constants.REDIRECT_URL, Constants.USER_HINT, 
        new AuthenticationCallback<AuthenticationResult>() { 

         @Override 
         public void onError(Exception exc) { 
          if (mLoginProgressDialog.isShowing()) { 
           mLoginProgressDialog.dismiss(); 
          } 
          Toast.makeText(getApplicationContext(), 
            TAG + "getToken Error:" + exc.getMessage(), Toast.LENGTH_SHORT) 
            .show(); 
          navigateToLogOut(); 
         } 

         @Override 
         public void onSuccess(AuthenticationResult result) { 
          if (mLoginProgressDialog.isShowing()) { 
           mLoginProgressDialog.dismiss(); 
          } 

          if (result != null && !result.getAccessToken().isEmpty()) { 
           setLocalToken(result); 
           sendRequest(); 
          } else { 
           navigateToLogOut(); 
          } 
         } 
        }); 

你不應該在移動應用客戶端的祕密呢。任何人都可以解開你的應用程序並找到它。

+0

什麼在Constant.ResourceId中傳遞以及代碼中使用ClientSecretKey的位置 – sss

+0

您不使用客戶端密鑰。您不能在移動應用中使用它,因爲它們在不受信任的環境中運行。資源ID是您想要訪問令牌的資源的URI。所以例如'https:// graph.windows.net /'用於Azure AD Graph API。 – juunas

+1

authenticationContext.acquireToken(LoginActivity.this,Constant.RESOURCE_ID, Constant.CLIENT_ID,Constant.REDIRECT_URL,「」,PromptBehavior。Auto,「」, callback);我使用這個Authority_Url = https://login.windows.net/(mydirectoryname).onmicrosoft.com this Redirect_url =「https://(mydomainname)/ users/auth/azure_oauth2/callback」 這個資源id =「 https://login.windows.net/(mydirectory_id)/oauth2/token「 但得到AADSTS50001錯誤* – sss

0

如果(結果!= NULL & &!result.getAccessToken()的isEmpty()){ 是錯誤的,加標記空檢查或添加成功的getStatus檢查...

是,MS特殊製造不良android示例[我認爲:)];

簡單的方法是打開下AD和開放的編輯清單您的應用程序creted: 從樣本: AUTHORITY_URL - 是「identifierUris」從應用程序清單(未Android清單;從註冊廣告網絡的API應用程序添加艙單); CLIENT_ID - 是appId; RESOURCE_ID - 也來自manifest; 「requiredResourceAccess」:[{「resourceAppId」:有些時候是auth ex消息;

並且您應該在AD應用程序中添加相同的回覆Url;

如果auth直接重定向到todoactivity由於某種原因導致失敗狀態,但如果打開添加用戶,您可以看到登錄用戶信息並登錄成功狀態;

因此,在修復該樣本後,它完全可以工作,但這是一場長達1-2天的頭腦風暴; 預計更多樣式ms樣品,看起來像每年的質量是去媽媽和更低;