Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event dispatch for easier customization #114

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ php:
- 7.0
- 7.1
- 7.2
- 7.3

install:
- composer install
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ This version of oauth2-php is a fork of https://github.com/quizlet/oauth2-php wi
- Uses [HttpFoundation](https://github.com/symfony/HttpFoundation) Request and Response for input/output
- More testable design
- Better test coverage

- Event dispatch for easier customization
- Use the *oauth2.pre.grant.authorization* event to modify the autorization parameters
- Use the *oauth2.generate.auth_code* event to customize the access token generation
- Use the *oauth2.post.grant.authorization* event to modify the autorization response variables
- Use the *oauth2.pre.grant.access_token* event to modify the grant access token parameters
- Use the *oauth2.generate.access_token* event to customize the access token generation
- Use the *oauth2.generate.refresh_token* event to customize the refresh token generation
- Use the *oauth2.post.grant.access_token* event to modify the grant access token response variables

(pull request is pending)

https://github.com/quizlet/oauth2-php is a fork of http://code.google.com/p/oauth2-php/ updated against OAuth2.0 draft
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

"require": {
"php": "^5.5.9|^7.0.8|^7.1.3|^7.2.5",
"symfony/http-foundation": "~3.0|~4.0|~5.0"
"symfony/http-foundation": "~3.0|~4.0|~5.0",
"symfony/event-dispatcher": "~3.0|~4.0|~5.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8 || ^5.0"
Expand Down
126 changes: 126 additions & 0 deletions lib/Event/GenerateTokenEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php
namespace OAuth2\Event;

use Symfony\Component\EventDispatcher\GenericEvent;
use OAuth2\Model\IOAuth2Client;

/**
* Event data for token generation
*
* @author Charles J. C Elling <tlakomistli.anakmosatlani@gmail.com>
*
*/
class GenerateTokenEvent extends GenericEvent
{
/**
* Client requesting the token
*
* @var IOAuth2Client $client
*/
protected $client;

/**
*
*
* @var mixed $data
*/
protected $data;

/**
* Scope of the token
*
* @var string|null
*/
protected $scope = null;

/**
* Token lifetime
*
* @var int|null
*/
protected $token_lifetime = null;

/**
* Generated token
*
* @var string|null
*/
protected $token = null;

/**
*
* @param IOAuth2Client $client
* @param mixed $data
* @param string|null $scope
* @param int|null $token_lifetime
*/
public function __construct(IOAuth2Client $client, $data, $scope = null, $token_lifetime = null)
{
parent::__construct();
$this->client = $client;
$this->data = $data;
$this->scope = $scope;
$this->token_lifetime = $token_lifetime;
}

/**
*
* @return IOAuth2Client
*/
public function getClient()
{
return $this->client;
}

/**
*
* @return mixed
*/
public function getData()
{
return $this->data;
}


/**
*
* @return string|null
*/
public function getScope()
{
return $this->scope;
}

/**
*
* @return number|null
*/
public function getToken_Lifetime()
{
return $this->token_lifetime;
}

/**
*
* @return string|null
*/
public function getToken()
{
return $this->token;
}

/**
*
* @param string|null $token
* @return self
*/
public function setToken($token)
{
$this->token = $token;
return $this;
}



}

57 changes: 57 additions & 0 deletions lib/Event/PostGrantAccessTokenEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
namespace OAuth2\Event;

use Symfony\Component\HttpFoundation\Request;
use OAuth2\Model\OAuth2Client;

/**
* Post grant access token event data
*
* @author Charles J. C Elling <tlakomistli.anakmosatlani@gmail.com>
*
*/
class PostGrantAccessTokenEvent extends PreGrantAccessTokenEvent
{
/**
* Access token variables
*
* @var array
*/
protected $token;

/**
*
* @param array $token
* @param Request $request
* @param array $data
* @param array $input
* @param OAuth2Client $client
*/
public function __construct(array $token, Request $request, array $data=[], $input=[], OAuth2Client $client = null)
{
parent::__construct($request,$data, $input, $client);
$this->token = $token;
}

/**
* Get the access token variables
*
* @return array
*/
public function getToken()
{
return $this->token;
}

/**
* Set the access token variables
*
* @param array $token
* @return self
*/
public function setToken(array $token)
{
$this->token = $token;
return $this;
}
}
56 changes: 56 additions & 0 deletions lib/Event/PostGrantAuthorizationEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
namespace OAuth2\Event;

use Symfony\Component\HttpFoundation\Request;

/**
* Post grant authorization event data
*
* @author Charles J. C Elling <tlakomistli.anakmosatlani@gmail.com>
*
*/
class PostGrantAuthorizationEvent extends PreGrantAuthorizationEvent
{

/**
* Result parameters
*
* @var array
*/
protected $result;

/**
*
* @param array $result
* @param Request $request
* @param array $params
* @param boolean $isAuthorized
*/
public function __construct(array $result, Request $request, array $params, $isAuthorized)
{
parent::__construct($request, $params, $isAuthorized);
$this->result = $result;
}

/**
* Get the result parameters
*
* @return mixed
*/
public function getResult()
{
return $this->result;
}

/**
* Set the result parameters
*
* @param array $result
* @return self
*/
public function setResult(array $result)
{
$this->result = $result;
return $this;
}
}