Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
Added Introspect and Revoke endpoints
Browse files Browse the repository at this point in the history
Bumped version number
  • Loading branch information
ventayol committed May 4, 2017
1 parent 156daae commit 2770631
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ php composer.phar require --prefer-dist mobilejazz/yii2-oauth2-server "*"
or add

```json
"mobilejazz/yii2-oauth2-server": "~2.0"
"mobilejazz/yii2-oauth2-server": "~2.1"
```

to the require section of your composer.json.
Expand All @@ -27,7 +27,6 @@ To use this extension, simply add the following code in your application config
```php
'oauth2' => [
'class' => 'mobilejazz\yii2\oauth2server\Module',
'class' => 'filsh\yii2\oauth2server\Module',
'tokenParamName' => 'accessToken',
'tokenAccessLifetime' => 3600 * 24,
'storageMap' => [
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "yii2-extension",
"license": "MIT",
"support": {
"email": "mtorruella@mobilejazz.com",
"email": "info@mobilejazz.com",
"source": "https://github.com/mobilejazz/yii2-oauth2-server"
},
"authors": [
Expand All @@ -15,18 +15,18 @@
"email": "[email protected]"
},
{
"name": "MobileJazz",
"email": "mtorruella@mobilejazz.com"
"name": "Mobile Jazz",
"email": "info@mobilejazz.com"
}
],
"require": {
"yiisoft/yii2": "*",
"bshaffer/oauth2-server-php": "v1.6"
"bshaffer/oauth2-server-php": "v1.9"
},
"autoload": {
"psr-4": {
"mobilejazz\\yii2\\oauth2server\\": ""
}
},
"version":"2.0.2"
"version":"2.1.0"
}
51 changes: 50 additions & 1 deletion controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace mobilejazz\yii2\oauth2server\controllers;

use mobilejazz\yii2\oauth2server\filters\auth\CompositeAuth;
use mobilejazz\yii2\oauth2server\models\OauthAccessTokens;
use Yii;
use yii\helpers\ArrayHelper;
use mobilejazz\yii2\oauth2server\filters\ErrorToExceptionFilter;
Expand All @@ -13,11 +15,18 @@ class DefaultController extends \yii\rest\Controller
*/
public function behaviors()
{
return ArrayHelper::merge(parent::behaviors(), [
$behaviors = ArrayHelper::merge(parent::behaviors(), [
'exceptionFilter' => [
'class' => ErrorToExceptionFilter::className()
],
]);

$behaviors['authenticator'] = [
'class' => CompositeAuth::className(),
'except' => ['token'],
];

return $behaviors;
}

public function actionToken()
Expand All @@ -33,4 +42,44 @@ public function actionToken()

return $response->getParameters();
}

public function actionRevoke()
{
$server = $this->module->getServer();
$request = $this->module->getRequest();
$response = $server->handleRevokeRequest($request);

return $response->getParameters();
}


public function actionIntrospect()
{
if (!Yii::$app->request->post('token'))
{
$message = Yii::t('oauth2server', 'Missing parameter: "token" is required');
if($message === null) {
$message = Yii::t('yii', 'An internal server error occurred.');
}
throw new \yii\web\HttpException(400, $message);

}

$response["active"] = false;

$token = OauthAccessTokens::findOne(["access_token"=>Yii::$app->request->post('token')]);
if ($token)
{
$expires = strtotime($token->expires);
if (time() < $expires)
$response["active"] = true;
$response["scope"] = $token->scope;
$response["user_id"] = $token->user_id;
$response["client_id"] = $token->client_id;
$response["exp"] = $expires;
}

return $response;
}

}
2 changes: 1 addition & 1 deletion messages/en/oauth2server.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'This application requires you specify a scope parameter' => 'This application requires you specify a scope parameter',
'This client is invalid or must authenticate using a client secret' => 'This client is invalid or must authenticate using a client secret',
'Unable to retrieve user information' => 'Unable to retrieve user information',
'Unable to retrieve user information' => 'Unable to retrieve user information',
'When putting the token in the body, the method must be POST' => 'When putting the token in the body, the method must be POST',
'you must set the user_id on the array returned by getUserDetails' => 'you must set the user_id on the array returned by getUserDetails',
'Missing parameter: "token" is required' => 'Missing parameter: "token" is required',
];

0 comments on commit 2770631

Please sign in to comment.