Sencha Architect 4-ExtJS 6.5-> Dreamfactory 2.9身份验证会话令牌 [英] Sencha Architect 4 - ExtJS 6.5 -> Dreamfactory 2.9 Authentication Session Token
问题描述
我有点卡住,我想问一下您的建议,我正在尝试设置登录窗口//使用Sencha Architect中的DreamFactory进行身份验证,但是我几乎是一个初学者.
I got a little bit stuck and I would like to ask your advice, I am trying to setup a login window // authentication using DreamFactory in Sencha Architect however I am pretty much a beginner.
我当前的代码是:
var username = Ext.getCmp('usr').getValue(),
password = Ext.getCmp('pwd').getValue();
Ext.Ajax.defaultHeaders = {
'X-DreamFactory-Api-Key' : 'xyz',
'Content-Type' : 'application/json'
};
Ext.Ajax.request({
url: 'http://dreamfactoryaddy:8080/api/v2/user/session',
withCredentials: true,
email: username,
password: password,
cors: true,
success: function(response) {
var obj = Ext.decode(response.responseText);
Ext.Ajax.defaultHeaders = {
'X-DreamFactory-Api-Key' :
'xyz', 'Content-Type' : 'application/json', 'X-DreamFactory-Session-
Token': obj.session_token
};
console.log(obj);
},
failure: function(response) {
console.log(response.responseText);
}
});
我收到此错误:
{"error":{"code":401,"context":null,"message":"There is no valid session for the current request.","status_code":401}}
您能给我一些如何正确处理会话的建议吗?
Can you give me some advice how to handle Sessions properly?
更新2:
var username = Ext.getCmp('usr').getValue(),
password = Ext.getCmp('pwd').getValue(),
headers = {
'X-DreamFactory-Api-Key' : 'xyz',
'Content-Type' : 'application/json'
};
Ext.Ajax.setDefaultHeaders(headers);
Ext.Ajax.request({
url: 'http://chalton.swiftmedia.ca:8080/api/v2/user/session',
withCredentials: true,
jsonData: {
"email" : username,
"password" : password
},
cors: true,
success: function(response) {
var obj = Ext.util.JSON.decode(response.responseText),
newheaders = {
'X-DreamFactory-Api-Key' : 'xyz',
'Content-Type' : 'application/json',
'X-DreamFactory-Session-Token': obj.session_token
};
console.log(response.responseText);
Ext.Ajax.setDefaultHeaders(newheaders);
},
failure: function(response) {
console.log(response.responseText);
}
});
},
推荐答案
如果检查浏览器控制台,可能会发现defaultHeaders
未正确应用于您的Ajax请求.
If you check the browser console, you may find that the defaultHeaders
are not correctly applied to your ajax requests.
我有其他我想要作为默认标题的其他标题也有同样的问题. Ext.Ajax.defaultHeaders = x
无效,Ext.Ajax.setDefaultHeaders(x)
无效.
I had the very same issue with arbitrary other headers I wanted as the default headers. Ext.Ajax.defaultHeaders = x
just doesn't work, Ext.Ajax.setDefaultHeaders(x)
does.
这篇关于Sencha Architect 4-ExtJS 6.5-> Dreamfactory 2.9身份验证会话令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!