gpt4 book ai didi

javascript - Sencha touch 2 azure如何向invokeApi添加 header 身份验证?

转载 作者:行者123 更新时间:2023-12-03 12:22:42 25 4
gpt4 key购买 nike

那么如何将 header 身份验证添加到 Ext.Azure.invokeApi() 请求中?我的程序需要 header 认证才能访问自定义api,因为我设置了只有经过认证的用户才有操作权限。

最佳答案

在当前版本中, header 身份验证未添加到调用 API 中 - 但可以通过覆盖轻松添加。

看看 Ext.azure.Azure.getDefaultHeaders() - 您可以将其更改为以下内容:

getDefaultHeaders : function() {
var headers = {
'X-ZUMO-APPLICATION' : this.getAppKey(),
'X-ZUMO-VERSION' : this.getUserAgentString()
};

var authorizedUser = Ext.azure.Authentication.getCurrentUser();

if (typeof authorizedUser !== 'boolean') {
headers['X-ZUMO-AUTH'] = authorizedUser.get('token');
}

return headers;
}

这样就可以了。我将记录一个有关在当前版本中无法执行此操作的错误,并将尝试尽快修复它。

要构建覆盖,请在应用程序中的某个位置包含以下代码:

Ext.define('Ext.override.Azure', {
override : 'Ext.azure.Azure',

getDefaultHeaders : function() {
var headers = {
'X-ZUMO-APPLICATION' : this.getAppKey(),
'X-ZUMO-VERSION' : this.getUserAgentString()
};

var authorizedUser = Ext.azure.Authentication.getCurrentUser();

if (typeof authorizedUser !== 'boolean') {
headers['X-ZUMO-AUTH'] = authorizedUser.get('token');
}

return headers;
}
});

关于javascript - Sencha touch 2 azure如何向invokeApi添加 header 身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24363273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com