【问题标题】:Intercepting outgoing Kendo Grid calls to add JWT authrization header拦截传出的 Kendo Grid 调用以添加 JWT 授权标头
【发布时间】:2015-04-03 12:51:32
【问题描述】:

我正在使用 AngularJs 开发单页应用程序。我的应用程序使用 JWT 授权标头令牌进行授权。我有 agularJs 拦截器,它将 Authorization 标头添加到来自我的 SPA 应用程序的每个传出 api 调用。

我最近在应用程序中添加了 Kendo UI,我注意到 Kendo Grid 发出的 api 调用没有通过我的 Angular 拦截器。

是否有一种干净的方法来拦截来自 KendoUi 组件的所有对外 API 调用,以便我可以添加授权标头令牌?

【问题讨论】:

    标签: asp.net-mvc angularjs kendo-ui single-page-application jwt


    【解决方案1】:
      function setAuthHeader(req) {
    
            var token = tokenStoreService.getToken();
            if (token) {
                req.setRequestHeader('Authorization', 'Bearer ' + token);
            }
        }
    
        function setGridAuthorization(dataSource) {
            if (dataSource && dataSource.transport && dataSource.transport.options) {
                var opt = dataSource.transport.options;
                if (opt.read) opt.read.beforeSend = setAuthHeader;
                if (opt.update) opt.update.beforeSend = setAuthHeader;
                if (opt.destroy) opt.destroy.beforeSend = setAuthHeader;
                if (opt.create) opt.create.beforeSend = setAuthHeader;
    
            } else if (dataSource && dataSource.transport) {
                var tran = dataSource.transport;
                if (tran.read) tran.read.beforeSend = setAuthHeader;
                if (tran.update) tran.update.beforeSend = setAuthHeader;
                if (tran.destroy) tran.destroy.beforeSend = setAuthHeader;
                if (tran.create) tran.create.beforeSend = setAuthHeader;
            }
        }
    

    【讨论】:

    • 服务器端 excel 导出怎么样?有没有一种干净的方法来拦截来自 KendoUi 组件的所有“代理 Excel 导出”调用,以便我可以添加授权标头令牌?提前致谢
    猜你喜欢
    • 2017-05-19
    • 2023-03-23
    • 2016-03-24
    • 2018-01-11
    • 2020-01-09
    • 2021-07-22
    • 1970-01-01
    • 2022-01-15
    相关资源
    最近更新 更多