2016-03-22 102 views
0

我一直在嘗試開發適用於應用程序的基於適配器的身份驗證,我不確定挑戰處理程序爲什麼不會在此觸發。挑戰不處理與基於適配器的身份驗證的挑戰

客戶端main.js:

var AuthenticationHandler = WL.Client.createChallengeHandler("EventAuthRealm"); 
 

 
AuthenticationHandler.isCustomResponse = function(response) { 
 
    if (!response || !response.responseJSON || response.responseText === null) { 
 
    return false; 
 
    } 
 
    if (typeof(response.responseJSON.authStatus) !== 'undefined') { 
 
    return true; 
 
    } else { 
 
    return false; 
 
    } 
 
}; 
 

 
AuthenticationHandler.handleChallenge = function(response) { 
 
    var authRequired = response.responseJSON.authRequired; 
 

 
    if (authRequired == false) { 
 

 
    WL.logger.debug("done"); 
 
    busyIndicator.hide(); 
 
    AuthenticationHandler.submitSuccess(); 
 
    toEventList(); //function to navigate to next page 
 

 

 
    } else if (authRequired == true) { 
 

 
    WL.logger.debug("false"); 
 
    busyIndicator.hide(); 
 
    AuthenticationHandler.submitFailure(); 
 
    WL.Logger.debug(response.responseJSON.errorMessage); 
 
    } 
 
};

登錄功能:

function login() { 
 

 
    var reg = $("#attendeeId").val(); 
 
    var userpw = $("#attendeePw").val(); 
 

 
    busyIndicator.show(); 
 
    var invocationData = { 
 
    adapter: "eventdbAdapter", 
 
    procedure: "submitAuthentication", 
 
    parameters: [reg, userpw] 
 
    }; 
 

 
    AuthenticationHandler.submitAdapterAuthentication(invocationData, {}); 
 

 
};

登錄頁面的

HTML代碼:

<div data-role="page" id="eventloginpage"> 
 
    <div data-role="header" align="center" data-theme="b">Event app</div> 
 

 
    <div data-role="content" style="padding: 15px" id="wat"> 
 
    <input type="text" name="attId" id="attendeeId" placeholder="Attendee ID"> 
 
    <input type="password" name="password" id="attendeePw" placeholder="Attendee Password"> 
 

 
    <!-- Buttons here --> 
 
    <a href="#" data-role="button" id="loginButton" data-theme="b" onclick="login();">Login</a> 
 
    <a href="#" data-role="button" id="button" onclick="logout();">Logout for now</a> 
 
    </div> 
 

 
    <div data-role="footer" align="center">Text</div> 
 
</div>

如果這可能是相關的,我構建的應用程序的多頁組件使用pagecontainer變化教程以下。

例子:

function toEventList() { 
 
    $(':mobile-pagecontainer').pagecontainer('change', 'eventpage.html'); 
 
}

每當我執行登錄功能,一切都會按計劃,直到submitAdapterAuthentication被調用。

Google開發者控制檯返回請求超時。在Android設備上執行應用程序時,Logcat會顯示狀態代碼201.我只能假定對象是使用從字段收集的信息成功創建的,但是,處理程序根本不提交憑證。

任何類型的建議將不勝感激。如果我的帖子看起來很愚蠢,我會提前道歉,因爲我對MobileFirst和Web技術一般都不太熟悉。

+0

狀態碼爲201表示。實體格式由Content-Type標題字段中給出的媒體類型指定。另一方面,原始服務器必須在返回201狀態碼之前創建資源。 201狀態碼指示請求已成功,因此已創建資源(例如新頁面)。 –

+0

所以請分享您的適配器代碼。或流動適當的文檔https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/all-tutorials/ –

+0

謝謝您的回覆哈桑。我在以下鏈接中添加了適配器的js和xml文件的代碼:https://jsfiddle.net/srvc0pk7/ – Willarch

回答

0

我想明白爲什麼它以前沒有正常工作。在適配器端,我沒有對submitAuthentication()中的測試登錄值使用嚴格的相等運算符,如示例中所示。但是,我認爲其他類型的平等運營者會起作用,但似乎並非如此。據我所知,這不是寫在任何文檔中的。

我之前提到的401錯誤似乎是MobileFirst服務器根據文檔對內置組件之一執行的檢查。

我也確保清理服務器並重新部署應用程序。

0

這將有助於瞭解您正在使用的MFP的版本,以便您可以查看相應的文檔。

請確保follwing在wlCommonInit()中實現。你可以從這裏看到documetation,Documentation,它需要聯繫工作燈服務器

WL.Client.connect( { 的onSuccess:onConnectSuccess, onFailure處:onConnectFailure });

+0

感謝您指出並抱歉在開始時不包含它。我正在使用MFP 7.1.0。我確實缺少來自wlCOmmonInit()的connect()。瀏覽器控制檯沒有變化。在我的Android設備上,我得到FWLSE0335E:在服務器上找不到授權失敗的客戶端ID。 – Willarch

+0

請清除網頁瀏覽器的cookie緩存,關閉它並再次嘗試 – Spindoctor

+0

仍然一樣。我注意到,作爲一個潛在的解決方案多次搜索,但它似乎沒有工作。 – Willarch

相關問題