我們使用:使用BMS客戶端時如何刷新令牌以及何時刷新令牌,以及是否有強制刷新的方法?
BMSClient.getInstance().registerAuthenticationListener("realm", new CustomAuthentication(this));
和:
AuthorizationManager.createInstance(this.getApplicationContext());
AuthorizationManager.getInstance().setAuthorizationPersistencePolicy(AuthorizationManager.PersistencePolicy.ALWAYS);
存儲在手機上的授權數據。 「授權數據將保存在本地存儲」設置爲始終。
上面的代碼總是在啓動時在我們的啓動畫面上運行,所以它總是在應用程序重新啓動時運行。
我們遇到的問題是,在我們懷疑令牌過期了一段時間後(小時或數天),我們以HTTP 307的形式得到響應。即使在重新啓動應用程序後,我們仍然根據我們的請求獲得此響應。解決它的唯一方法是從設置中進入應用程序並清除所有數據。
下面的問題將幫助我們向前走在我們的測試和可能的解決方案:
- 有多久令牌BMSClient緩存? (測試目的)
- AuthorizationManager是否可以幫助我們以任何方式強制執行新的令牌提取?
- 他們是否正在註銷註銷功能?
我們的定製監聽器:
public class CustomAuth implements AuthenticationListener {
private Context activityContext;
public CustomAuth(Context activityContext) {
this.activityContext = activityContext;
}
@Override
public void onAuthenticationChallengeReceived(AuthenticationContext authContext, JSONObject challenge, Context context) {
//1. read the challenge JSONObject
//2. handle the challenge (use the context for handling UI based operations)
//3. return response using the AuthenticationContext authContext
SharedPreferences preferences = activityContext.getSharedPreferences("UserPreference", Context.MODE_PRIVATE);
String email = preferences.getString("email", "");
if(email.equals("")) {
email = "[email protected]";
}
JSONObject jsonEmail = new JSONObject();
try {
jsonEmail.put("email", email);
} catch (JSONException e) {
authContext.submitAuthenticationChallengeAnswer(null);
}
authContext.submitAuthenticationChallengeAnswer(jsonEmail);
}
@Override
public void onAuthenticationSuccess(Context context, JSONObject info) {
//additional operations in case of authentication success
Log.d("Authentication", "Auth success: " + String.valueOf(info));
}
@Override
public void onAuthenticationFailure(Context context, JSONObject info) {
//additional operations in case of authentication failure
Log.d("Authentication", "Auth failure ." + String.valueOf(info));
}
}
添加了我們的自定義authlistener。我們非常確定這可能是您的一個問題。我們正在經歷的是,最近幾天,應用程序突然不會去保護資源。在查看日誌時,我們從onAuthFail獲取日誌,並使用json {「reson」:「Login Failed」}。在調試時我們可以認爲它永遠不會進入onAuthChallangeReceived。然後突然它會受到挑戰,一切都很好。你知道,如果你們最近有任何更新可能是背後的行爲? – enno4859
您可以爲我提供您的適用於您的Bluemix實例的appID,以便我可以查看日誌 –
我們的產品應用程序ID:9c877adb-c380-43ce-bb2d-ac9c3d32a04c 我們的開發人員實例應用程序ID:905ce1db-d7b5-41ca-9b4e -a9e1a0695fed 我們在兩種情況下遇到同樣的問題。 – enno4859