首页 > 解决方案 > Salesforce Commerce Cloud 控制器身份验证

问题描述

我在商业云中做了一个控制器,以便从外部订单管理服务更新订单。

然后 Commerce Cloud 内部的控制器将通过 POST 方法接收订单详细信息,并相应地将更新保存在订单中。

问题是我无法通过外部资源发送请求。对于任何请求,我都会收到结果:

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
    <title>401 - Authorization Required.</title>
    <link rel="STYLESHEET" type="text/css" href="/waroot/style.css">
</head>

我正在发送请求以获取https://account.demandware.com/dwsso/oauth2/access_token中的令牌,并使用正确的令牌发送请求以及资源位置的令牌,遵循https://中给出的示例documentation.b2c.commercecloud.salesforce.com/DOC1/index.jsp?topic=%2Fcom.demandware.dochelp%2Fcontent%2Fb2c_commerce%2Ftopics%2Fsearch_engine_optimization%2Fb2c_digital_url_syntax_without_seo.html

例如:https://localhost/on/demandware.store/Sites-SiteGenesis-Site/default/Hello-World

我尝试了两种不同的控制器:

server.post('Test', function (req, res, next) {
    try {
        Transaction.wrap(function () {
            // Some logic
        });
    } catch(e) {
        Logger.error('Exception "{0}"" .', e.message);
    }
    next();
});

还有一个更简单的方法:

exports.Test = function(){
    response.getWriter().println('Hello World!');
};
exports.Test.public = true;

但无论我做什么,我总是收到 401 - Authorization Required 响应。

我应该更改身份验证过程、控制器或我的资源位置是否有问题以允许来自第三方系统的请求访问我的控制器?

标签: node.jsauthenticationcontrollerrestsalesforce-commerce-cloud

解决方案


推荐阅读