简体   繁体   English

Appcelerator ACS.Users.login API获取错误代码400,并显示消息:“发送了无效的请求”。

[英]Appcelerator ACS.Users.login API Getting error code 400 with message: 'Invalid request sent.'

I am trying to store some data on Custom Object of Appcelerator ACS. 我正在尝试在Appcelerator ACS的“自定义对象”上存储一些数据。 So there will be a service to do that. 因此,将有一项服务来做到这一点。 Each time it require authentication to create a new object 每次需要身份验证以创建新对象时

But I am sometime getting below error while login with ACS. 但是我有时在使用ACS登录时遇到错误。 But it not occuring always. 但是它并不总是发生。 It only if I call service multiple time. 仅当我多次致电服务时。

error i am getting is: 我得到的错误是:

{ success: false, error: true, code: 400, message: "Invalid request sent." {成功:错误,错误:正确,代码:400,消息:“发送了无效的请求。” } }

Code used to login : 用于登录的代码:

ACS.Users.login(userData, function(data){
    if(data.success) {
        console.log("----------Successful to login.---------------");
        console.log(data);
        res.send(data);
        res.end();

    } else {
        console.log("------------------login failed---------------");
        console.log(data);
        res.send(data);
        res.end();
    }
},req, res);

Can some one can help me to understand how to re-use session id from node.ACS web service app (Not web app)? 有人可以帮我了解如何重用node.ACS Web服务应用程序(而非Web应用程序)中的会话ID吗?

How I can keep session / check session validity before pushing something to custom object? 如何在将某些内容推送到自定义对象之前保持会话/检查会话有效性? Has anyone faced similar issue? 有没有人遇到过类似的问题?

Thanks Peter 谢谢彼得

Since you are passing in the req and res parameters into ACS.Users.login, the session is saved in the _session_id cookie: 由于您要将req和res参数传递到ACS.Users.login中,因此该会话将保存在_session_id cookie中:

http://docs.appcelerator.com/cloud/latest/#!/guide/node_acs http://docs.appcelerator.com/cloud/latest/#!/guide/node_acs

When you make subsequent calls to ACS, you pass in the req and res parameters and it will check for this session token. 当您随后调用ACS时,您传入req和res参数,它将检查该会话令牌。

A session can become invalid after timeout or logout. 会话可能在超时或注销后变为无效。 To check whether a session is still good, one way is to check against this REST API endpoint (GET): 要检查会话是否仍然良好,一种方法是对照此REST API端点(GET):

https://api.cloud.appcelerator.com/v1/users/show/me.json?key=(YOUR ACS KEY)&_session_id=(SESSION ID OF THE USER) https://api.cloud.appcelerator.com/v1/users/show/me.json?key=(您的 ACS密钥)&_ session_id =(用户的会话ID)

Also, for some reason acs-node v0.9.3 appears to be returning the same session ID, even for different users. 另外,由于某些原因,即使对于不同的用户,acs-node v0.9.3似乎都返回相同的会话ID。 Some side-effects I've seen include (1) the wrong user attempting to make a change to an object, and (2) objects created by one user are actually owned by the last person who logged in. Making sure acs-node is at v0.9.2 avoids this issue. 我看到的一些副作用包括(1)试图更改对象的错误用户,以及(2)一个用户创建的对象实际上是最后登录的人所有。确保acs-node是v0.9.2中的版本避免了此问题。

Now that node-acs has been shut down , everyone is obliged to move to the new arrowdb node sdk. 现在, node-acs已关闭 ,每个人都必须移至新的arrowdb节点sdk。

To solve the issue above about not authenticating the User, before every ArrowDB call, make sure to pass the session_id of the user like so: 要解决以上关于不对用户进行身份验证的问题,请在每次ArrowDB调用之前,确保像这样传递用户的session_id:

// Connect Node.ACS to existing ACS
var ArrowDB = require('arrowdb'),
    arrowDBApp = new ArrowDB('XXYYZZZ', { // ArrowDB Key
        apiEntryPoint: 'https://api.cloud.appcelerator.com',
        autoSessionManagement: false, // handle session_id yourself
        prettyJson: true,
        responseJsonDepth: 3
    }); 

// == Creates the ACS_Event for a logged in User on ArrowDB ==
function createACSEvent(uniqueId, params) {
    arrowDBApp.sessionCookieString = params.session_id; //<-- THIS IS IT!
    arrowDBApp.eventsCreate({
        name: 'someEvent',
        start_time: params.start_time,
        custom_fields: params,
    }, function(err, result) {
        if (err) {
            logger.info( 'ERROR ACS_Event created '+ err);
        } else {
            logger.info( 'Success Creating ACSEvent ' + JSON.stringify(result));
        }
    });
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 收到错误 UnhandledPromiseRejectionWarning:错误:发送后无法设置标头。 在快递 js api - getting error UnhandledPromiseRejectionWarning: Error: Can't set headers after they are sent. in express js api 错误:发送标头后无法设置标头。 刷新获取请求后收到错误 - Error: Can't set headers after they are sent. error received after refreshing a get request 节点js中出现错误“错误:发送后无法设置标头。” - getting error in node js "Error: Can't set headers after they are sent." HTTP POST请求错误“错误:发送标头后无法设置标头。” - HTTP POST request error “Error: Can't set headers after they are sent.” 我收到“未处理的拒绝错误:发送标头后无法设置标头。” - I am getting “Unhandled rejection Error: Can't set headers after they are sent.” 得到错误:错误:发送标头后无法设置标头。 重新呈现页面后 - Getting error: Error: Can't set headers after they are sent. after rerendering page 调用api时不断出现400错误(错误请求) - Keep getting 400 error(Bad Request) while calling an api 只能发出一个没有错误的 GET 请求:“发送后无法设置标头。” - Can only make one GET request without error: "Can't set headers after they are sent." 错误:“已发送回复。” - Fastify - 无日志 - Error: "Reply was already sent." - Fastify - No logs 为什么我收到“错误:发送后无法设置标头。”? - Why am I getting “Error: Can't set headers after they are sent.”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM