2016-04-21 113 views
1

當我發送POST請求https://api.molt.in/v1/customers/authenticate我得到了奇怪的回報:客戶認證

'Authorization':'Bearer ' + token_data.access_token 

你可以在這裏看到我的全碼:

{"status":false,"error":"HTTP method used is not supported for this endpoint"} 

如果我添加自定義標題,我只得到這個錯誤:

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:"[email protected]", 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); 

    }); 

回答

2

如果你打電話https://api.molt.in/v1/customers/token,而不是https://api.molt.in/v1/customers/authenticate那麼你應該找回立方米stomer令牌,然後可以用於後續請求。

如果你使用JS,可以在moltin SDK手動添加,建立這個分支副本:https://github.com/moltin/js-sdk/tree/feature/customer-logins

這應該有使用moltin.Customer.login()方法本身支持...

+0

中的代碼該分支缺少Customer的端點定義。添加該行後: Customer.prototype.endpoint ='customers'; 它完美的作品。 –