【问题标题】:U2F JavaScript for Client Side in GWT (JSNI)用于 GWT 中客户端的 U2F JavaScript (JSNI)
【发布时间】:2015-03-27 09:58:16
【问题描述】:

我正在尝试使用此源代码从 GWT 项目中的 U2F Token 获得响应:

public class Test implements EntryPoint {

    @Override
    public void onModuleLoad() {
         Window.alert("Alert 3:"+u2FTest());
    }

    public static native String u2FTest()/*-{
    var respond = {rep: "Clear"};
    var RegistrationData = {"challenge":"dG7vN-E440ZnJaKQ7Ynq8AemLHziJfKrBpIBi5OET_0",
                            "appId":"https://localhost:8443",
                            "version":"U2F_V2"};
 $wnd.u2f.register([RegistrationData], [],
  function(data) {if(data.errorCode) {
        alert("U2F failed with error: " + data.errorCode);
        return;
    }

    respond.rep=JSON.stringify(data);
    alert("Alert 1: "+respond.rep); 
});
 alert("Alert 2: "+respond.rep);
 return respond.rep;
}-*/;

}

由于某些原因,我收到这样的警报:

  1. (警报 2)首先显示“清除”结果
  2. (警报 3)带有“清除”
  3. (警报 1)带有令牌响应

通常我必须得到(警报 1)和令牌响应,然后是 2,3。那么在获得令牌响应之前如何停止执行 谢谢,

【问题讨论】:

  • 我需要等到收到来自 Token 的 JSON 对象

标签: javascript google-app-engine gwt jsni fido-u2f


【解决方案1】:

拥抱异步!

public static native void u2FTest(com.google.gwt.core.client.Callback<String, Integer> callback) /*-{
  // …
  $wnd.u2f.register(regReqs, signReqs, $entry(function(response) {
    if (response.errorCode) {
      callback.@com.google.gwt.core.client.Callback::onFailure(*)(@java.lang.Integer::valueOf(I)(response.errorCode));
    } else {
      callback.@com.google.gwt.core.client.Callback::onSuccess(*)(JSON.stringify(response));
    }
  }));
}*-/;

(不要忘记在$entry() 中包装回调,以便将异常路由到GWT.UnhandledExceptionHandler,如果有的话)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-25
    • 2013-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多