简体   繁体   中英

How to call Web API from ExtJS with token based authentication

Ext.Ajax.request({ url: 'Employee/Search',
method: 'POST',
headers: { "Content-Type":"application/json","Accept": "application/json","Authorization": "OAuth oauth_token=158ghhBtgf2586525hggfgdf" },
jsonData: {
"FirstName": txtFirstName.getValue()
},
success: function(response) {
},
failure: function(response) {
}
});

This is giving me 401 (Unauthorized Request)

I am using adal.js library by Microsoft, and using the following code:

window.acquireTokenCallback = function (error, token) {
    if(error || !token) {
        Ext.alert('ADALERROR', error || 'Token empty');
        return;
    }
    // Apply token to all future Ajax requests.
    Ext.Ajax.setDefaultHeaders({
        'Authorization': 'Bearer ' + token,
        'Accept': 'application/json'
    });
    // Load Settings from Server.
    me.loadSettings();
};

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