开发者

Where to put OAuth logic?

开发者 https://www.devze.com 2023-03-11 11:51 出处:网络
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, twitt

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开发者_Go百科 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. :)


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消