简体   繁体   中英

Sencha touch 2 azure how to add header authentication to invokeApi?

So how can I add header authentication to the Ext.Azure.invokeApi() request? My program needs header authentication to access the custom api, because I have set the operation permissions to only authenticated users.

In the current version, header auth isn't added to the invoke API - but it's easy to add via an override.

Take a look at Ext.azure.Azure.getDefaultHeaders() - you could change it to the following:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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