![]() |
|
tiDoctrineOAuthServerPlugin - 0.0.4A OAuth Server plugin. |
|
![]() |
4
users
Sign-in
to change your status |
A OAuth Server plugin. |
The tiDoctrineOAuthServerPlugin provides the basis for making an OAuth server. It provides each requested URL in the OAuth protocol 1.0a (request token, user authorization and access token). It provides the pages to authorize/refuse the access to the connected sfDoctrineGuardUser. If the user is not connected, he is automatically redirected to a login page. The authorized consumer keys (that authorizes applications to request tokens) are defined in the database (they must be added manually for the moment).
| Name | Status | |
|---|---|---|
|
|
lead | rf.dillit <<ta>> cireme |
Copyright (c) 2012 Emeric Kasbarian
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| Version | License | API | Released |
|---|---|---|---|
| 0.0.4beta | MIT license | 0.0.4beta | 13/04/2012 |
| 0.0.3beta | MIT license | 0.0.3beta | 13/04/2012 |
The tiDoctrineOAuthServerPlugin provides the basis for making an OAuth server. It provides each requested URL in the OAuth protocol 1.0a (request token, user authorization and access token). It provides the pages to authorize/refuse the access to the connected sfDoctrineGuardUser. If the user is not connected, he is automatically redirected to a login page. The authorized consumer keys (that authorizes applications to request tokens) are defined in the database (they must be added manually for the moment).
Install the plugin (via a package)
symfony plugin:install tiDoctrineOAuthServerPlugin
Install the plugin (via a git checkout)
git clone git://github.com/Tillid/tiDoctrineOAuthServerPlugin.git plugins/tiDoctrineOAuthServerPlugin
Activate the plugin in the config/ProjectConfiguration.class.php
class ProjectConfiguration extends sfProjectConfiguration { public function setup() { $this->enablePlugins(array( 'sfDoctrinePlugin', 'sfDoctrineOAuthServerPlugin', '...' )); } }
Rebuild your model, update you database tables by starting from scratch and load the fixtures (it will delete all the existing tables, then re-create them)
symfony doctrine:build --all --and-load --no-confirmation
Enable the tiOAuthServer module in your settings.yml
all:
.settings:
enabled_modules: [default, tiOAuthServer]
Clear your cache
symfony cc
The tiDoctrineOAuthServerPlugin provides three routes, for each step of the OAuth connexion protocol :
ti_oauth_request_token: via /request_token, used to retrieve the request token
ti_oauth_authorize: via /authorize, used to allow the user to authorize (or not) the access to all the user data
ti_oauth_access_token: via /access_token, used to retrieve the access token, that must be stored in the client application.
You can use a plugin like sfDoctrineOAuthPlugin to manage the client-side connexion.
Then, all you have to do is to create actions and protect them like that :
public function executeMyPostTicket(sfWebRequest $request) { try { $req = OAuthRequest::from_request(); list($consumer, $token) = tiOAuthServer::getInstance()->verify_request($req); $access_token = Doctrine_Core::getTable('OAuthServerAccessTokens')->createQuery('a') ->where('a.id = ?', $token) ->fetchOne(); if (!$access_token) throw new OAuthException(); // Write your code here echo $access_token->getIdUser(); return sfView::NONE; } catch( OAuthException $e ) { // The request wasn't valid! header('WWW-Authenticate: OAuth realm="http://localhost/"'); echo 'I\'m afraid I can\'t let you do that Dave.'; die; } }
