【问题标题】:How to call Web API from ExtJS with token based authentication如何使用基于令牌的身份验证从 ExtJS 调用 Web API
【发布时间】:2018-02-09 07:35:14
【问题描述】:

Ext.Ajax.request({ 网址:“员工/搜索”,
方法:'POST',
标头:{ "Content-Type":"application/json","Accept":"application/json","Authorization":"OAuth oauth_token=158ghhBtgf2586525hggfgdf" },
jsonData: {
“名字”:txtFirstName.getValue()
},
成功:函数(响应){
},
失败:函数(响应){
}
});

这给了我 401(未经授权的请求)

【问题讨论】:

    标签: javascript asp.net-web-api extjs access-token


    【解决方案1】:

    我正在使用 Microsoft 的 adal.js 库,并使用以下代码:

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

    【讨论】:

      猜你喜欢
      • 2017-04-19
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      • 2016-07-31
      • 2017-07-01
      • 2016-06-09
      • 2019-03-13
      • 1970-01-01
      相关资源
      最近更新 更多