codemix / restyii

A RESTful extension for Yii.
15 stars 10 forks source link

Allow to inject authentication headers #27

Closed mikehaertl closed 11 years ago

mikehaertl commented 11 years ago

We should provide a method to inject authentication methods.

I'd suggest to expose a event onBeforeRequest, that receives the Guzzle request object in $event->request. This way we can easily integrate OAuth2Yii:

'components' => array(
    'restyii' => array(
        'onBeforeRequest' => function($event) {
            if($token = Yii::app()->oauth2->getProvider('abc')->accessToken)!==null) {
                $event->request->addHeader('Authorization: Bearer '.$token);
            }
         },