【问题标题】:NodeJS HapiJS with OAUTH2 and Salesforce (force.com)NodeJS HapiJS 与 OAUTH2 和 Salesforce (force.com)
【发布时间】:2016-03-20 13:41:47
【问题描述】:

您好 bell / hapi 开发人员和/或专家...提前感谢您的任何建议...我正在尝试为 oauth 完成 forcedotcom 策略(salesforce),它几乎可以工作,我可以'找不到任何有关该错误的文档。

我收到一个错误“[错误:获取自定义访问令牌失败]”

我的应用程序正确重定向到 salesforce,提示登录 Salesforce 域,进行身份验证,并正确返回回调 URL,但是,回调 url 路由/控制器失败,因为“isAuthenticated”为假,但我可以在请求中,从 salesforce 返回到回调的 URL 包含一个“代码”参数(身份验证访问令牌和一个“状态”值。)

这是我的策略

// Register bell with the server
server.register(require('bell'), function(err) {
  server.auth.strategy('forcedotcom', 'bell', {
    provider: {
      protocol: 'oauth2',
      useParamsAuth: false,
      auth: config.forcedotcom.authURL,
      token: config.forcedotcom.tokenURL
    },
    isSecure: false,
    clientId: config.forcedotcom.clientID,
    clientSecret: config.forcedotcom.clientSecret,
    password: config.sessionCookie.sessionSecret,
    location: config.forcedotcom.callbackURL
  });
});

这里是回调路由(在callbackURL的配置中指定

server.route({
  method: ['GET', 'POST'],
  path: '/auth/forcedotcom/callback',
  config: {
    auth: {
      strategy: 'forcedotcom',
      mode: 'try'
    },
    handler: function(request, reply) {
      console.warn('request', request, 'reply', reply);
      if (!request.auth.isAuthenticated) {
        return reply('Authentication failed due to: ' + request.auth.error.message);
      }

      return reply.redirect('/');
    }
  }
});

任何方向都会令人惊叹。谢谢!

【问题讨论】:

  • 在 hapi 开发人员的帮助下,我们在第二次呼叫/令牌请求中看到了来自 salesforce 的 400...另一个与 hapi 无关的帖子通过 uri 解码来自 salesforce 的 oauth 代码解决了这个问题(第一个响应),在发送到令牌回调之前。我不知道如何用 hapi 做到这一点,但我们越来越近了。 similar-but-different-problem-resolved

标签: javascript node.js oauth-2.0 salesforce hapijs


【解决方案1】:

我相信您需要将useParamAuth 设置为true。 Salesforce 要求 client_secretclient_id 作为查询参数而不是标题。

你也可以试试这个库https://www.npmjs.com/package/hapi-salesforce-auth-suite,它包括signrequest auth和oauth。

【讨论】:

  • 这是问题的一部分,另一部分,我不好意思说是 cookie SSL 设置,在 localhost 中测试 SSL cookie 并从 http 浏览没有正确设置 cookie。 :(
猜你喜欢
  • 2015-06-21
  • 1970-01-01
  • 2013-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-26
  • 1970-01-01
相关资源
最近更新 更多