Skip to content

Commit 1f5caae

Browse files
committed
Add event dispatch for easier customization
1 parent a41fef6 commit 1f5caae

12 files changed

+838
-11
lines changed

Diff for: README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ This version of oauth2-php is a fork of https://github.com/quizlet/oauth2-php wi
1515
- Uses [HttpFoundation](https://github.com/symfony/HttpFoundation) Request and Response for input/output
1616
- More testable design
1717
- Better test coverage
18-
18+
- Event dispatch for easier customization
19+
- Use the *oauth2.pre.grant.authorization* event to modify the autorization parameters
20+
- Use the *oauth2.generate.auth_code* event to customize the access token generation
21+
- Use the *oauth2.post.grant.authorization* event to modify the autorization response variables
22+
- Use the *oauth2.pre.grant.access_token* event to modify the grant access token parameters
23+
- Use the *oauth2.generate.access_token* event to customize the access token generation
24+
- Use the *oauth2.generate.refresh_token* event to customize the refresh token generation
25+
- Use the *oauth2.post.grant.access_token* event to modify the grant access token response variables
26+
1927
(pull request is pending)
2028

2129
https://github.com/quizlet/oauth2-php is a fork of http://code.google.com/p/oauth2-php/ updated against OAuth2.0 draft

Diff for: composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
],
1818
"require": {
1919
"php": "^5.5.9|>=7.0.8",
20-
"symfony/http-foundation": "~3.0|~4.0"
20+
"symfony/http-foundation": "~3.0|~4.0",
21+
"symfony/event-dispatcher": "~3.0|~4.0"
2122
},
2223
"require-dev": {
2324
"phpunit/phpunit": "~4.0"

Diff for: lib/Event/GenerateTokenEvent.php

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
namespace OAuth2\Event;
3+
4+
use Symfony\Component\EventDispatcher\Event;
5+
use OAuth2\Model\IOAuth2Client;
6+
7+
/**
8+
* Event data for token generation
9+
*
10+
* @author Charles J. C Elling <[email protected]>
11+
*
12+
*/
13+
class GenerateTokenEvent extends Event
14+
{
15+
/**
16+
* Client requesting the token
17+
*
18+
* @var IOAuth2Client $client
19+
*/
20+
protected $client;
21+
22+
/**
23+
*
24+
*
25+
* @var mixed $data
26+
*/
27+
protected $data;
28+
29+
/**
30+
* Scope of the token
31+
*
32+
* @var string|null
33+
*/
34+
protected $scope = null;
35+
36+
/**
37+
* Token lifetime
38+
*
39+
* @var int|null
40+
*/
41+
protected $token_lifetime = null;
42+
43+
/**
44+
* Generated token
45+
*
46+
* @var string|null
47+
*/
48+
protected $token = null;
49+
50+
/**
51+
*
52+
* @param IOAuth2Client $client
53+
* @param mixed $data
54+
* @param string|null $scope
55+
* @param int|null $token_lifetime
56+
*/
57+
public function __construct(IOAuth2Client $client, $data, $scope = null, $token_lifetime = null)
58+
{
59+
$this->client = $client;
60+
$this->data = $data;
61+
$this->scope = $scope;
62+
$this->token_lifetime = $token_lifetime;
63+
}
64+
65+
/**
66+
*
67+
* @return IOAuth2Client
68+
*/
69+
public function getClient()
70+
{
71+
return $this->client;
72+
}
73+
74+
/**
75+
*
76+
* @return mixed
77+
*/
78+
public function getData()
79+
{
80+
return $this->data;
81+
}
82+
83+
84+
/**
85+
*
86+
* @return string|null
87+
*/
88+
public function getScope()
89+
{
90+
return $this->scope;
91+
}
92+
93+
/**
94+
*
95+
* @return number|null
96+
*/
97+
public function getToken_Lifetime()
98+
{
99+
return $this->token_lifetime;
100+
}
101+
102+
/**
103+
*
104+
* @return string|null
105+
*/
106+
public function getToken()
107+
{
108+
return $this->token;
109+
}
110+
111+
/**
112+
*
113+
* @param string|null $token
114+
* @return self
115+
*/
116+
public function setToken($token)
117+
{
118+
$this->token = $token;
119+
return $this;
120+
}
121+
122+
123+
124+
}
125+

Diff for: lib/Event/PostGrantAccessTokenEvent.php

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
namespace OAuth2\Event;
3+
4+
use Symfony\Component\HttpFoundation\Request;
5+
use OAuth2\Model\OAuth2Client;
6+
7+
/**
8+
* Post grant access token event data
9+
*
10+
* @author Charles J. C Elling <[email protected]>
11+
*
12+
*/
13+
class PostGrantAccessTokenEvent extends PreGrantAccessTokenEvent
14+
{
15+
/**
16+
* Access token variables
17+
*
18+
* @var array
19+
*/
20+
protected $token;
21+
22+
/**
23+
*
24+
* @param array $token
25+
* @param Request $request
26+
* @param array $data
27+
* @param array $input
28+
* @param OAuth2Client $client
29+
*/
30+
public function __construct(array $token, Request $request, array $data=[], $input=[], OAuth2Client $client = null)
31+
{
32+
parent::__construct($request,$data, $input, $client);
33+
$this->token = $token;
34+
}
35+
36+
/**
37+
* Get the access token variables
38+
*
39+
* @return array
40+
*/
41+
public function getToken()
42+
{
43+
return $this->token;
44+
}
45+
46+
/**
47+
* Set the access token variables
48+
*
49+
* @param array $token
50+
* @return self
51+
*/
52+
public function setToken(array $token)
53+
{
54+
$this->token = $token;
55+
return $this;
56+
}
57+
}

Diff for: lib/Event/PostGrantAuthorizationEvent.php

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
namespace OAuth2\Event;
3+
4+
use Symfony\Component\HttpFoundation\Request;
5+
6+
/**
7+
* Post grant authorization event data
8+
*
9+
* @author Charles J. C Elling <[email protected]>
10+
*
11+
*/
12+
class PostGrantAuthorizationEvent extends PreGrantAuthorizationEvent
13+
{
14+
15+
/**
16+
* Result parameters
17+
*
18+
* @var array
19+
*/
20+
protected $result;
21+
22+
/**
23+
*
24+
* @param array $result
25+
* @param Request $request
26+
* @param array $params
27+
* @param boolean $isAuthorized
28+
*/
29+
public function __construct(array $result, Request $request, array $params, $isAuthorized)
30+
{
31+
parent::__construct($request, $params, $isAuthorized);
32+
$this->result = $result;
33+
}
34+
35+
/**
36+
* Get the result parameters
37+
*
38+
* @return mixed
39+
*/
40+
public function getResult()
41+
{
42+
return $this->result;
43+
}
44+
45+
/**
46+
* Set the result parameters
47+
*
48+
* @param array $result
49+
* @return self
50+
*/
51+
public function setResult(array $result)
52+
{
53+
$this->result = $result;
54+
return $this;
55+
}
56+
}

0 commit comments

Comments
 (0)