Node.js 客户验证

Node.js 客户验证,node.js,moltin,Node.js,Moltin,当我向https://api.molt.in/v1/customers/authenticate我收到奇怪的回音: {"status":false,"error":"HTTP method used is not supported for this endpoint"} 我只有在添加自定义标题时才会出现此错误: 'Authorization':'Bearer ' + token_data.access_token 您可以在此处看到我的完整代码: var formData = {grant_

当我向
https://api.molt.in/v1/customers/authenticate
我收到奇怪的回音:

{"status":false,"error":"HTTP method used is not supported for this endpoint"}
我只有在添加自定义标题时才会出现此错误:

'Authorization':'Bearer ' + token_data.access_token
您可以在此处看到我的完整代码:

var formData = {grant_type:'implicit', client_id: clientId}

    request.post({url:'https://api.molt.in/oauth/access_token',form:formData}, function (err, httpResponse, body){
        if(err){
            console.log(err);
        }
        token_data = JSON.parse(body);
    });

    moltin.Authenticate(function(){

        var options = {url:'https://api.molt.in/v1/customers/authenticate',
            form:{email:"xxxx@xxx.com", password:'xxxx'},
            headers: {
                'Authorization':'Bearer ' + token_data.access_token
            }
            };

        function callBack(err, httpResponse, body){
            if(err){
                console.log(err);
            }
            console.log("\naccess_token: "+token_data.access_token+"\nbody: "+body);
            res.send(body);
        }

        request.post(options,callBack);

    });

如果您呼叫
https://api.molt.in/v1/customers/token
而不是
https://api.molt.in/v1/customers/authenticate
然后,您应该取回客户令牌,然后用于后续请求

如果您正在使用JS,并且可以手动添加moltin SDK,请从此分支生成副本:


应该支持在本地使用
moltin.Customer.login()
方法…

分支中的代码缺少客户端点的定义。添加行后:Customer.prototype.endpoint='customers';它工作得很好。