简体   繁体   English

Sencha touch 2 azure如何在InvokeApi中添加标头身份验证?

[英]Sencha touch 2 azure how to add header authentication to invokeApi?

So how can I add header authentication to the Ext.Azure.invokeApi() request? 那么,如何向Ext.Azure.invokeApi()请求添加标头身份验证? My program needs header authentication to access the custom api, because I have set the operation permissions to only authenticated users. 我的程序需要标头身份验证才能访问自定义api,因为我已将操作权限设置为仅通过身份验证的用户。

In the current version, header auth isn't added to the invoke API - but it's easy to add via an override. 在当前版本中,标头auth未添加到invoke API中-但通过覆盖很容易添加。

Take a look at Ext.azure.Azure.getDefaultHeaders() - you could change it to the following: 看一下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;
}

And that would do the trick. 这样就可以了。 I'll log a bug about not being able to do this in the current version and will try to get it fixed soon. 我将记录一个有关当前版本中无法执行此操作的错误,并将尝试尽快修复。

To build the override, include the following code somewhere in your app: 要构建覆盖,请在您的应用中的某处包含以下代码:

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;
    }
});

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM