OAuth 逻辑放在哪里?
我在项目中使用 Zend Framework,并且创建一个仅用于身份验证的控制器。 在此项目中,我们将接受用户通过其他网站(如 facebook、twitter、myspace 等)的帐户进行注册。为此,我们将使用 OAuth。但我怀疑应该将每个 OAuth 站点相关身份验证的逻辑放在哪里?仅以 facebook 为例,在我的控制器中占用了 50 行代码,这样我的控制器就不会瘦了...
我不知道该把它放在哪里。 为每个站点创建一个 Zend_Auth 适配器,仅为此创建一项服务,最好的方法是什么?
抱歉英语不好。 :)
I'm using Zend Framework in a project, and I'm creating a controller only for authentication.
In this project we'll accept that a user signs up through a account of other sites like facebook, twitter, myspace, etc.. For this we will be using OAuth. But I'm having a doubt where I should put the logic for each OAuth site related authentication? Only the facebook, for example, occupied 50 lines of code in my controller, and in this way my controllers will not be thin...
I wonder where I should put this.
Create an Zend_Auth adapter for each one of the sites, create a service only to this, what is the best way?
And sorry the poor english. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JF Austin 有一个相当使用 Zend_Oauth_Consumer。从那里为 Twitter、Facebook 等创建特定的子类似乎很简单。他甚至似乎有一个 Twitter适配器已经。 他的博客文章
或者,请注意 这个 by 劳埃德·沃特金。
结果:所有 OAuth 逻辑都隐藏在这些适配器中。然后,您的控制器可以实例化此身份验证适配器,将其提供给
Zend_Auth::authenticate($adapter)
,然后根据返回的结果采取操作,使控制器专注于更高级别的应用程序连接。JF Austin has a fairly generic OAuth authentication adapter implementation that uses a Zend_Oauth_Consumer. Creating specific subclasses of this for Twitter, Facebook, etc seems to be straightforward from there. He even seems to have a Twitter adapter already. Use of the adapter is described in his blog post about it.
Alternatively, note this one by Lloyd Watkin.
Upshot: all the OAuth logic is buried inside these adapters. Your controllers can then instantiate this authentication adapter, feed it to
Zend_Auth::authenticate($adapter)
, and then take action based upon the returned result, keeping the controller focused on the higher-level app wiring.您的 OAuth 逻辑应该像您的所有业务逻辑一样位于模型内部。您的控制器应该做的是控制程序流程并设置视图变量以在视图脚本中使用。
亲切的问候
加里
Your OAuth logic should live inside models as should all your buisiness logic. Your controller should be left to do is control the program flow and setup view variables for use in your view script.
Kind regards
Garry