submitAdapterAuthentication无效 [英] submitAdapterAuthentication not working

查看:148
本文介绍了submitAdapterAuthentication无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦我从质询处理程序收到submitAdapterAuthentication,我一直在尝试进行特定的操作,而我无法执行任何操作,因为我的代码甚至都没有通过它编译。我在一个角度服务的方法中使用submitAdapterAuthentication。该方法如下所示:

I have been trying to do a specific operation once I receive the submitAdapterAuthentication from the challenge handler and I could not do any operation because my code it does not even compile through it. I am using the submitAdapterAuthentication in one method of my angular service. The method looks like this:

login: function (user, pass) {
      //promise
      var deferred = $q.defer();
      //tempuser
      tempUser = {username: user, password: pass};
      userObj.user = user;
      checkOnline().then(function (onl) {
        if (onl) { //online
          console.log("attempting online login");
          var auth = "Basic " + window.btoa(user + ":" + pass);
          var invocationData = {
            parameters: [auth, user],
            adapter: "SingleStepAuthAdapter",
            procedure: "submitLogin"
          };
          ch.submitAdapterAuthentication(invocationData, {
            onFailure: function (error) {
              console.log("ERROR ON FAIL: ", error);
            },
            onConnectionFailure: function (error) {
              console.log("BAD CONNECTION - OMAR", error);
            },
            timeout: 10000,
            fromChallengeRequest: true,
            onSuccess: function () {
              console.log("-> submitAdapterAuthentication onSuccess!");
              //update user info, as somehow isUserAuthenticated return false without it
              WL.Client.updateUserInfo({
                onSuccess: function () {
                  //return promise
                  deferred.resolve(true);
                }
              });
            }
          });
        } else { //offline
          console.log("attempting offline login");
          deferred.resolve(offlineLogin());
        }
        uiService.hideBusyIndicator();
      });
      uiService.hideBusyIndicator();
      return deferred.promise;
    }

其中 ch
var ch = WL.Client.createChallengeHandler(securityTest);

checkOnline 是检查用户是否为是否在线:

and checkOnline is this function that checks whether the user is online or not:

function checkOnline() {
    var deferred = $q.defer();
    WL.Client.connect({
      onSuccess: function () {
        console.log("** User is online!");
        deferred.resolve(true);
      },
      onFailure: function () {
        console.log("** User is offline!");
        deferred.resolve(false);
      },
      timeout: 1000
    });
    return deferred.promise;
  }

最后这是 submitLogin 程序我有 SingleStepAuthAdapter.js 。 SingleStepAuthAdapter是适配器的名称。

Finally this is the "submitLogin" procedure that I have in my SingleStepAuthAdapter.js. SingleStepAuthAdapter is the name of the adapter.

//-- exposed methods --//
function submitLogin(auth, username){

  WL.Server.setActiveUser("SingleStepAuthAdapter", null);

  var input = {
    method  : 'get',
    headers: {Authorization: auth},
    path : "/",
    returnedContentType : 'plain'
  };

  var response = "No response";
  response = WL.Server.invokeHttp(input);

  WL.Logger.info('Response: ' + response.isSuccessful);
  WL.Logger.info('response.responseHeader: ' + response.responseHeader);
  WL.Logger.info('response.statusCode: ' + response.statusCode);

  if (response.isSuccessful === true && (response.statusCode === 200)){

    var userIdentity = {
      userId: username,
      displayName: username,
      attributes: {
        foo: "bar"
      }
    };

    WL.Server.setActiveUser("SingleStepAuthAdapter", userIdentity);

    return {
      authRequired: false
    };

  }

  WL.Logger.error('Auth unsuccessful');

  return onAuthRequired(null, "Invalid login credentials");
}

所以我试图向我的控制器发送一个承诺,以便重定向用户到另一个页面,但由于挑战处理程序甚至没有工作,因此未返回承诺。

So I am trying to send a promise to my controller in order to redirect the user to another page but the promise is not being returned as the challenge handler is not even working.

顺便说一下,我已经按照本教程 https://medium.com/@papasimons/worklight-authentication-done-right-with-angularjs-768aa933329c

有谁知道这是怎么回事?

推荐答案

你对Challenge Handler和我的理解有很大不同。

Your understanding of the Challenge Handler and mine are considerably different.

虽然

 ch.submitAdapterAuthentication()

在结构上类似于标准的适配器调用方法I从来没有使用任何回调。

is similar in structure to the standard adapter invocation methods I have never used any callbacks with it.

我的工作是从 IBM AdapteBasedAuthentication教程资料

基本思路是你的挑战处理程序应该有两个回调方法:

The basic idea is that your challenge handler should have two callback methods:

isCustomResponse()
handleChallenge()

您将看到这些函数被调用以响应您的提交。

You will see these functions invoked in response to your submission.

我建议先从这些方法开始。我不能评论您引用的离子示例,但我自己使用角度/离子与身份验证框架和挑战处理程序。我的出发点是上面引用的IBM材料。

I suggest that start by looking at those methods. I can't comment on the ionic example you reference, but I have myself used angular/ionic with the authentication framework and challenge handlers. My starting point was the IBM material I reference above.

这篇关于submitAdapterAuthentication无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆