authentication - 什么是最佳管理设计/架构实践的方法,以在ribbon.js应用程序中管理身份验证( session )和授权

标签 authentication backbone.js authorization

我在任何地方都找不到很多东西。大多数示例应用程序只是不谈论安全性等。假定将使用基于rest的API调用对用户进行身份验证。应如何构造应用程序以确保身份验证[也可以授权]。指向示例应用程序的指针会很棒。请根据单页应用程序和常规应用程序添加 View 。
[我相信每个观点都应该照顾好它]

最佳答案

几个月前做一个使用基于REST的api的单页应用程序时遇到了相同的问题。搜索答案后,我想到的是使用HTTP的现有401和403错误。我让我的API返回了这些错误。然后使用扩展的错误处理模型来捕获这些异常,以处理这些错误,并通过路由器navigate函数将其路由至我的登录名。

var ErrorHandlerModel = Backbone.Model.extend({

    initialize: function(attributes, options) {
        options || (options = {});
        this.on("error", this.errorHandler);
        this.init && this.init(attributes, options);
    },

    errorHandler: function(model, error) {
        if (error.status == 401 || error.status == 403) {
          app.history.navigate('login', true);
        }
    }

});

在事后看来,尽管我认为最好使用全局jquery ajaxError函数来代替。上面的片段基于几个月前的类似question posted here

我还必须覆盖 Backbone 的默认获取行为,以便我可以使用ogin触发错误,以捕获api的json响应中包含的响应变量。
var Login = Backbone.Model.extend({  

    urlRoot: '/login',

    parse: function(resp,xhr) {
        if (resp.response == 'success') {
            app.history.navigate('dashboard', true);
        }
        else {
            this.trigger('loginError');     
        }
    return false;
    }
});

关于authentication - 什么是最佳管理设计/架构实践的方法,以在ribbon.js应用程序中管理身份验证( session )和授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10920860/

相关文章:

ios - Cognito 身份验证有效但显示错误?

mongodb - 如何使用Golang和MongoDriver解决 "command find requires authentication"

python - Django 1.8(Python 3.4): Show different templates based on user authorization with Class-Based Views

authorization - 为什么Kubernetes的 “kubectl”被 “Authorization error”中止?

api - Binance API key

php - 使用 auth_request 模块的 Nginx 身份验证

使用 Backbone.js 发布到 Yii PHP 框架

javascript - 所有 View 逻辑都应该放在模板中吗?

javascript - Backbone 重新排序了一个集合,以便家始终是第一位的?

rest - 匿名访问 REST API?