Compare commits

...

706 Commits
1.0.5 ... 4.0.0

Author SHA1 Message Date
Alex Bilbie
73917a0327 Merge branch 'release/4.0.0' 2014-11-08 17:24:09 +00:00
Alex Bilbie
ad86f71b34 Removed year 2014-11-08 17:22:50 +00:00
Alex Bilbie
d58877131d Removed fizzfuzz for now 2014-11-08 17:22:46 +00:00
Alex Bilbie
846b4d1652 Updated changelog 2014-11-08 17:21:49 +00:00
Alex Bilbie
583c21e7db Updated unit tests 2014-11-08 17:16:17 +00:00
Alex Bilbie
7dc5a8090f Remove old test 2014-11-08 17:03:20 +00:00
Alex Bilbie
6b29b7450e If the client should redirect during AuthCodeGrant authorisation then provide a redirect uri 2014-11-08 17:03:15 +00:00
Alex Bilbie
b9debaab26 Fix #231 2014-11-08 16:44:39 +00:00
Alex Bilbie
856051bfb3 Fix #232 2014-11-08 16:20:13 +00:00
Alex Bilbie
fa55a791e7 Updated http-foundation. Fixes #241 2014-11-07 16:53:56 +00:00
Alex Bilbie
5c5d7d5340 Removed old Travis before_script commands 2014-11-07 02:31:54 +00:00
Alex Bilbie
a2a768b6e6 All interfaces extend StorageInterface 2014-11-07 02:31:37 +00:00
Alex Bilbie
4bbbc72035 Added StorageInterface 2014-11-07 02:29:04 +00:00
Alex Bilbie
3815355489 Removed generic getStorage method and replaced with distinct calls to getters 2014-11-07 02:20:06 +00:00
Alex Bilbie
9bb7af6f83 More docblock fixes 2014-11-07 01:48:23 +00:00
Alex Bilbie
d16b1b72ba Docblock fix 2014-11-07 01:36:17 +00:00
Alex Bilbie
e37289231d Removed dead code 2014-11-07 01:36:12 +00:00
Alex Bilbie
1c2ec943e9 Missing parameter 2014-11-07 01:35:59 +00:00
Alex Bilbie
17dfc897b4 Docfix 2014-11-07 01:30:54 +00:00
Alex Bilbie
7586e62da1 Dead code 2014-11-07 01:30:50 +00:00
Alex Bilbie
a1c3746a5a Another docblock fix 2014-11-07 01:26:42 +00:00
Alex Bilbie
d23dc4d247 Docblock fixes 2014-11-07 01:25:13 +00:00
Alex Bilbie
293bc52972 Code declared in interface, not needed 2014-11-07 01:25:04 +00:00
Alex Bilbie
11ab167376 Docblock fix 2014-11-07 01:20:05 +00:00
Alex Bilbie
f290de6dfc Docblock fixes 2014-11-07 01:17:04 +00:00
Alex Bilbie
d260167155 Docblock fixes 2014-11-07 01:13:21 +00:00
Alex Bilbie
3f114dc5e3 Exclude example dirs 2014-11-07 01:08:05 +00:00
Alex Bilbie
fedd10b5ed Docblock fix 2014-11-07 01:07:55 +00:00
Alex Bilbie
746cd4ab7d Namespace fix 2014-11-07 01:07:47 +00:00
Alex Bilbie
5848c0d920 Failure is not an option anymore with hhvm 2014-11-07 00:57:29 +00:00
Alex Bilbie
db7c42cc91 Fixed broken tests 2014-11-07 00:55:38 +00:00
Alex Bilbie
f01cf7ef2f Merge branch 'develop' of github.com:thephpleague/oauth2-server into develop 2014-11-07 00:46:09 +00:00
Alex Bilbie
61f8195edd Docblock fixes 2014-11-07 00:46:02 +00:00
Alex Bilbie
c38d20b163 Ignore certain paths in Scrutenizer 2014-11-07 00:45:42 +00:00
Alex Bilbie
fbf1535db1 Renamed Adapter to AbstractStorage because it isn't actually an adapter 2014-11-07 00:45:25 +00:00
Alex Bilbie
90ce1932cc Merge pull request #240 from leevigraham/patch-1
Associate the $client with $session.
2014-11-06 18:29:49 -05:00
Leevi Graham
b60693c5d6 Associate the $client with $session. 2014-11-07 07:50:22 +11:00
Alex Bilbie
736a7b95eb Merge pull request #235 from tompedals/patch-1
Update ScopeStorage::get method signature to match the interface
2014-11-03 06:05:02 -05:00
Alex Bilbie
b50f7ce04e Merge pull request #236 from gabrielsch/patch-1
Fixing docblock indentation
2014-11-03 06:02:49 -05:00
Gabriel Schmitt
b2514e35f4 Fixing docblock indentation 2014-10-28 16:10:18 -02:00
tompedals
bc314f7c52 Update ScopeStorage::get method signature to match the interface 2014-10-25 22:43:56 +01:00
Alex Bilbie
72e3ddad1e Updated dependencies 2014-10-11 23:38:59 +01:00
Alex Bilbie
6333a975f8 Update README.md 2014-10-03 14:42:01 +01:00
Alex Bilbie
44ab7b6135 Updated league/event to 1.0.* 2014-10-03 14:26:55 +01:00
Alex Bilbie
bfcccb2671 Merge pull request #215 from sumeko/patch-1
Update AbstractServer.php
2014-10-01 22:26:57 +01:00
Alex Bilbie
3183828c1c Added _site to .gitignore 2014-10-01 00:16:46 +01:00
Alex Bilbie
6be7c119db Renamed Github user 2014-10-01 00:16:26 +01:00
Alex Bilbie
0f13ff188a Renamed method to getRequest 2014-10-01 00:14:16 +01:00
Alex Bilbie
099f009b39 Ignore tests dir 2014-10-01 00:01:22 +01:00
Alex Bilbie
136edf16c5 Fix #213 2014-09-30 23:55:21 +01:00
Alex Bilbie
62d658524b Expecting coverage on 3 runs not 4 2014-09-30 23:24:26 +01:00
Alex Bilbie
5b9f9a500d Renamed scrutinizer.yml to .scrutinizer.yml 2014-09-30 23:20:52 +01:00
Alex Bilbie
05d33f7020 Updated README 2014-09-30 23:12:43 +01:00
Alex Bilbie
d9bf0e5899 Updated .travis.yml 2014-09-30 23:07:00 +01:00
Alex Bilbie
63be2684d3 Added scrutinizer.yml 2014-09-30 22:57:35 +01:00
Alex Bilbie
536ef3244d Inject the session into the token type 2014-09-30 22:28:49 +01:00
Alex Bilbie
a3f5d20592 Changed method names to be clearer that we're setting params 2014-09-30 22:28:38 +01:00
Alex Bilbie
1e3a192920 Inject server into tokentype 2014-09-30 22:26:34 +01:00
Alex Bilbie
b68a5c2abb Added authentication failure events 2014-09-30 22:16:34 +01:00
Alex Bilbie
643c3493c4 Merge pull request #211 from pulkitjalan/grant-access-token
support grant specific access token ttl
2014-09-29 09:45:09 +01:00
Sum
64ca2a4b49 Update AbstractServer.php 2014-09-22 12:56:15 +07:00
pulkit
1ff3d1adda support grant specific access token ttl 2014-09-11 13:58:01 +01:00
Alex Bilbie
9e2a6ed238 If there are no scopes to format then just return an empty array 2014-09-10 17:22:01 +01:00
Alex Bilbie
be51cdf9b1 Fixed spelling mistake 2014-09-09 13:36:20 +01:00
Alex Bilbie
13cd0cacdf Merge pull request #204 from ushahidi/missing-token-message
Add a new "missing_token" exception message to Resource server
2014-09-08 22:01:33 +01:00
Alex Bilbie
67587e450b Merge pull request #207 from thvranken/develop
Session ID returned correctly
2014-09-06 18:44:04 +01:00
Thomas Vranken
6ce190d33b Session ID returned correctly
Session ID was not returned correctly after creating a session.
2014-09-06 17:53:02 +02:00
Alex Bilbie
f923e89c3d Merge pull request #206 from GrahamCampbell/patch-1
Update .travis.yml
2014-08-31 20:07:40 +01:00
Graham Campbell
31c3cbe593 Update .travis.yml 2014-08-31 16:49:10 +01:00
Woody Gilk
f03e4a9e37 Add a new "missing_token" exception message to Resource server 2014-08-26 11:42:41 -05:00
Alex Bilbie
7d8989a8cd Fix #202 2014-08-18 16:47:36 +01:00
Alex Bilbie
b9e12a7fec Removed length 2014-08-16 10:57:08 +02:00
Alex Bilbie
d32cea1988 Removed tests that had crept in 2014-08-16 10:53:32 +02:00
Alex Bilbie
ce1a650ae1 Updated .gitignore 2014-08-16 10:39:14 +02:00
Alex Bilbie
01e823427f Updated homepage 2014-08-16 10:24:53 +02:00
Alex Bilbie
da92410ecb Merge pull request #196 from barryvdh/patch-1
Remove links to wiki
2014-08-13 08:29:34 +02:00
Alex Bilbie
d65bd112a9 Merge pull request #198 from GrahamCampbell/patch-2
Imoroved some version coinstraints
2014-08-10 11:16:17 +01:00
Graham Campbell
2ca3df60be Imoroved some version coinstraints 2014-08-10 11:15:41 +01:00
Alex Bilbie
23303905a8 Merge pull request #197 from GrahamCampbell/patch-1
Update composer.json
2014-08-10 11:15:18 +01:00
Graham Campbell
0b8e69f0d0 Update composer.json 2014-08-10 11:11:15 +01:00
Barry vd. Heuvel
a448f2167b Remove links to wiki
They don't work anymore. Not sure where they went?
2014-08-08 10:57:30 +02:00
Alex Bilbie
3494b65be0 Old mysql.sql file shouldn't be in codebase 2014-08-07 11:23:58 +01:00
Alex Bilbie
9ff841aa6f Update README.md 2014-08-06 18:16:16 +01:00
Alex Bilbie
dc4136a6f5 Fix JSON 2014-08-06 18:05:00 +01:00
Alex Bilbie
7e4317cf54 Added branch alias for 4.0.x-dev
Fixes #194
2014-08-06 18:02:47 +01:00
Alex Bilbie
522c7478c7 Fix #169 2014-08-06 09:53:47 +01:00
Alex Bilbie
130d42c85e Removed some files which shouldn't be there 2014-08-06 09:37:19 +01:00
Alex Bilbie
0433791bc6 Accidentally merged wrong version of file 2014-08-06 09:29:32 +01:00
Alex Bilbie
79f15f3855 Merge branch 'v4.0.0-WIP' into develop
Conflicts:
	.gitignore
	.travis.yml
	README.md
	composer.json
	phpunit.xml
	sql/mysql.sql
	src/League/OAuth2/Server/Grant/RefreshToken.php
	src/League/OAuth2/Server/Resource.php
	src/League/OAuth2/Server/Storage/SessionInterface.php
	src/League/OAuth2/Server/Util/Request.php
	src/Util/KeyAlgorithm/DefaultAlgorithm.php
	tests/resource/ResourceServerTest.php
	tests/util/RedirectUriTest.php
	tests/util/RequestTest.php
	tests/util/SecureKeyTest.php
2014-08-06 09:21:56 +01:00
Alex Bilbie
0754b9ec75 Merge branch 'v4.0.0-relational-example' into v4.0.0-WIP 2014-08-06 09:02:54 +01:00
Alex Bilbie
6568ca5790 Removing fizzfuzz for now until I can work out what the hell is wrong with it 2014-08-06 08:59:48 +01:00
Alex Bilbie
30abfeefbf Tried removed --prefer-dist 2014-08-06 08:56:11 +01:00
Alex Bilbie
1483ce936b Fizzfuzz is lowercase now 2014-08-06 08:51:53 +01:00
Alex Bilbie
661086d3b8 Removed coveralls and phpcs testing 2014-08-06 08:47:28 +01:00
Alex Bilbie
ca1b977786 Added another test 2014-08-06 08:43:25 +01:00
Alex Bilbie
7525fc0884 Bug fixes 2014-08-06 08:43:08 +01:00
Alex Bilbie
06d5b343d6 Fixed incorrect exception status code and error type 2014-08-06 08:42:58 +01:00
Alex Bilbie
07a42f6f43 Added setAccessTokenId method 2014-08-06 08:42:42 +01:00
Alex Bilbie
8be92d413d Implemented final storage methods 2014-08-06 08:42:15 +01:00
Alex Bilbie
71ac21b70e Removed unnecessary methods 2014-08-06 08:41:50 +01:00
Alex Bilbie
12ab753f15 Updated associateScope method 2014-08-04 20:15:31 +01:00
Alex Bilbie
684a8a269e Updated examples 2014-08-04 18:54:01 +01:00
Alex Bilbie
cd60c2961f Removed session ID 2014-08-04 18:53:44 +01:00
Alex Bilbie
f046a024e4 Updated .travis.yml to use FizzFuzz 2014-08-04 15:28:04 +01:00
Alex Bilbie
90e585ba9a Removed codeception file 2014-08-04 15:27:33 +01:00
Alex Bilbie
7e0e337134 Fixed grant password fuzz test 2014-08-04 15:27:08 +01:00
Alex Bilbie
324da27ea9 Added verify credentials callback 2014-08-04 15:26:56 +01:00
Alex Bilbie
0a260f0c8c Commented out refresh token for now 2014-08-04 15:26:47 +01:00
Alex Bilbie
1a4cc3b750 Return password 2014-08-04 15:26:26 +01:00
Alex Bilbie
b3da61822e Updated example code examples 2014-08-04 15:19:17 +01:00
Alex Bilbie
69208fe0ac Added more fizzfuzz tests 2014-08-04 15:18:55 +01:00
Alex Bilbie
806838b8e4 So long codeception, you suck 2014-08-04 15:18:44 +01:00
Alex Bilbie
2637af87ec Merge branch 'v4.0.0-relational-example' of github.com:thephpleague/oauth2-server into v4.0.0-relational-example 2014-08-04 10:54:50 +01:00
Alex Bilbie
ac3e787278 Updated api.php code 2014-08-04 09:12:43 +01:00
Alex Bilbie
ffe59f5a5f Added Fuzz tests 2014-08-04 09:12:00 +01:00
Alex Bilbie
7b9899c46b Removed line break in error messages 2014-08-04 09:11:53 +01:00
Alex Bilbie
c29340ae27 Added FizzFuzz requirement 2014-08-04 09:11:19 +01:00
Alex Bilbie
ad12a088cf Renamed auth to authServer 2014-07-28 13:56:00 +01:00
Alex Bilbie
0810be9ce4 Merge branch 'v4.0.0-relational-example' of github.com:thephpleague/oauth2-server into v4.0.0-relational-example 2014-07-28 13:54:46 +01:00
Alex Bilbie
7f75246619 Added auth functional tests 2014-07-27 22:51:00 +01:00
Alex Bilbie
5ec1bf8a88 Renamed auth.php to authcode_grant.php 2014-07-27 22:50:41 +01:00
Alex Bilbie
443d72ee24 Ignore .paw file 2014-07-27 17:18:00 +01:00
Alex Bilbie
861da5fee9 Updated .gitignore 2014-07-27 17:17:47 +01:00
Alex Bilbie
f3fc921212 Added redirect URI property 2014-07-27 17:16:46 +01:00
Alex Bilbie
54e6bbd4a6 expires isn't part of the spec 2014-07-27 17:15:55 +01:00
Alex Bilbie
0d6c4f65b9 Store the redirect URI too 2014-07-27 17:14:50 +01:00
Alex Bilbie
cfd1c93a46 Updated response code 2014-07-27 17:14:35 +01:00
Alex Bilbie
29b09227ac Implemented more methods 2014-07-27 17:12:03 +01:00
Alex Bilbie
6cb5863b81 Added missing column 2014-07-27 17:11:27 +01:00
Alex Bilbie
2f14f6b391 Version bump 2014-07-23 16:13:50 +01:00
Alex Bilbie
94369abd60 Merge branch 'release/3.2.2'
Conflicts:
	composer.json
2014-07-23 16:10:02 +01:00
Alex Bilbie
45edac4216 Version bump 2014-07-23 16:08:50 +01:00
Alex Bilbie
5bdfc9908a Updated changelog 2014-07-23 16:08:33 +01:00
Alex Bilbie
1890d71838 Merge branch 'develop' of github.com:thephpleague/oauth2-server into develop 2014-07-23 16:05:42 +01:00
Alex Bilbie
00d5fb5834 Merge pull request #188 from ushahidi/fix-http-headers-util-request
Fix Resource server Request HTTP header access
2014-07-23 15:58:24 +01:00
Robbie Mackay
49b776c495 In Resource::getExceptionHttpHeaders() use Request::BuildFromGlobals 2014-07-23 07:48:05 -07:00
Woody Gilk
31e03c2d36 Fix broken http header extraction in Util\Request 2014-07-23 07:47:29 -07:00
Alex Bilbie
395ee3bf49 Moved existing functional tests into resource server folder 2014-07-22 12:15:41 +01:00
Alex Bilbie
6f85bcbbf1 Merge branch 'develop' of github.com:thephpleague/oauth2-server into develop 2014-07-22 11:45:54 +01:00
Alex Bilbie
47a5c1ba08 100% unit test coverage 2014-07-22 11:45:19 +01:00
Alex Bilbie
d123ba095c Dammit 2014-07-22 11:11:23 +01:00
Alex Bilbie
bfad6c7e28 Fix path for codeception logs 2014-07-22 11:07:29 +01:00
Alex Bilbie
7067a35d3a Fixed broken example tests 2014-07-22 10:58:15 +01:00
Alex Bilbie
f40ada9ac7 Moved unit tests 2014-07-22 09:23:00 +01:00
Alex Bilbie
ca61d5d4e0 Moved functional tests 2014-07-22 09:21:01 +01:00
Phil Sturgeon
7771bc04ec Merge pull request #186 from ushahidi/resource-server-correct-http-error
Send HTTP 401 for invalid_token, rather than insufficient_scope
2014-07-15 15:39:28 +01:00
Alex Bilbie
20032f33a2 More tests 2014-07-12 12:07:46 +01:00
Alex Bilbie
b694cca743 Fix broken test 2014-07-12 08:58:18 +01:00
Alex Bilbie
1e78f62823 Lotsa bug fixes and updates 2014-07-11 18:27:03 +01:00
Alex Bilbie
c6bc1b0cfc Updated tests 2014-07-11 18:19:10 +01:00
Alex Bilbie
48dea185d8 Added getEventEmitter method to abstractserver 2014-07-11 18:18:41 +01:00
Woody Gilk
f34dd4a0cb 401 status is for invalid_token, not insufficient_scope 2014-07-11 11:59:18 -05:00
Alex Bilbie
4362f17fd6 Update composer.json 2014-07-11 16:21:40 +01:00
Alex Bilbie
6d81c1e57e Merge branch 'develop' 2014-07-11 15:27:19 +01:00
Alex Bilbie
1a88d3f4c5 Ignore build files 2014-07-11 15:21:32 +01:00
Alex Bilbie
0a3215be8e Added entity trate 2014-07-11 15:18:47 +01:00
Alex Bilbie
954f29f879 Added league/event and implemented SessionOwnerEvent 2014-07-11 15:13:28 +01:00
Alex Bilbie
4480aa3456 Merge pull request #178 from ushahidi/resource-server-errors
Resource server errors
2014-07-11 11:47:29 +01:00
Woody Gilk
44db2b295f Stop testing stdClass as an argument to hasScope, it is pointless 2014-07-10 17:02:50 -05:00
Woody Gilk
33f4f5b7ab Add $required parameter to hasScope(), triggers InsufficientScopeException 2014-07-10 17:02:16 -05:00
Woody Gilk
e61782975a Copy getExceptionType(), getExceptionMessage(), and getExceptionHttpHeaders() to Resource server 2014-07-10 17:02:16 -05:00
Woody Gilk
d7c1c50269 Throw MissingAccessTokenException in the Resource server when no token exists 2014-07-10 16:59:25 -05:00
Alex Bilbie
f2b5967f10 Merge pull request #184 from fahmiardi/basic-authentication
[4.0] Basic authentication
2014-07-06 20:07:11 +01:00
Fahmi Ardi
92779ad078 missing clientSecret variable 2014-07-03 15:03:58 +07:00
Fahmi Ardi
83c7dea1cc allowing client crendentials to be sent as Basic authentication 2014-07-03 14:58:13 +07:00
Phil Sturgeon
4486b7120f Merge pull request #177 from ushahidi/notabs
Clean up mixed tabs and spaces in test files
2014-07-02 11:40:16 +01:00
Phil Sturgeon
687e794ce3 Merge pull request #182 from acairns/develop
Use utf8_unicode_ci as default collation
2014-07-02 11:39:59 +01:00
Andrew Cairns
c7dfc42d57 Use utf8_unicode_ci as default collation 2014-06-26 15:39:35 +01:00
Alex Bilbie
33c68a2103 More updates to relational example 2014-06-23 08:20:34 +01:00
Alex Bilbie
92639fbbd6 Removed dead code 2014-06-20 14:31:17 +01:00
Alex Bilbie
9af1d2a201 100% test coverage 2014-06-20 14:29:47 +01:00
Alex Bilbie
f24d1be3e9 Merge branch 'refs/heads/v4.0.0-WIP' into v4.0.0-relational-example 2014-06-20 14:16:40 +01:00
Alex Bilbie
80802e5df4 Merge branch 'v4.0.0-WIP' of github.com:php-loep/oauth2-server into v4.0.0-WIP 2014-06-20 14:16:09 +01:00
Alex Bilbie
6aa52adb3e Fixed broken tests after rename 2014-06-20 14:16:03 +01:00
Woody Gilk
cd767c07fa Replace all tabs with 4 spaces in test files 2014-05-31 16:30:32 -05:00
Alex Bilbie
0b1edadaa7 Merge pull request #176 from mdwheele/adds-authcode-create-method
Adds create method to AuthCodeInterface
2014-05-30 10:51:01 +01:00
Dustin Wheeler
c1269a97d6 Adds create method to AuthCodeInterface. Relates to #160. 2014-05-29 19:27:45 -07:00
Alex Bilbie
5e4cd98706 Use US spelling 2014-05-23 16:26:29 +01:00
Alex Bilbie
4ebf3f838f Added initial examples 2014-05-23 16:25:09 +01:00
Alex Bilbie
11c4c93398 Added Capsule namespace 2014-05-23 16:24:45 +01:00
Alex Bilbie
cf32b5dd1b Readme update 2014-05-23 16:23:40 +01:00
Alex Bilbie
8e164f4b99 Merge pull request #171 from acairns/develop
Fixing Bearer case for consistency
2014-05-22 09:31:47 +01:00
Andrew Cairns
400d4d8f1e Fixing Bearer case for consistency 2014-05-20 17:13:29 +01:00
Phil Sturgeon
5ffbe6ac37 Delete phpunit.xml 2014-05-13 14:01:13 +01:00
Alex Bilbie
f7231b2c6a Create the codecept logs path and ensure it is writeable 2014-05-10 12:07:33 +01:00
Alex Bilbie
9a6ab4141f Download and run codeception 2014-05-10 12:00:15 +01:00
Alex Bilbie
ad5cef3b7d Ensure token works via header 2014-05-10 11:58:00 +01:00
Alex Bilbie
cd44bf8f48 Ignore codecept test logs 2014-05-10 11:54:26 +01:00
Alex Bilbie
d065549e95 First commit of API tests 2014-05-10 11:54:11 +01:00
Alex Bilbie
e43bdc837c Added ircmaxell/password-compat so PHP 5.4 doesn't error out 2014-05-09 11:15:24 +01:00
Alex Bilbie
45b971d286 Prefer-dist 2014-05-09 11:05:37 +01:00
Alex Bilbie
4096c8cd20 Move back down to root directory 2014-05-09 11:02:17 +01:00
Alex Bilbie
66febb7744 Assume we're already in examples/relational 2014-05-09 10:58:15 +01:00
Alex Bilbie
d517b4c9e1 Removed composer.lock 2014-05-09 10:57:42 +01:00
Alex Bilbie
2412f1f826 Testing travis composer install relational example, running the init command and starting local webserver 2014-05-09 10:53:33 +01:00
Alex Bilbie
c5aee31405 First commit of relational example 2014-05-09 10:46:59 +01:00
Alex Bilbie
81e9e7364b Removed example SQL 2014-05-09 10:08:00 +01:00
Alex Bilbie
11664e6d37 Added ability to cast token as a string 2014-05-09 08:16:02 +01:00
Alex Bilbie
d40ee11ef5 Scope entity is json serializable 2014-05-08 11:55:04 +01:00
Alex Bilbie
b9cedc8b93 PSR fixes 2014-05-08 11:52:51 +01:00
Alex Bilbie
58adefa7d0 Removed unnecessary parameter 2014-05-08 10:29:52 +01:00
Alex Bilbie
61f039366b Throw correct exception when access token is invalid 2014-05-08 10:29:40 +01:00
Alex Bilbie
6a0596f40b Fix #164 2014-05-07 17:30:07 +01:00
Alex Bilbie
e32f153acf Merge branch 'v4.0.0-WIP' of github.com:php-loep/oauth2-server into v4.0.0-WIP 2014-05-07 17:25:54 +01:00
Alex Bilbie
4823bfde8b Test OAuthException 2014-05-07 17:25:38 +01:00
Alex Bilbie
7e0115f0ad Test OAuthExceptin 2014-05-07 17:25:25 +01:00
Alex Bilbie
49650d1ae9 Removed Mac token type for now 2014-05-07 17:21:32 +01:00
Alex Bilbie
aae99c2487 Use token type to determine access token in header 2014-05-07 17:21:24 +01:00
Alex Bilbie
0d293e7c30 Merge branch 'refs/heads/v4.0.0-WIP' into 4.0.0-156-token-types 2014-05-07 17:11:46 +01:00
Alex Bilbie
be4799edc9 Merge pull request #167 from lucadegasperi/patch-2
updated calls to proper request methods
2014-05-07 17:11:29 +01:00
Alex Bilbie
7516606fd3 Set default token type as bearer for Resource Server 2014-05-07 17:10:52 +01:00
Alex Bilbie
e4c43faa33 Fixed tests 2014-05-07 17:09:52 +01:00
Alex Bilbie
87fbcb19af Use the correct variable 2014-05-07 17:09:45 +01:00
Alex Bilbie
6300cd5d72 Set the default token type as Bearer 2014-05-07 17:09:34 +01:00
Alex Bilbie
0b047fd8e4 Update token types 2014-05-07 17:09:19 +01:00
Luca Degasperi
07c04d15d7 updated calls to proper request methods 2014-05-06 14:30:25 +02:00
Alex Bilbie
54c2c48704 Merge pull request #166 from lucadegasperi/patch-1
Added a missing use statement
2014-05-06 12:57:14 +01:00
Luca Degasperi
95d068e818 Added a missing use statement 2014-05-06 13:52:50 +02:00
Alex Bilbie
c5ffd05eee First commit of token types 2014-05-03 14:03:02 +01:00
Alex Bilbie
b3c3676381 Removed /tests from .gitignore. Fool 2014-05-03 13:54:39 +01:00
Alex Bilbie
7356c5ad74 Renamed test classes 2014-05-03 13:54:30 +01:00
Alex Bilbie
b8e2c5a3f8 Ignore build folder [ci-skip] 2014-05-03 11:47:06 +01:00
Alex Bilbie
f7e68d6e10 Fixed auth code entity storage calls 2014-05-03 11:40:39 +01:00
Alex Bilbie
719b87a40c Added missing methods to auth code storage interface 2014-05-03 11:39:18 +01:00
Alex Bilbie
62f5766908 Removed bit deli [skip ci] 2014-05-03 11:25:37 +01:00
Alex Bilbie
f46c1d2aa4 Removed old phpunit command 2014-05-03 11:21:05 +01:00
Alex Bilbie
1f61f45f5f Fixed broken .travis.yml file 2014-05-03 11:18:09 +01:00
Alex Bilbie
8e0b525ba2 Updated phpunit.xml 2014-05-03 11:17:59 +01:00
Alex Bilbie
19bd476395 Fix silly mistake 2014-05-03 11:13:36 +01:00
Alex Bilbie
7fada0964d Run codesniffer 2014-05-03 11:08:43 +01:00
Alex Bilbie
b82551c97d PHPCS fixes 2014-05-03 11:08:33 +01:00
Alex Bilbie
5c8ed58c67 Cleaned up tests 2014-05-03 10:55:25 +01:00
Alex Bilbie
ed7f5370ca More CS fixer changes 2014-05-03 10:53:57 +01:00
Alex Bilbie
97e7a00bca CS fixer changes 2014-05-03 10:53:43 +01:00
Alex Bilbie
193018aecf Merge branch 'v4.0.0-WIP' of github.com:php-loep/oauth2-server into v4.0.0-WIP 2014-05-03 10:49:00 +01:00
Alex Bilbie
76289c68da Merge pull request #163 from GrahamCampbell/composer
Updated composer.json
2014-05-03 10:44:31 +01:00
Graham Campbell
9f6576c0fa Updated composer.json 2014-05-03 10:27:40 +01:00
Alex Bilbie
107991b0a7 Updated grant tests with new grant name 2014-05-02 17:25:04 +01:00
Alex Bilbie
ffc25fb276 Renamed Grants 2014-05-02 17:24:55 +01:00
Alex Bilbie
97fd115530 Updated with new entity names 2014-05-02 17:21:53 +01:00
Alex Bilbie
8fbbc7bd07 isValidRequest now throws exception 2014-05-02 15:15:03 +01:00
Alex Bilbie
228144a701 Inject server 2014-05-02 15:14:46 +01:00
Alex Bilbie
184fac507b Bug fix for OAuthException 2014-05-02 15:14:36 +01:00
Alex Bilbie
82c10c32fd Removed FQN 2014-05-02 15:14:25 +01:00
Alex Bilbie
782f43c73a Updated entity class names 2014-05-02 15:14:12 +01:00
Alex Bilbie
6e5327a0e2 Renamed StubAbstractToken 2014-05-02 15:12:45 +01:00
Alex Bilbie
5206d77167 Renamed test classes 2014-05-02 15:12:15 +01:00
Alex Bilbie
bdd2bc322c Renamed entities (added Entity to the end of class name) 2014-05-02 15:12:00 +01:00
Alex Bilbie
e5315dc016 Test fixes 2014-05-01 14:57:12 +01:00
Alex Bilbie
8b4b884a03 Pass the token instead of string 2014-05-01 14:47:01 +01:00
Alex Bilbie
f78caa24bb Renamed method to be more obvious 2014-05-01 14:46:43 +01:00
Alex Bilbie
79b1e39798 Removed special case for cURL 2014-05-01 14:46:35 +01:00
Alex Bilbie
797ed66eda Added getBySession 2014-05-01 14:46:22 +01:00
Alex Bilbie
16bdc36ccb Accept token instead of strings 2014-05-01 14:45:38 +01:00
Alex Bilbie
b5f02d0739 Inject the access token object 2014-05-01 14:44:13 +01:00
Alex Bilbie
1183fe80c6 Lots of fixes for tests following exceptions changes 2014-05-01 14:33:11 +01:00
Alex Bilbie
9f1f0cc3bc Updates to exceptions 2014-05-01 14:32:54 +01:00
Alex Bilbie
6981ced972 Updated thrown exceptions 2014-04-25 11:24:48 +01:00
Alex Bilbie
019dfa8836 Updated thrown exceptions 2014-04-25 11:24:42 +01:00
Alex Bilbie
7f6ca35628 Updated exceptions 2014-04-25 11:24:33 +01:00
Alex Bilbie
e1a7f576e4 Moved exception code into new exception classes 2014-04-25 11:24:25 +01:00
Alex Bilbie
6250daabd3 Updated .gitignore 2014-04-25 11:18:43 +01:00
Alex Bilbie
04277aeaa0 Updated .gitignore 2014-04-25 10:04:04 +01:00
Alex Bilbie
647de842ff Updated exceptions 2014-04-25 10:01:01 +01:00
Alex Bilbie
ed10cbb4dc Updated change log for 3.2 2014-04-09 08:53:45 +01:00
Alex Bilbie
ba5f2840fb Merge branch 'release/3.2' into develop 2014-04-06 22:04:27 +01:00
Alex Bilbie
e8aeaf0777 Merge branch 'release/3.2' 2014-04-06 22:04:19 +01:00
Alex Bilbie
fcc1388aeb Updated change log and version number 2014-04-06 22:04:12 +01:00
Alex Bilbie
d7ddfe6452 Updated docblock 2014-04-06 22:01:56 +01:00
Alex Bilbie
785d3bd21f Merge pull request #151 from giftcards/develop
add the ability to change the algorithm that is used to generate the token strings
2014-04-06 21:13:58 +01:00
Alex Bilbie
5893ba4e8e Fixes #151 2014-04-06 21:08:35 +01:00
Alex Bilbie
b2c07aa68f Renamed method make to generate 2014-04-06 21:08:20 +01:00
Alex Bilbie
ac29fc4a62 Added more keywords, removed suggest key 2014-04-06 19:20:17 +01:00
Alex Bilbie
f78bb954d0 Removed weird spacing 2014-04-06 19:18:31 +01:00
Alex Bilbie
29b0389a75 PSR-4 baby! 2014-04-06 19:17:56 +01:00
Alex Bilbie
2aa318cfd7 AuthCode grant 2014-04-06 19:14:46 +01:00
Alex Bilbie
82f7c7abaf Removed unused method 2014-04-06 19:14:37 +01:00
Alex Bilbie
2d90540531 Spelling fix 2014-04-06 19:14:29 +01:00
Alex Bilbie
de681b1ebf RefreshToken is already taken so use RT 2014-04-06 19:14:16 +01:00
Alex Bilbie
b5217271b0 Added exception message testing 2014-04-06 19:13:45 +01:00
Joseph Deray
cc1e78e1ff removed unused use statement 2014-03-11 12:42:26 -04:00
Joseph Deray
b12a1d84df added the ability to change the algorithm used to generate the token strings. added files missing in last commit 2014-03-11 12:41:21 -04:00
Joseph Deray
901aab9deb added the ability to change the algorithm used to generate the token strings 2014-03-11 12:39:09 -04:00
Alex Bilbie
9ac56ad547 Updated @link 2014-03-09 20:05:38 +00:00
Alex Bilbie
c60b29d201 First commit of AuthCode grant and entity 2014-03-09 20:03:05 +00:00
Alex Bilbie
2a524efff5 Bug fix 2014-03-09 20:02:22 +00:00
Alex Bilbie
c8c69829f0 Copyright change 2014-03-09 20:02:06 +00:00
Alex Bilbie
22794d49d1 Removed old implicit grant 2014-03-09 19:35:53 +00:00
Alex Bilbie
4e37d9bb61 Updated Refresh Token and Password grants 2014-03-09 19:35:23 +00:00
Alex Bilbie
af06f9f3ea Updated copyright 2014-03-09 19:34:37 +00:00
Alex Bilbie
aef86227da Updated copyright 2014-03-09 19:34:23 +00:00
Phil Sturgeon
54ffa58e7b Merge branch 'develop' of github.com:thephpleague/oauth2-server 2014-02-26 18:15:37 -05:00
Phil Sturgeon
5f7c14789b Bumped composer.json version 2014-02-26 18:14:53 -05:00
Phil Sturgeon
0bc16c04d9 Fixed lots of links, and improved readability of links. 2014-02-26 17:45:32 -05:00
Phil Sturgeon
8a2922697f Merge branch 'release/3.1.2'
Conflicts:
	README.md
2014-02-26 17:45:16 -05:00
Phil Sturgeon
1045c70bac Fixed some links in README. 2014-02-26 17:37:33 -05:00
Phil Sturgeon
3c9fd6be27 Updated changelog. 2014-02-26 17:35:34 -05:00
Phil Sturgeon
f83a9a7fa4 Support Authorization header passed as ENV var
Some hosts (at this point I only know of Fortrabbit) require Authorization headers to be passed as an environment variable, which PHP will then shove into . See more: http://fortrabbit.com/docs/essentials/quirks-and-constraints\#authorization-header
2014-02-26 17:28:17 -05:00
Alex Bilbie
d10cc5040d Inject server into storage 2014-02-24 16:50:19 +00:00
Alex Bilbie
d314c1efd9 Merge branch 'v4.0.0-WIP' of github.com:php-loep/oauth2-server into v4.0.0-WIP 2014-02-24 14:43:56 +00:00
Alex Bilbie
468acbc369 Renamed Resource to ResourceServer 2014-02-24 14:43:26 +00:00
Alex Bilbie
013b1b53b4 Renamed Authorization to AuthorizationServer 2014-02-24 14:43:00 +00:00
Alex Bilbie
5254c9d225 Renamed Authorization to AuthorizationServer 2014-02-24 14:42:35 +00:00
Alex Bilbie
e07e0dba78 Added PHP 5.6 testing 2014-02-12 09:57:58 +00:00
Phil Sturgeon
8556f616d3 Ninja 5.6 test 2014-02-11 12:27:35 -05:00
Alex Bilbie
064d4d967c Update composer.json 2014-01-23 08:18:21 +00:00
Alex Bilbie
a85feb1a32 Update composer.json 2014-01-23 08:18:00 +00:00
Alex Bilbie
8e7a975f1a Update composer.json 2014-01-23 08:17:44 +00:00
Phil Sturgeon
5829781b38 Update composer.json 2014-01-22 11:28:23 -05:00
Phil Sturgeon
895a379ed3 Update composer.json 2014-01-22 11:27:38 -05:00
Alex Bilbie
e4622b1f65 Check for headers only by default, also allow a token to be passed in 2014-01-17 17:17:13 +00:00
Alex Bilbie
c5f48782e6 $accessToken should be protected not public 2014-01-17 17:16:52 +00:00
Alex Bilbie
9de979a4ee Little bug fix 2014-01-17 10:37:05 +00:00
Alex Bilbie
20df1f50a6 Some initial grant testing 2014-01-17 10:36:57 +00:00
Alex Bilbie
40ea409aed Removed private property reader hack 2014-01-16 17:27:05 +00:00
Alex Bilbie
a5b4198cb7 Removed PHP Documentor from composer.json 2014-01-16 17:14:47 +00:00
Alex Bilbie
e71eb8074c Update composer before running 2014-01-16 17:09:51 +00:00
Alex Bilbie
0c4a45f329 Updated phpunit.xml.dist 2014-01-16 16:59:40 +00:00
Alex Bilbie
115ca30f5a Added hhvm testing 2014-01-16 16:53:44 +00:00
Alex Bilbie
310c00a096 Updated tests 2014-01-16 16:51:21 +00:00
Alex Bilbie
add1aa5949 Updated tests 2014-01-16 16:51:06 +00:00
Alex Bilbie
36760a07cc Updated util tests 2014-01-16 16:50:30 +00:00
Alex Bilbie
11e0b004bd Numerous updates 2014-01-16 16:50:16 +00:00
Alex Bilbie
a2db7e1929 Removed old tests 2014-01-16 16:50:03 +00:00
Alex Bilbie
3cd5f50e64 Renamed Entities/ folder to Entity/ 2014-01-16 16:49:46 +00:00
Alex Bilbie
603efeb80d Dropped http-foundation support down to just 2.* 2014-01-10 18:01:15 +00:00
Alex Bilbie
69571bc8ef Little fixes 2014-01-10 17:30:18 +00:00
Alex Bilbie
ca3b7d51df Added abstract server 2014-01-10 17:30:12 +00:00
Alex Bilbie
ac2beb08d6 Lots of logic implementation fixes 2014-01-10 12:30:13 +00:00
Alex Bilbie
0250d8d4d1 Too many changes to describe 2014-01-08 16:15:29 +00:00
Alex Bilbie
2d90a09f65 Scopes no longer have names 2013-12-31 15:36:02 +00:00
Alex Bilbie
e9d867ba95 Removed id property from token entities, just use token now 2013-12-31 15:35:51 +00:00
Alex Bilbie
2c732a6647 PHP error fix 2013-12-31 15:35:13 +00:00
Alex Bilbie
0b1221ac14 Use http-foundation 2.4.* 2013-12-31 15:35:04 +00:00
Alex Bilbie
ca4763483d Removed old SQL tables 2013-12-26 20:24:02 +00:00
Alex Bilbie
9d6ecfae46 Little changes 2013-12-26 20:22:31 +00:00
Alex Bilbie
a3863fec2e Updated authorisation server 2013-12-24 17:02:58 +00:00
Alex Bilbie
5cd420bd5d Updated resource server 2013-12-24 17:02:49 +00:00
Alex Bilbie
e62bc4e98d Updated storage interfaces 2013-12-24 17:02:34 +00:00
Alex Bilbie
7a38187076 Updated grants 2013-12-24 17:01:56 +00:00
Alex Bilbie
40490db27f Added ServerException 2013-12-24 17:01:29 +00:00
Alex Bilbie
bc74aff46d Added entities 2013-12-24 17:01:11 +00:00
Alex Bilbie
337cb088e9 Delete some old files we don't care about 2013-12-24 17:01:02 +00:00
Alex Bilbie
25332be3d1 Update .travis.yml 2013-12-23 23:39:49 +00:00
Alex Bilbie
13b15dfa3a Update README.md 2013-12-19 12:33:39 +00:00
Alex Bilbie
7c1b913e49 Travis will now test against HHVM 2013-12-19 12:32:09 +00:00
Alex Bilbie
9e5bd4cd67 First commit of Session 2013-12-16 23:47:53 +00:00
Alex Bilbie
427ae50704 First commit of AccessToken 2013-12-16 23:47:47 +00:00
Alex Bilbie
449ba5005c First commit of updated ResourceServer 2013-12-16 23:47:03 +00:00
Alex Bilbie
b86d1f1406 Added symfony/http-foundation as dependency 2013-12-16 17:15:31 +00:00
Alex Bilbie
f563a59ce8 Update CONTRIBUTING.md 2013-12-06 10:50:22 +00:00
Alex Bilbie
324a3f0cdc Merge pull request #123 from alexbilbie/develop
Added CONTRIBUTING.md
2013-12-06 02:49:06 -08:00
Alex Bilbie
f07d169336 Added CONTRIBUTING.md 2013-12-06 10:48:38 +00:00
Alex Bilbie
227707c5dc Merge pull request #122 from andersonamuller/patch-1
Typo in docblock
2013-12-06 02:27:51 -08:00
Alex Bilbie
6d7887dc36 Removed unnecessary line 2013-12-06 10:20:42 +00:00
Alex Bilbie
5870368e33 Added TravisCI's new asset caching http://about.travis-ci.org/blog/2013-12-05-speed-up-your-builds-cache-your-dependencies/ 2013-12-06 10:20:03 +00:00
Anderson Müller
9b9cf79f39 Typo in docblock 2013-12-06 11:17:41 +01:00
Alex Bilbie
619d755008 Removed some tests that randomly fail 2013-12-06 10:17:33 +00:00
Alex Bilbie
2adefdf4c8 Removed section about built in PDO drivers 2013-12-05 21:42:48 +00:00
Alex Bilbie
b5854215a7 Went back to old title 2013-12-05 21:37:24 +00:00
Alex Bilbie
302026d437 Merge branch 'master' of github.com:php-loep/oauth2-server 2013-12-05 21:33:03 +00:00
Alex Bilbie
8d17049877 Merge branch 'refs/heads/master' into develop 2013-12-05 21:32:44 +00:00
Alex Bilbie
1f523c3a08 README updates 2013-12-05 21:32:29 +00:00
Alex Bilbie
924066166c Merge pull request #119 from bitdeli-chef/master
Add a Bitdeli Badge to README
2013-12-05 13:18:26 -08:00
Bitdeli Chef
0dcda992c7 Add a Bitdeli badge to README 2013-12-05 21:20:48 +00:00
Alex Bilbie
70aafb7521 Merge branch 'release/3.1.1' into develop 2013-12-05 21:10:03 +00:00
Alex Bilbie
f59213499c Merge branch 'release/3.1.1' 2013-12-05 21:09:43 +00:00
Alex Bilbie
d9917a57e1 Version bump 2013-12-05 21:09:35 +00:00
Alex Bilbie
dba976d6ac Fixes #108, fixes #114 - ucfirst headers 2013-12-05 20:57:22 +00:00
Alex Bilbie
8fe3ed7eb5 Merge branch 'release/3.1' into develop 2013-12-05 20:43:04 +00:00
Alex Bilbie
9099173db2 Merge branch 'release/3.1' 2013-12-05 20:42:52 +00:00
Alex Bilbie
c6ac1de26b Updated changelog 2013-12-05 20:42:42 +00:00
Alex Bilbie
e55ca5bc05 Version bump 2013-12-05 20:41:51 +00:00
Alex Bilbie
4febb90210 Merge branch 'feature/no-inject-server' into develop 2013-12-05 20:33:08 +00:00
Alex Bilbie
75482c9e20 Test setIdentifier because @philsturgeon didn't 2013-12-05 20:32:46 +00:00
Alex Bilbie
0db8850e81 Merge branch 'refs/heads/develop' into feature/no-inject-server
Conflicts:
	src/League/OAuth2/Server/Grant/GrantTrait.php
2013-12-05 20:28:31 +00:00
Alex Bilbie
9a224bd847 Merge branch 'feature/no-inject-server' into develop 2013-12-05 20:26:22 +00:00
Alex Bilbie
0c36045913 Updated unit tests 2013-12-05 20:25:55 +00:00
Alex Bilbie
262ce23fb9 No longer need to inject auth server into grant 2013-12-05 20:25:50 +00:00
Phil Sturgeon
1419ba8cdc Added GrantTrait::setIdentifier
I found it useful to be able to set the identifier so I could "alias" one for deprecation. Hopefully no issues here @alexbilbie
2013-12-04 17:23:19 -05:00
Alex Bilbie
b55b73c1e8 Merge branch 'release/3.0.1' into develop 2013-12-02 18:52:28 +00:00
Alex Bilbie
e95ae977cc Merge branch 'release/3.0.1' 2013-12-02 18:52:18 +00:00
Alex Bilbie
572e6935a6 Version bump + changelog 2013-12-02 18:49:44 +00:00
Alex Bilbie
dd88426323 Merge branch 'hotfix/travistest'
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2013-12-02 18:48:09 +00:00
Alex Bilbie
14683bc65e Removed testing of PHP 5.3 2013-12-02 18:47:56 +00:00
Alex Bilbie
1d3bc85423 Merge branch 'release/3.0'
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2013-12-02 18:44:48 +00:00
Alex Bilbie
10a4bf41ed Version bump 2013-12-02 18:44:08 +00:00
Alex Bilbie
041104e2b1 Updated changelog 2013-12-02 18:43:42 +00:00
Alex Bilbie
031cf3064a Moved some grant related functions into a trait to reduce duplicate code 2013-12-02 18:42:54 +00:00
Alex Bilbie
954ff19823 Removed suggested composer packages 2013-11-29 12:35:29 +00:00
Alex Bilbie
5bb1359ad7 Added some initial changelogs 2013-11-29 12:34:18 +00:00
Alex Bilbie
2bd61f040b Updated minimum PHP requirement to 5.4+ to support future changes 2013-11-29 12:34:08 +00:00
Alex Bilbie
bacc9ce316 Added some extra keywords 2013-11-29 12:23:35 +00:00
Alex Bilbie
5ec2c24b5c Removed build in DB providers, will be included in separate repos 2013-11-29 12:23:05 +00:00
Alex Bilbie
ec9a08af63 Updated .gitignore 2013-11-25 23:59:37 +00:00
Alex Bilbie
6cade987a2 Added html coverage 2013-11-25 23:59:10 +00:00
Alex Bilbie
44408b873f Make sure $this is returned 2013-11-25 23:58:42 +00:00
Alex Bilbie
b4bfa69c88 Removed nyan cat printer 2013-11-25 23:52:45 +00:00
Alex Bilbie
9c3c70a5fb Removed old build script 2013-11-25 23:52:25 +00:00
Alex Bilbie
556e9cc9ab Merge pull request #101 from jackshakes/develop
Update Implicit Grant token TTL and response structure
2013-11-25 15:05:22 -08:00
jlehner
d3158a830b Update Implicit Grant Type with the following:
- Added accessTokenTTL variable and setter method
 - Updated response in the completeFlow method to include all required parameters per OAuth2 spec
 - completeFlow function accounts for local grant TTL override
2013-09-26 14:40:56 -04:00
Alex Bilbie
4a71c376b8 Merge branch 'refs/heads/master' into develop
Conflicts:
	.travis.yml
	README.md
2013-09-26 11:18:10 +01:00
Alex Bilbie
ed427cba37 Merge pull request #92 from hailwood/patch-1
Adding 'auto_approve' to client details array (with updated interface docs)
2013-09-26 03:07:07 -07:00
Alex Bilbie
a358835522 Merge pull request #100 from fotovio/develop
Fixed Issues with Returns and Columns of Fluent Storage
2013-09-26 03:06:11 -07:00
Daniel Schniepp
23627c659e Fixed issues with returns and columns 2013-09-25 16:59:45 +02:00
Alex Bilbie
bee71c1e83 Merge pull request #94 from daveWid/request-interface-cleanup
Request interface cleanup
2013-09-08 03:23:26 -07:00
Alex Bilbie
ad97273455 Gave "bearer" a capital "B". Fixes #96 2013-09-07 18:00:13 +01:00
Alex Bilbie
0b55dc4c01 Gave "bearer" a capital "B" 2013-09-07 17:59:44 +01:00
Alex Bilbie
4985770d07 Gave "bearer" a capital "B" 2013-09-07 17:59:34 +01:00
Dave Widmer
a2bf4e0dfb Removing constructor and buildFromGlobals from RequestInterface. Fixes: #88 2013-09-06 09:14:24 -04:00
Alex Bilbie
cfbb037e07 Removed all code coverage output except text to stdout 2013-09-06 10:39:08 +01:00
Alex Bilbie
6c28fea213 Merge pull request #87 from daveWid/normalize-headers
Normalize headers
2013-09-06 02:36:54 -07:00
Matthew Hailwood
e5dc3001c4 Update ClientInterface.php 2013-09-04 12:43:12 +12:00
Matthew Hailwood
69531c3eb5 Adding auto_approve field to client details array. 2013-09-04 12:38:45 +12:00
Phil Sturgeon
89f3446b98 Merge pull request #79 from reinink/patch-1
Fixed link to authorization server guide.
2013-08-27 09:01:16 -07:00
Dave Widmer
69710a5909 Normalizing headers to a Ucfirst-With-Dashes format. 2013-08-20 11:40:02 -04:00
Phil Sturgeon
85353c5844 Test in PHP 5.5 too 2013-08-08 09:25:17 -04:00
Alex Bilbie
879d98abfb Merge pull request #84 from nhorvath/develop
Update Implicit.php
2013-08-02 11:58:01 -07:00
nhorvath
f612e105bd Update Implicit.php
Fix typo in class name. Change "Implict" to "Implicit"
2013-08-02 14:51:13 -04:00
Alex Bilbie
56f63bb4c0 Added printer, don't test anything in vendor/ 2013-07-30 10:17:59 +01:00
Alex Bilbie
8a42bc796f Removed printer [ci skip] 2013-07-30 10:13:47 +01:00
Alex Bilbie
8fa7b303fa Added Nyan printer for the lolz 2013-07-30 10:10:59 +01:00
Alex Bilbie
55b86e26ad [ci skip] 2013-07-30 10:10:29 +01:00
toopay
e1f09db6af update composer 2013-07-27 07:34:46 +07:00
toopay
1e28faabb9 Blacklist all vendors 2013-07-27 06:56:40 +07:00
toopay
9a3a91760a Update composer 2013-07-27 06:47:21 +07:00
toopay
78d65e102a update travis 2013-07-27 06:47:10 +07:00
toopay
701010b129 Update travis 2013-07-27 06:32:04 +07:00
toopay
84afff9ad2 Default phpunit config that will be ignored if phpunit.xml exists 2013-07-27 06:31:15 +07:00
toopay
cfc61147e1 Add phpunit coverage listener 2013-07-27 06:29:46 +07:00
Jonathan Reinink
66ddba808f Fixed link to authorization server guide. 2013-07-26 10:04:09 -04:00
Alex Bilbie
6324a97118 Added badges [ci skip] 2013-07-26 11:08:24 +01:00
Alex Bilbie
4170f4e841 Update .travis.yml 2013-07-26 10:56:23 +01:00
Alex Bilbie
5c21370691 Added satooshi/php-coveralls to composer.json [ci skip] 2013-07-26 10:55:56 +01:00
Phil Sturgeon
c176c1cddc Added contributors 2013-07-24 13:14:48 -04:00
Alex Bilbie
71b6f2c2bc Merge pull request #78 from philipbrown/fix_fluent_client_argument_default
Fix fluent client argument default
2013-07-18 09:11:31 -07:00
Philip Brown
f1567df802 Set $grantType default 2013-07-17 11:40:06 +01:00
Alex Bilbie
307964d571 Fixed missing $this 2013-06-18 18:27:34 +01:00
Alex Bilbie
a1ca904255 Merge branch 'develop' of github.com:php-loep/oauth2-server into develop 2013-06-18 18:17:02 +01:00
Alex Bilbie
6e045afa26 Merge pull request #70 from gstjohn/master
Fix to docblocks
2013-06-08 04:28:34 -07:00
Garrett St. John
8f15158d1c Fix to docblocks 2013-06-06 14:00:17 -07:00
Garrett St. John
ca4e749986 Fix to docblocks 2013-06-06 13:09:15 -07:00
Alex Bilbie
cc0ab4905a Merge pull request #68 from jasongrimes/public-determineAccessToken
Make determineAccessToken() public
2013-06-06 06:52:12 -07:00
Jason Grimes
e5a48c929b Make determineAccessToken() public in order to check if an access token was sent before checking its validity. 2013-06-05 23:59:29 -04:00
Alex Bilbie
829cef936a mErge branch 'feature/fluent' into develop 2013-06-02 14:59:31 +01:00
Alex Bilbie
f78e05cb08 Anal space fixes 2013-06-02 14:59:05 +01:00
Alex Bilbie
0999bf4de3 Added missing functions 2013-06-02 14:58:59 +01:00
Alex Bilbie
e442253e26 Anal spacing fixes and removed PHP5.4+ specific array syntax 2013-06-02 14:58:52 +01:00
Alex Bilbie
4c4155fdac Added \Illuminate\Support\Facades\DB namespace 2013-06-02 14:54:49 +01:00
Alex Bilbie
d901e90602 Added \Illuminate\Support\Facades\DB namespace 2013-06-02 14:41:38 +01:00
Alex Bilbie
32a7ed38a9 Updated PSR compliance. Added Illuminate\Support\Facades\DB namespace 2013-06-02 14:40:59 +01:00
Alex Bilbie
9dec6c4bfe Added Doctrine/DBAL implementation of storage classes (thanks @inanimatt) 2013-06-02 14:25:06 +01:00
Alex Bilbie
bcfb9ec475 Merge branch 'release/2.1.1' into develop 2013-06-02 13:55:12 +01:00
Alex Bilbie
98be9ab252 Merge branch 'release/2.1.1' 2013-06-02 13:55:01 +01:00
Alex Bilbie
e0f4ccb775 Updated changelog 2013-06-02 13:54:54 +01:00
Alex Bilbie
dca0898c2f Version bump 2013-06-02 13:54:47 +01:00
Alex Bilbie
7da9e1a9d7 Merge pull request #64 from alexmcroberts/develop
Conditional isValid flag to check for Authorization header only. Fixes #57
2013-06-02 05:46:45 -07:00
Alex McRoberts
a4a8f6e661 This fixes #57. By passing in a conditional flag refering to headersOnly, the library would stil respect RFC6749 Section 7 and RFC6750 Section 2. 2013-05-27 21:27:30 -07:00
Alex Bilbie
a9ecca92fc Fixed broken test 2013-05-27 19:38:07 +01:00
Alex Bilbie
47c24e3181 Corrected array key call. Fixes #63 2013-05-27 20:33:07 +02:00
Alex Bilbie
4d36ebd3e7 Added namespaces 2013-05-14 09:50:40 +01:00
Alex Bilbie
0b3a9dc888 Converted PHP 5.4 array syntax to old-skool syntax 2013-05-14 09:46:14 +01:00
Alex Bilbie
1fcdbf45b2 Removed docblocks 2013-05-14 09:45:19 +01:00
Alex Bilbie
94a064e2f4 Added fluent storage from #54 2013-05-14 09:44:12 +01:00
Alex Bilbie
92b6ce3335 Added default value for final argument in ClientInterface::getClient(). Fixes #56 2013-05-14 09:00:36 +01:00
Alex Bilbie
ee9549287e Updated docblocks 2013-05-14 08:59:53 +01:00
Alex Bilbie
4b3e0bf668 Fixed semantic meaning of requireScopeParam() and requireStateParam() by changing their default value to true 2013-05-10 23:01:54 -07:00
Alex Bilbie
05d4b68586 Optimised regex and re-added trim() following conversation in #52 2013-05-10 23:00:47 -07:00
Alex Bilbie
ec9c39c108 Merge branch 'release/2.1' into develop 2013-05-10 17:59:37 -07:00
Alex Bilbie
5d0b295a82 Merge branch 'release/2.1' 2013-05-10 17:59:29 -07:00
Alex Bilbie
9ec5442f90 Updated changelog 2013-05-10 17:59:08 -07:00
Alex Bilbie
4112913813 Version bump 2013-05-10 17:58:57 -07:00
Alex Bilbie
5eb4227709 Merge branch 'feature/auth-code-scopes' into develop. Fixes #44 2013-05-10 17:42:05 -07:00
Alex Bilbie
f5251a6080 Updated sessions 2013-05-10 17:39:29 -07:00
Alex Bilbie
86fb02d218 Added cascading relationship between oauth_sessions_authcodes and oauth_sessions 2013-05-10 17:32:39 -07:00
Alex Bilbie
ef4a138237 Fixed associateAuthCodeScope() query 2013-05-10 17:29:28 -07:00
Alex Bilbie
d531a37412 Don't add scope IDs 2013-05-10 17:26:23 -07:00
Alex Bilbie
ca599437f6 Added oauth_session_authcode_scopes 2013-05-10 17:24:46 -07:00
Alex Bilbie
252afddbd3 Updated oauth_session_authcodes table. Added id field, remove scope_ids field 2013-05-10 17:24:31 -07:00
Alex Bilbie
c57c4b1b4f Fixed key name 2013-05-10 17:19:53 -07:00
Alex Bilbie
ba2dc90f3b Altered associateScope logic 2013-05-10 17:08:20 -07:00
Alex Bilbie
7373f312da Updated variable name 2013-05-10 17:08:10 -07:00
Alex Bilbie
a01810d8fa Updated validateAuthCode in PDO Session 2013-05-10 17:07:29 -07:00
Alex Bilbie
3ea3eb5ebd Implemented getAuthCodeScopes() in PDO Session 2013-05-10 17:07:06 -07:00
Alex Bilbie
11022e16ef Updated validateAuthCode() in SessionInterface 2013-05-10 17:06:44 -07:00
Alex Bilbie
8d06a7b685 Updated getAuthCodeScopes() in SessionInterface 2013-05-10 17:06:05 -07:00
Alex Bilbie
c66c8092f9 Revert "Return the session_id for validateAuthCode instead of an array"
This reverts commit 51138f8738.
2013-05-10 16:57:39 -07:00
Alex Bilbie
591139f44d Added associateAuthCodeScope to PDO 2013-05-10 16:57:18 -07:00
Alex Bilbie
410ad09b5c Updated PDO associateAuthCode 2013-05-10 16:56:38 -07:00
Alex Bilbie
51138f8738 Return the session_id for validateAuthCode instead of an array 2013-05-10 16:53:52 -07:00
Alex Bilbie
aa8d38108f Associate scopes to auth codes in separate method. Creating an auth code now returns an ID 2013-05-10 16:53:21 -07:00
Alex Bilbie
9372cc85d0 Added getAuthCodeScopes() method 2013-05-10 16:50:34 -07:00
Alex Bilbie
accb80289f Added associateAuthCodeScope() method 2013-05-10 16:50:13 -07:00
Alex Bilbie
e591fbb25c Merge branch 'feature/refresh-token-rotation' into develop 2013-05-10 16:13:22 -07:00
Alex Bilbie
fdb89fb5e4 Updated tests 2013-05-10 16:13:11 -07:00
Alex Bilbie
ce51821043 If rotateRefreshTokens() is true then associate new access tokens 2013-05-10 16:13:06 -07:00
Alex Bilbie
eac33d50b3 Added missing semicolon 2013-05-10 16:12:43 -07:00
Alex Bilbie
2552b73b17 Added rotateRefreshTokens() method 2013-05-10 16:00:40 -07:00
Alex Bilbie
8c4019693b Updated @ziege's patch to overcome awkward access token definition requirement (i.e. access token can have a space in it) and also optimised code. Fixes #52 2013-05-10 12:57:34 -07:00
ziege
b88ef82563 Fixed two probems in access token check
1) The method returned the wrong result in case when the access token itself contained the string "Bearer".

2) When using cURL, the request is sometimes send twice (in my case when the first request returned a 404 error), and the Authorization header of the second request is doubled, so that you get a "Authorization: Bearer XXX, Bearer XXX". This case is checked now. (BTW: Tested with the current PHP version 5.4.15 on Windows.)
2013-05-10 20:00:01 +02:00
Alex Bilbie
3e5b4a1735 Move zetacomponents/database to "suggest" in composer.json. Fixes #51 2013-05-10 10:13:17 -07:00
Alex Bilbie
41a7125370 Accidentally used PHP 5.4 style bracket 2013-05-09 11:48:21 -07:00
Alex Bilbie
c40484abb1 Merge branch 'feature/refresh-token-rewrite' into develop 2013-05-09 11:42:31 -07:00
Alex Bilbie
f4bcfee687 Update associated scopes if requested in refresh access token. Fixes #47 2013-05-09 11:42:28 -07:00
Alex Bilbie
6d8eb9d05e Added removeRefreshToken method to SessionInterface 2013-05-09 11:40:29 -07:00
Alex Bilbie
76f2f6a5e1 Don't delete old sessions when issuing new access tokens using the Password or Client Credential grants. Fixes #32 2013-05-09 10:43:44 -07:00
Alex Bilbie
d677b765b2 Renamed scopes.key to scopes.scope. Updated ScopeInterface and PDO/Scope. Fixes #45 2013-05-09 10:23:41 -07:00
Alex Bilbie
7035792325 Allow for multiple default scopes. Fixes #42 2013-05-09 10:15:36 -07:00
Alex Bilbie
351c2e97ea If scope parameter is required and there are not requested scopes AND there is no default scope set then fail
Should have been included in with previous commit
2013-05-09 10:06:44 -07:00
Alex Bilbie
ddefb2ee16 Set the scope parameter to not be required by default. Fixes #43 2013-05-09 10:02:41 -07:00
Alex Bilbie
c3b41a5e8a Merge branch 'release/2.0.5' into develop 2013-05-09 09:47:33 -07:00
Alex Bilbie
b16c58bfe1 mErge branch 'release/2.0.5' 2013-05-09 09:47:21 -07:00
Alex Bilbie
e6d0a19e8f Version bump 2013-05-09 09:47:11 -07:00
Alex Bilbie
2296d09e92 Changelog update 2013-05-09 09:47:07 -07:00
Alex Bilbie
69af252844 Fixed docblock 2013-05-09 09:45:10 -07:00
Alex Bilbie
d9c598af3c Removed DEFAULT '' that has slipped in 2013-05-09 09:38:08 -07:00
Alex Bilbie
3cb79fc2b5 Fixed oauth_session_token_scopes primary key 2013-05-09 09:31:05 -07:00
Alex Bilbie
39379fe5b6 Merge branch 'release/2.0.4' into develop 2013-05-09 08:01:45 -07:00
Alex Bilbie
1375f91e15 Merge branch 'release/2.0.4' 2013-05-09 08:01:33 -07:00
Alex Bilbie
08a7055679 Version bump 2013-05-09 08:01:25 -07:00
Alex Bilbie
9f9a828294 Updated changelog 2013-05-09 08:01:18 -07:00
Alex Bilbie
77fbb2a851 Removed docblocks from session PDO class 2013-05-09 07:55:54 -07:00
Alex Bilbie
c0683586e2 A refresh token should be bound to a client ID 2013-05-09 07:55:10 -07:00
Alex Bilbie
86a483f288 Adding missing column to oauth_session_authcodes 2013-05-09 07:54:09 -07:00
Alex Bilbie
3617a3b37d Renamed primary key in oauth_client_endpoints table 2013-05-09 07:17:41 -07:00
Alex Bilbie
24634aabd7 Merge branch 'release/2.0.3' into develop 2013-05-08 22:09:35 -07:00
Alex Bilbie
ffc286c9f9 mErge branch 'release/2.0.3' 2013-05-08 22:09:18 -07:00
Alex Bilbie
7064442a4c Version bump 2013-05-08 22:09:10 -07:00
Alex Bilbie
68a64e9498 Fixed home page 2013-05-08 22:08:43 -07:00
Alex Bilbie
b04240b9e7 Merge branch 'release/2.0.2' into develop 2013-05-08 19:39:41 -07:00
Alex Bilbie
196a5aea13 Merge branch 'release/2.0.2' 2013-05-08 19:39:28 -07:00
Alex Bilbie
f2f99b429f Version bump 2013-05-08 19:39:15 -07:00
Alex Bilbie
561bda71a9 Link to wiki 2013-05-08 19:38:23 -07:00
Alex Bilbie
6b686a96e7 Updated tutorial links 2013-05-08 19:37:19 -07:00
Alex Bilbie
dbe21cc5a7 Removed null as default for parameters 2013-05-08 19:36:00 -07:00
Alex Bilbie
8b154054c3 Updated License 2013-05-08 19:04:40 -07:00
Alex Bilbie
972e517280 Added example queries and expected responses 2013-05-08 18:37:34 -07:00
Alex Bilbie
ca9760cd36 Updated docblocks and example queries in scope and client storage interfaces 2013-05-08 18:16:24 -07:00
Alex Bilbie
75894fd5bc Test for getClientId 2013-05-08 18:12:18 -07:00
Alex Bilbie
083a44df2e Fixed broken tests following previous commits 2013-05-08 18:10:43 -07:00
Alex Bilbie
1e57533127 Added getClientId method 2013-05-08 18:06:18 -07:00
Alex Bilbie
92e217d0ac Show default parameters 2013-05-08 18:06:09 -07:00
Alex Bilbie
707354348a Changed scope to be a delimiter to a space as required by the spec 2013-05-08 17:42:15 -07:00
Alex Bilbie
f0d493b064 Updated link to wiki 2013-05-08 17:04:17 -07:00
Alex Bilbie
46f0e6c84d Updated docblocks 2013-05-08 17:04:01 -07:00
Alex Bilbie
1dd768545a Updated more docblocks 2013-05-08 14:10:58 -07:00
Alex Bilbie
787c8c566f Updated docblocks 2013-05-08 14:10:48 -07:00
Alex Bilbie
fd10861065 Added missing docblock 2013-05-08 14:10:15 -07:00
Alex Bilbie
0812ca2927 Added missing clientId variable, fixed docblock 2013-05-08 13:59:17 -07:00
Alex Bilbie
a8a375ed1f Anal code style fix 2013-05-08 13:40:15 -07:00
Alex Bilbie
f4b32a2bc6 Optimised tests by removing unused variables and adding further assertions 2013-05-08 13:34:05 -07:00
Alex Bilbie
e2350a65b1 Removed unused functions 2013-05-08 13:24:29 -07:00
Alex Bilbie
437833cd32 Renamed AuthServer to Authorization, renamed ResourceServer to Resource. Updated all tests and other files 2013-05-08 11:42:23 -07:00
Alex Bilbie
1df524ae6e Added missing docblocks 2013-05-08 11:31:38 -07:00
Alex Bilbie
9d1693cf78 Fixed incorrect @link 2013-05-08 11:30:53 -07:00
Alex Bilbie
5524e9b9c8 Moved files into server namespace/folder and updated docblock copyright statements 2013-05-08 11:29:24 -07:00
Alex Bilbie
2d6cc3c98e Renamed package 2013-05-08 11:06:49 -07:00
Alex Bilbie
f4b955ccff Updated tests for new namespace 2013-05-08 11:06:21 -07:00
Alex Bilbie
850473ce40 Renamed namespace to League\OAuth2\ 2013-05-08 11:06:09 -07:00
Alex Bilbie
22d900def1 Updated the changelog 2013-05-08 10:52:13 -07:00
Alex Bilbie
41eef0c3e2 Updated the README 2013-05-08 10:51:56 -07:00
Alex Bilbie
037fd6e4f7 Test for setRefreshTokenTTL 2013-05-08 10:44:03 -07:00
Alex Bilbie
0b927ddfbb Test for setAuthTokenTTL 2013-05-08 10:43:53 -07:00
Alex Bilbie
56b8b7c64e Updated associateRefreshToken to use expire time 2013-05-08 10:38:16 -07:00
Alex Bilbie
0407dbb09b Added refresh token expires column 2013-05-08 10:35:24 -07:00
Alex Bilbie
d6932cbb5e Renamed get/setExpiresIn to get/setAccessTokenTTL 2013-05-08 10:35:13 -07:00
Alex Bilbie
c77484e97b Added refresh token TTL 2013-05-08 10:34:25 -07:00
Alex Bilbie
9f90cd2635 Added method to set the auth token TTL 2013-05-07 15:20:32 -07:00
Alex Bilbie
8fd9e3f312 Renamed setExpiresIn method to accessTokenTTL 2013-05-07 15:16:30 -07:00
Alex Bilbie
5df1338046 New test for getGrantType to test for exception 2013-05-06 15:42:11 -07:00
Alex Bilbie
5d7e0d67cc Updated tests for custom expires in 2013-05-06 15:36:59 -07:00
Alex Bilbie
fdebbac2df Allow grant access token expiresIn override 2013-05-06 15:04:00 -07:00
Alex Bilbie
a561a9d98a Throw an exception if a grant can't be loaded when called in getGrantType 2013-05-06 13:57:46 -07:00
Alex Bilbie
3ac6690ac9 Fixed repo url 2013-05-06 13:13:11 -07:00
Alex Bilbie
e1f83a50ae Merge branch 'refs/heads/develop'
Conflicts:
	composer.json
	src/OAuth2/AuthServer.php
	src/OAuth2/Grant/Password.php
2013-05-06 13:05:39 -07:00
Alex Bilbie
8cdc273dba Fixed composer.json replace key 2013-05-06 12:57:44 -07:00
Alex Bilbie
eada9053ad Updated README 2013-05-06 12:54:16 -07:00
Alex Bilbie
5867774bee Added "replace" key into composer.json 2013-05-06 12:53:39 -07:00
Alex Bilbie
18151d9a8e Version 2.0 baby! 2013-05-06 12:43:50 -07:00
Alex Bilbie
f207a1909f Updated package description 2013-05-06 12:43:38 -07:00
Alex Bilbie
e713d0df9c Renamed package 2013-05-06 12:43:27 -07:00
Alex Bilbie
1ca8a4f4c3 Updated authserver tests 2013-05-06 11:09:36 -07:00
Alex Bilbie
9349425ecd Fixed ResourceServerTest.php 2013-05-06 10:28:49 -07:00
Alex Bilbie
38f6be2aa0 Removed unnecessary methods 2013-05-05 18:22:03 +01:00
Alex Bilbie
d0abd8c295 Fixed getting of session scopes 2013-05-05 18:18:55 +01:00
Alex Bilbie
9be23cf222 Added session scopes 2013-05-05 18:16:28 +01:00
Alex Bilbie
90508a191d Get scopes by access token instead of session ID 2013-05-05 18:14:27 +01:00
Alex Bilbie
10d7d3cb3d Updated response params 2013-05-05 18:11:01 +01:00
Alex Bilbie
89850420f6 Updated query to return session details 2013-05-05 18:09:47 +01:00
Alex Bilbie
9b73eab07c SQL query fix 2013-05-05 18:06:00 +01:00
Alex Bilbie
6897e233d4 Changed variable syntax style to be PSR2 2013-05-05 18:05:46 +01:00
Alex Bilbie
acfadc8993 Actually fixed the bug in validateAccessToken this time 2013-05-05 18:01:00 +01:00
Alex Bilbie
cc81e20206 Bug fix in validateAccessToken 2013-05-05 18:00:08 +01:00
Alex Bilbie
92303c7b26 Implemented validateAccessToken in PDO 2013-05-05 17:58:40 +01:00
Alex Bilbie
2866185349 Updated implicit grant 2013-04-30 15:51:55 +01:00
Alex Bilbie
b9570ac6b0 Fixed getScopes 2013-04-30 15:48:11 +01:00
Alex Bilbie
2a3ae641ab Added getAccessToken, fixed validateRefreshToken docblock 2013-04-30 15:38:48 +01:00
Alex Bilbie
d149490c78 Updated getScopes 2013-04-30 15:32:07 +01:00
Alex Bilbie
c0d8a2c4fb Lots of updated functions 2013-04-30 15:08:20 +01:00
Alex Bilbie
5b03859467 Removed unnecessary code 2013-04-30 15:08:03 +01:00
Alex Bilbie
a661634194 Updated refresh token grant 2013-04-30 15:07:44 +01:00
Alex Bilbie
c73d45fc07 PSR-2 fix 2013-04-30 14:33:30 +01:00
Alex Bilbie
85a53d7470 Fixed Password grant to match past updates 2013-04-30 14:28:59 +01:00
Alex Bilbie
18eea191ed Fixed docblock 2013-04-30 14:28:40 +01:00
Alex Bilbie
14cff9ea44 Added missing db init 2013-04-29 11:59:45 +01:00
Alex Bilbie
1696903b8b Removed extra bracket 2013-04-29 11:53:20 +01:00
Alex Bilbie
13c67c9a40 Updated completeFlow 2013-04-29 11:31:07 +01:00
Alex Bilbie
2dcb81d93c Updated newAuthoriseRequest 2013-04-29 11:25:23 +01:00
Alex Bilbie
b39a9a5edc Added missing DB instance::get() calls 2013-04-29 11:13:31 +01:00
Alex Bilbie
325242e3aa Added missing third parameter 2013-04-29 11:12:35 +01:00
Alex Bilbie
757d2a4fd9 Removed scalar type hinting because it isn't supported 2013-04-29 11:11:16 +01:00
Alex Bilbie
725ab74e5c Updated PDO session 2013-04-29 11:02:32 +01:00
Alex Bilbie
b7ca5d330b Updated associateRefreshToken 2013-04-29 11:02:03 +01:00
Alex Bilbie
4034bea6d1 Updated client credentials grant 2013-04-29 10:36:35 +01:00
Alex Bilbie
6751c4d2fe Fixed mistake from previous commit 2013-04-29 10:35:47 +01:00
Alex Bilbie
53a55d4946 Completely scrapped the old SessionInterface and simplified it 2013-04-29 10:34:11 +01:00
Alex Bilbie
79338d0d75 Delete an associated auth code 2013-04-29 00:02:00 +01:00
Alex Bilbie
17bc6a1512 Comment update 2013-04-29 00:01:51 +01:00
Alex Bilbie
6543ebcd4d Updated updateSession code 2013-04-29 00:01:34 +01:00
Alex Bilbie
351bec6019 Don't associate a scope with a session, we associate it with an access token later 2013-04-29 00:01:07 +01:00
Alex Bilbie
a4715bfc3b Updated create a new session 2013-04-29 00:00:04 +01:00
Alex Bilbie
4ef8030a93 First commit of PDO storage class 2013-04-28 23:58:01 +01:00
Alex Bilbie
7bfbe81f61 Started PDO storage classes 2013-04-28 23:57:50 +01:00
Alex Bilbie
81d6bcf00a Changed params around and removed line breaks 2013-04-28 23:57:29 +01:00
Alex Bilbie
a93a039df3 Lots of table fixes 2013-04-28 23:56:17 +01:00
Alex Bilbie
d0d0d2a7c3 Require zetacompontents/database 2013-04-28 19:06:21 +01:00
Alex Bilbie
6f71439edd Renamed lots of columns 2013-04-23 14:20:38 +01:00
Alex Bilbie
b0d3ba7e70 Revert "Removed session_token_id column from oauth_session_authcode"
This reverts commit 859e6720bf.
2013-04-23 13:56:13 +01:00
Alex Bilbie
a265b027cc Removed stage parameter 2013-04-23 13:52:21 +01:00
Alex Bilbie
859e6720bf Removed session_token_id column from oauth_session_authcode 2013-04-23 13:45:07 +01:00
Alex Bilbie
b7bae1120b Fixed mysql character set 2013-04-23 13:44:21 +01:00
Alex Bilbie
4727a83d84 Removed stage parameter 2013-04-23 13:29:33 +01:00
Alex Bilbie
67641acdff Revert "renamed package to oauth2-server"
This reverts commit 09b74aa61d.
2013-04-17 14:27:09 +01:00
Alex Bilbie
09b74aa61d renamed package to oauth2-server 2013-04-17 14:22:42 +01:00
Alex Bilbie
d75d266376 Updated SQL structure 2013-04-03 15:50:07 +01:00
Alex Bilbie
645d412c02 Removed die(var_dump()) 2013-03-31 13:57:35 +01:00
Alex Bilbie
5f1609577e Added stateParamRequired method 2013-03-31 13:57:24 +01:00
Alex Bilbie
351580d9d8 Added getResponseTypes() method 2013-03-31 13:37:12 +01:00
Alex Bilbie
9c9db978c6 Move authorisation code grant stuff into own grant 2013-03-31 13:37:02 +01:00
Alex Bilbie
a18b4184f5 getScopes() now have the grant type and client ID passed 2013-03-28 10:44:45 +00:00
Alex Bilbie
a7b4f7d66b Added grant to getClient calls. Fixes #21 2013-03-27 14:47:07 +00:00
Alex Bilbie
18933d5075 Merge branch 'feature/http-headers' into develop. Fixes #29 2013-03-27 14:27:47 +00:00
Alex Bilbie
d53abc661c getExceptionHttpHeaders() unit tests 2013-03-27 14:27:06 +00:00
Alex Bilbie
3481ec8aa2 Variable name fixes + little changes to support unit tests 2013-03-27 14:26:46 +00:00
ziege
e563230f10 Method to get all headers for the error response
Method added to get all required headers for the error response, according to the RFC - the correct HTTP status code and the "WWW-Authenticate" header in special cases.
2013-03-27 13:33:09 +00:00
Alex Bilbie
28f85e3bea Fixed broken unit test. Fixes #28 2013-03-27 13:29:11 +00:00
ziege
4cb4d5ba21 Refresh token removed in Client Credentials Grant
As defined in RFC: http://tools.ietf.org/html/rfc6749#section-4.4.3
2013-03-27 13:25:58 +00:00
Alex Bilbie
be478561b6 Fixed unit tests following 74d9946db3 2013-03-22 16:28:45 +00:00
Alex Bilbie
608fdb3ac3 Merge pull request #26 from ziege/patch-1
Storage corrected
2013-03-22 09:27:14 -07:00
ziege
74d9946db3 Storage corrected
Wrong client storage replaced with session storage
2013-03-22 17:24:36 +01:00
Alex Bilbie
521e5b22aa Updated unit tests 2013-03-22 12:43:53 +00:00
Alex Bilbie
85312f6995 Updated ClientCredentials to properly include scopes 2013-03-22 12:36:18 +00:00
Alex Bilbie
f463eb9db1 Style fixes 2013-03-22 11:44:53 +00:00
Alex Bilbie
f4cdfa91c1 Updated Password grant 2013-03-22 11:41:04 +00:00
Alex Bilbie
fe6ecb1dcf Added test_issueAccessToken_HTTP_auth(). Fixes #22 2013-03-22 11:08:52 +00:00
Alex Bilbie
0bf2a5333a Added test_scopeParamRequired() 2013-03-22 11:07:55 +00:00
Alex Bilbie
105a5b2a31 Fixed client_id and client_secret retrieval from request in conformity with the RFC 2013-03-22 10:40:47 +00:00
Alex Bilbie
ecf2f2b9ea Updated ResourceServerTest 2013-03-22 10:37:01 +00:00
Alex Bilbie
493834fcbf Removed base64 decoding of token when present in authorization header. Fixes #23 2013-03-22 10:35:42 +00:00
Alex Bilbie
fb518715ce Updated authserver tests 2013-03-21 16:25:44 +00:00
Alex Bilbie
fce24aa74d Added getDefaultScope method 2013-03-21 16:22:44 +00:00
Alex Bilbie
0c30b9ca66 Added scopeParamRequired method 2013-03-21 16:22:29 +00:00
Alex Bilbie
03aa81450e Renamed method to setDefaultScope 2013-03-21 16:22:16 +00:00
Michael Gooden
6c34535155 First test case.
Signed-off-by: Michael Gooden <michael@bluepointweb.com>
2013-03-21 14:47:32 +00:00
Michael Gooden
5bd62fe942 Add optional default scope parameter.
Signed-off-by: Michael Gooden <me@michaelgooden.net>
2013-03-21 14:47:29 +00:00
lapause
26781d2c38 Corrected wrong return documentation for SessionInterface::validateAuthCode() method 2013-03-21 14:42:51 +00:00
lapause
18e1bb33de Added missing details (return values on failure) to methods of SessionInterface 2013-03-21 14:42:47 +00:00
lapause
3a6468897f Removed obsolete namespace inclusion 2013-03-21 14:42:43 +00:00
lapause
97484eea6a Typo correction in inline doc 2013-03-21 14:42:38 +00:00
Alex Bilbie
a2f87f20b7 Version bump 2013-03-18 16:48:38 +00:00
Alex Bilbie
b6ba08813d Small bug fixes. Fixes #13 2013-03-18 16:46:07 +00:00
Alex Bilbie
3341728eb2 Added implicit grant 2013-03-06 18:01:44 +00:00
Alex Bilbie
6b172d4c27 Made getGrantType public for use with implicit grant 2013-03-06 18:01:34 +00:00
Alex Bilbie
4962762c28 Change from static calls 2013-03-06 18:01:12 +00:00
Alex Bilbie
56b559894c Spelling fix 2013-03-06 17:57:48 +00:00
Alex Bilbie
a9a68a5cc8 Added scope parameter association for clientcredentials and password scope
TODO: Unit tests
2013-03-06 17:18:48 +00:00
Alex Bilbie
542ca52d49 Set a default parameter for getParam 2013-03-06 17:18:13 +00:00
Alex Bilbie
7d0c075b36 It ain't static anymore Jim 2013-03-06 17:18:04 +00:00
Alex Bilbie
c056be3e48 Updated .travis.yml 2013-03-06 17:05:07 +00:00
Alex Bilbie
f3e6f99696 Removed old build files 2013-03-06 17:04:49 +00:00
Alex Bilbie
3ad4010526 Cleaned up .gitignore 2013-03-06 17:04:31 +00:00
Alex Bilbie
07c07ccb5e Removed static functions, inject authserver instance into grants 2013-03-06 16:59:18 +00:00
Alex Bilbie
6a8f8bf7b7 Removed phpunit from composer.json 2013-03-06 16:58:29 +00:00
Alex Bilbie
4917bc228c Updated .gitignore 2013-03-06 16:57:29 +00:00
Alex Bilbie
b58082b536 Merge pull request #10 from MichaelGooden/patch-1
Fix state parameter check typo
2013-03-04 07:43:33 -08:00
Michael Gooden
f70c039275 Fix state parameter check typo 2013-03-04 17:31:59 +02:00
Alex Bilbie
f102b4fb68 Merge branch 'master' of github.com:lncd/OAuth2 2013-03-04 13:22:44 +00:00
Alex Bilbie
c003f699c7 1.0.7 merge 2013-03-04 13:22:01 +00:00
Alex Bilbie
ad78ec838b Version bump 2013-03-04 13:18:34 +00:00
Alex Bilbie
34a7d14557 Added requireStateParam() method. Fixes #9 2013-03-04 13:15:12 +00:00
Alex Bilbie
f5b6b43bef Added requireScopes() method 2013-03-04 13:10:00 +00:00
Michael Gooden
3be3794311 Normalise long function definition.
Signed-off-by: Michael Gooden <michael@bluepointweb.com>
2013-03-04 12:20:11 +00:00
Michael Gooden
710c65aa42 Fix typo in SessionInterface::validateAuthCode. 2013-03-04 12:20:11 +00:00
Alex Bilbie
7d3712a4b1 Added tutorial section 2013-02-28 17:03:15 +00:00
Alex Bilbie
d6955922e9 Added description of grants link 2013-02-28 16:26:06 +00:00
Alex Bilbie
352d49ec5a Fixed broken tests 2013-02-22 16:56:17 +00:00
Alex Bilbie
88616853c4 Fixed broken tests 2013-02-22 16:55:42 +00:00
Alex Bilbie
8eb7dc0d76 Spelling fix 2013-02-22 15:45:49 +00:00
Alex Bilbie
4cc3f97569 Spelling fix 2013-02-22 15:45:42 +00:00
Alex Bilbie
e6545f9dca Merge branch 'release/1.0.6' into develop 2013-02-22 15:42:47 +00:00
Alex Bilbie
7b1b5e94cb Merge branch 'release/1.0.6' 2013-02-22 15:42:38 +00:00
Alex Bilbie
eceb84b978 Version bump 2013-02-22 15:42:32 +00:00
Alex Bilbie
ffac434bcc Added missing state parameter 2013-02-22 15:38:47 +00:00
Alex Bilbie
e74e5061d8 Added tutorial links 2013-02-22 15:21:24 +00:00
Alex Bilbie
cb523e7e34 Added tutorial links 2013-02-22 13:31:05 +00:00
Alex Bilbie
da12c09fda Merge branch 'release/1.0.5' into develop 2013-02-21 17:52:10 +00:00
135 changed files with 8728 additions and 3769 deletions

3
.gitattributes vendored
View File

@@ -1,4 +1,5 @@
tests/ export-ignore
phpunit.xml export-ignore
build.xml export-ignore
test export-ignore
test export-ignore
.travis.yml export-ignore

20
.gitignore vendored
View File

@@ -1,8 +1,14 @@
/vendor/
/vendor
/composer.lock
/docs/build/
/build/logs/
/build/coverage/
test
/docs/
/testing/
/build
/docs
/testing
/examples/relational/vendor
/examples/relational/config/oauth2.sqlite3
/examples/nosql/vendor
/examples/nosql/config/oauth2.sqlite3
/examples/relational/composer.lock
/tests/codecept/tests/_log
oauth2-server.paw
/output_*/
/_site

37
.scrutinizer.yml Normal file
View File

@@ -0,0 +1,37 @@
filter:
excluded_paths:
- tests/*
- vendor/*
- examples/*
checks:
php:
code_rating: true
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true
tools:
external_code_coverage:
timeout: 600
runs: 3
php_code_coverage: false
php_code_sniffer:
config:
standard: PSR2
filter:
paths: ['src']
php_loc:
enabled: true
excluded_dirs: [vendor, tests, examples]
php_cpd:
enabled: true
excluded_dirs: [vendor, tests, examples]

View File

@@ -1,8 +1,19 @@
language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
before_script: composer install --dev
script: phpunit -c build/phpunit.xml
before_script:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --prefer-source --dev
script:
- mkdir -p build/logs
- phpunit --coverage-text --verbose --coverage-clover=coverage.clover
after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover

View File

@@ -1,5 +1,112 @@
# Changelog
## 4.0.0 (released 2014-11-08)
* Complete rewrite
* Check out the documentation - [http://oauth2.thephpleague.com](http://oauth2.thephpleague.com)
## 3.2.0 (released 2014-04-16)
* Added the ability to change the algorithm that is used to generate the token strings (Issue #151)
## 3.1.2 (released 2014-02-26)
* Support Authorization being an environment variable. [See more](http://fortrabbit.com/docs/essentials/quirks-and-constraints#authorization-header)
## 3.1.1 (released 2013-12-05)
* Normalize headers when `getallheaders()` is available (Issues #108 and #114)
## 3.1.0 (released 2013-12-05)
* No longer necessary to inject the authorisation server into a grant, the server will inject itself
* Added test for 1419ba8cdcf18dd034c8db9f7de86a2594b68605
## 3.0.1 (released 2013-12-02)
* Forgot to tell TravisCI from testing PHP 5.3
## 3.0.0 (released 2013-12-02)
* Fixed spelling of Implicit grant class (Issue #84)
* Travis CI now tests for PHP 5.5
* Fixes for checking headers for resource server (Issues #79 and #)
* The word "bearer" now has a capital "B" in JSON output to match OAuth 2.0 spec
* All grants no longer remove old sessions by default
* All grants now support custom access token TTL (Issue #92)
* All methods which didn't before return a value now return `$this` to support method chaining
* Removed the build in DB providers - these will be put in their own repos to remove baggage in the main repository
* Removed support for PHP 5.3 because this library now uses traits and will use other modern PHP features going forward
* Moved some grant related functions into a trait to reduce duplicate code
## 2.1.1 (released 2013-06-02)
* Added conditional `isValid()` flag to check for Authorization header only (thanks @alexmcroberts)
* Fixed semantic meaning of `requireScopeParam()` and `requireStateParam()` by changing their default value to true
* Updated some duff docblocks
* Corrected array key call in Resource.php (Issue #63)
## 2.1 (released 2013-05-10)
* Moved zetacomponents/database to "suggest" in composer.json. If you rely on this feature you now need to include " zetacomponents/database" into "require" key in your own composer.json. (Issue #51)
* New method in Refresh grant called `rotateRefreshTokens()`. Pass in `true` to issue a new refresh token each time an access token is refreshed. This parameter needs to be set to true in order to request reduced scopes with the new access token. (Issue #47)
* Rename `key` column in oauth_scopes table to `scope` as `key` is a reserved SQL word. (Issue #45)
* The `scope` parameter is no longer required by default as per the RFC. (Issue #43)
* You can now set multiple default scopes by passing an array into `setDefaultScope()`. (Issue #42)
* The password and client credentials grants now allow for multiple sessions per user. (Issue #32)
* Scopes associated to authorization codes are not held in their own table (Issue #44)
* Database schema updates.
## 2.0.5 (released 2013-05-09)
* Fixed `oauth_session_token_scopes` table primary key
* Removed `DEFAULT ''` that has slipped into some tables
* Fixed docblock for `SessionInterface::associateRefreshToken()`
## 2.0.4 (released 2013-05-09)
* Renamed primary key in oauth_client_endpoints table
* Adding missing column to oauth_session_authcodes
* SECURITY FIX: A refresh token should be bound to a client ID
## 2.0.3 (released 2013-05-08)
* Fixed a link to code in composer.json
## 2.0.2 (released 2013-05-08)
* Updated README with wiki guides
* Removed `null` as default parameters in some methods in the storage interfaces
* Fixed license copyright
## 2.0.0 (released 2013-05-08)
**If you're upgrading from v1.0.8 there are lots of breaking changes**
* Rewrote the session storage interface from scratch so methods are more obvious
* Included a PDO driver which implements the storage interfaces so the library is more "get up and go"
* Further normalised the database structure so all sessions no longer contain infomation related to authorization grant (which may or may not be enabled)
* A session can have multiple associated access tokens
* Induvidual grants can have custom expire times for access tokens
* Authorization codes now have a TTL of 10 minutes by default (can be manually set)
* Refresh tokens now have a TTL of one week by default (can be manually set)
* The client credentials grant will no longer gives out refresh tokens as per the specification
## 1.0.8 (released 2013-03-18)
* Fixed check for required state parameter
* Fixed check that user's credentials are correct in Password grant
## 1.0.7 (released 2013-03-04)
* Added method `requireStateParam()`
* Added method `requireScopeParam()`
## 1.0.6 (released 2013-02-22)
* Added links to tutorials in the README
* Added missing `state` parameter request to the `checkAuthoriseParams()` method.
## 1.0.5 (released 2013-02-21)
* Fixed the SQL example for SessionInterface::getScopes()
@@ -19,4 +126,4 @@
## 1.0.0 (released 2013-02-15)
* First release
* First major release

15
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,15 @@
Thanks for contributing to this project.
**Please submit your pull request against the `develop` branch only.**
Please ensure that you run `phpunit` from the project root after you've made any changes.
If you've added something new please create a new unit test, if you've changed something please update any unit tests as appropritate.
We're trying to ensure there is **100%** test code coverage (including testing PHP errors and exceptions) so please ensure any new/updated tests cover all of your changes.
Thank you,
@alexbilbie

View File

@@ -1,52 +1,72 @@
# PHP OAuth Framework
# PHP OAuth 2.0 Server by [@alexbilbie](https://twitter.com/alexbilbie)
The goal of this project is to develop a standards compliant [OAuth 2](http://tools.ietf.org/wg/oauth/draft-ietf-oauth-v2/) authorization server and resource server.
[![Latest Version](http://img.shields.io/packagist/v/league/oauth2-server.svg?style=flat-square)](https://github.com/thephpleague/oauth2-server/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/thephpleague/oauth2-server/master.svg?style=flat-square)](https://travis-ci.org/thephpleague/oauth2-server)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/thephpleague/oauth2-server.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/oauth2-server/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/thephpleague/oauth2-server.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/oauth2-server)
[![Total Downloads](https://img.shields.io/packagist/dt/league/oauth2-server.svg?style=flat-square)](https://packagist.org/packages/league/oauth2-server)
## Package Installation
The framework is provided as a Composer package which can be installed by adding the package to your composer.json file:
A standards compliant [OAuth 2.0](http://tools.ietf.org/wg/oauth/draft-ietf-oauth-v2/) authorization server and resource server written in PHP which makes working with OAuth 2.0 trivial. You can easily configure an OAuth 2.0 server to protect your API with access tokens, or allow clients to request new access tokens and refresh them.
```javascript
{
"require": {
"lncd/OAuth2": "*"
}
}
```
It supports out of the box the following grants:
---
* Authorization code grant
* Client credentials grant
* Resource owner password credentials grant
* Refresh grant
The library features 100% unit test code coverage. To run the tests yourself run `phpunit -c build/phpunit.xml`.
You can also define your own grants.
## Current Features
In addition it supports the following token types:
### Authorization Server
* Bearer tokens
* MAC tokens (coming soon)
* JSON web tokens (coming soon)
The authorization server is a flexible class and following core specification grants are implemented:
* authorization code ([section 4.1](http://tools.ietf.org/html/rfc6749#section-4.1))
* refresh token ([section 6](http://tools.ietf.org/html/rfc6749#section-6))
* client credentials ([section 2.3.1](http://tools.ietf.org/html/rfc6749#section-2.3.1))
* password (user credentials) ([section 4.3](http://tools.ietf.org/html/rfc6749#section-4.3))
## Requirements
### Resource Server
The following versions of PHP are supported:
The resource server allows you to secure your API endpoints by checking for a valid OAuth access token in the request and ensuring the token has the correct permission to access resources.
* PHP 5.4
* PHP 5.5
* PHP 5.6
* HHVM
## Future Goals
## Documentation
### Authorization Server
This library has [full documentation](http://oauth2.thephpleague.com), powered by [Jekyll](http://jekyllrb.com/).
* Support for [JSON web tokens](http://tools.ietf.org/wg/oauth/draft-ietf-oauth-json-web-token/).
* Support for [SAML assertions](http://tools.ietf.org/wg/oauth/draft-ietf-oauth-saml2-bearer/).
Contribute to this documentation in the [gh-pages branch](https://github.com/thephpleague/oauth2-server/tree/gh-pages/).
---
## Changelog
This code will be developed as part of the [Linkey](http://linkey.blogs.lincoln.ac.uk) project which has been funded by [JISC](http://jisc.ac.uk) under the Access and Identity Management programme.
[See the project releases page](https://github.com/thephpleague/oauth2-server/releases)
This code was principally developed by [Alex Bilbie](http://alexbilbie.com/) ([Twitter](https://twitter.com/alexbilbie)|[Github](https://github.com/alexbilbie)).
## Contributing
Valuable contribtions have been made by the following:
Please see [CONTRIBUTING](https://github.com/thephpleague/oauth2-server/blob/master/CONTRIBUTING.md) for details.
* [Dan Horrigan](http://dandoescode.com) ([Twitter](https://twitter.com/dandoescode)|[Github](https://github.com/dandoescode))
* [Nick Jackson](http://nickjackson.me) ([Twitter](https://twitter.com/jacksonj04)|[Github](https://github.com/jacksonj04))
## Support
Bugs and feature request are tracked on [GitHub](https://github.com/thephpleague/oauth2-server/issues)
## License
This package is released under the MIT License. See the bundled [LICENSE](https://github.com/thephpleague/oauth2-server/blob/master/LICENSE) file for details.
## Credits
This code is principally developed and maintained by [Alex Bilbie](https://twitter.com/alexbilbie).
Special thanks to:
* [Dan Horrigan](https://github.com/dandoescode)
* [Nick Jackson](https://github.com/jacksonj04)
* [Michael Gooden](https://github.com/MichaelGooden)
* [Phil Sturgeon](https://github.com/philsturgeon)
* [and all the other contributors](https://github.com/thephpleague/oauth2-server/contributors)
The initial code was developed as part of the [Linkey](http://linkey.blogs.lincoln.ac.uk) project which was funded by [JISC](http://jisc.ac.uk) under the Access and Identity Management programme.

142
build.xml
View File

@@ -1,142 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="PHP OAuth 2.0 Server" default="build">
<target name="build" depends="prepare,lint,phploc,pdepend,phpmd-ci,phpcs-ci,phpcpd,composer,phpunit,phpdox,phpcb"/>
<target name="build-parallel" depends="prepare,lint,tools-parallel,phpcb"/>
<target name="minimal" depends="prepare,lint,phploc,pdepend,phpcpd,composer,phpunit,phpdox,phpcb" />
<target name="tools-parallel" description="Run tools in parallel">
<parallel threadCount="2">
<sequential>
<antcall target="pdepend"/>
<antcall target="phpmd-ci"/>
</sequential>
<antcall target="phpcpd"/>
<antcall target="phpcs-ci"/>
<antcall target="phploc"/>
<antcall target="phpdox"/>
</parallel>
</target>
<target name="clean" description="Cleanup build artifacts">
<delete dir="${basedir}/build/api"/>
<delete dir="${basedir}/build/code-browser"/>
<delete dir="${basedir}/build/coverage"/>
<delete dir="${basedir}/build/logs"/>
<delete dir="${basedir}/build/pdepend"/>
</target>
<target name="prepare" depends="clean" description="Prepare for build">
<mkdir dir="${basedir}/build/api"/>
<mkdir dir="${basedir}/build/code-browser"/>
<mkdir dir="${basedir}/build/coverage"/>
<mkdir dir="${basedir}/build/logs"/>
<mkdir dir="${basedir}/build/pdepend"/>
<mkdir dir="${basedir}/build/phpdox"/>
</target>
<target name="lint">
<apply executable="php" failonerror="true">
<arg value="-l" />
<fileset dir="${basedir}/src">
<include name="**/*.php" />
<modified />
</fileset>
</apply>
</target>
<target name="phploc" description="Measure project size using PHPLOC">
<exec executable="phploc">
<arg value="--log-csv" />
<arg value="${basedir}/build/logs/phploc.csv" />
<arg path="${basedir}/src" />
</exec>
</target>
<target name="pdepend" description="Calculate software metrics using PHP_Depend">
<exec executable="pdepend">
<arg value="--jdepend-xml=${basedir}/build/logs/jdepend.xml" />
<arg value="--jdepend-chart=${basedir}/build/pdepend/dependencies.svg" />
<arg value="--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg" />
<arg path="${basedir}/src" />
</exec>
</target>
<target name="phpmd" description="Perform project mess detection using PHPMD and print human readable output. Intended for usage on the command line before committing.">
<exec executable="phpmd">
<arg path="${basedir}/src" />
<arg value="text" />
<arg value="${basedir}/build/phpmd.xml" />
</exec>
</target>
<target name="phpmd-ci" description="Perform project mess detection using PHPMD creating a log file for the continuous integration server">
<exec executable="phpmd">
<arg path="${basedir}/src" />
<arg value="xml" />
<arg value="${basedir}/build/phpmd.xml" />
<arg value="--reportfile" />
<arg value="${basedir}/build/logs/pmd.xml" />
</exec>
</target>
<target name="phpcs" description="Find coding standard violations using PHP_CodeSniffer and print human readable output. Intended for usage on the command line before committing.">
<exec executable="phpcs">
<arg value="--standard=${basedir}/build/phpcs.xml" />
<arg value="--extensions=php" />
<arg value="--ignore=third_party/CIUnit" />
<arg path="${basedir}/src" />
</exec>
</target>
<target name="phpcs-ci" description="Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server">
<exec executable="phpcs" output="/dev/null">
<arg value="--report=checkstyle" />
<arg value="--report-file=${basedir}/build/logs/checkstyle.xml" />
<arg value="--standard=${basedir}/build/phpcs.xml" />
<arg value="--extensions=php" />
<arg value="--ignore=third_party/CIUnit" />
<arg path="${basedir}/src" />
</exec>
</target>
<target name="phpcpd" description="Find duplicate code using PHPCPD">
<exec executable="phpcpd">
<arg value="--log-pmd" />
<arg value="${basedir}/build/logs/pmd-cpd.xml" />
<arg path="${basedir}/src" />
</exec>
</target>
<target name="composer" description="Install Composer requirements">
<exec executable="composer.phar" failonerror="true">
<arg value="install" />
<arg value="--dev" />
</exec>
</target>
<target name="phpunit" description="Run unit tests with PHPUnit">
<exec executable="${basedir}/vendor/bin/phpunit" failonerror="true">
<arg value="--configuration" />
<arg value="${basedir}/build/phpunit.xml" />
</exec>
</target>
<target name="phpdox" description="Generate API documentation using phpDox">
<exec executable="phpdox"/>
</target>
<target name="phpcb" description="Aggregate tool output with PHP_CodeBrowser">
<exec executable="phpcb">
<arg value="--log" />
<arg path="${basedir}/build/logs" />
<arg value="--source" />
<arg path="${basedir}/src" />
<arg value="--output" />
<arg path="${basedir}/build/code-browser" />
</exec>
</target>
</project>

View File

@@ -1,8 +0,0 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<description>PHP_CodeSniffer configuration</description>
<rule ref="PSR2"/>
</ruleset>

View File

@@ -1,14 +0,0 @@
<ruleset name="OAuth 2.0 Server"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
Ruleset for OAuth 2.0 server
</description>
<!-- Import the entire unused code rule set -->
<rule ref="rulesets/unusedcode.xml" />
</ruleset>

View File

@@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" bootstrap="../tests/Bootstrap.php">
<testsuites>
<testsuite name="Authorization Server">
<directory suffix="Test.php">../tests/authorization</directory>
</testsuite>
<testsuite name="Resource Server">
<directory suffix="Test.php">../tests/resource</directory>
</testsuite>
<testsuite name="Utility Methods">
<directory suffix="Test.php">../tests/util</directory>
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory suffix=".php">PEAR_INSTALL_DIR</directory>
<directory suffix=".php">PHP_LIBDIR</directory>
<directory suffix=".php">../vendor/composer</directory>
<directory suffix=".php">../vendor/mockery</directory>
<directory suffix=".php">../vendor/phpunit</directory>
<directory suffix=".php">../tests</directory>
<directory suffix=".php">../testing</directory>
</blacklist>
</filter>
<logging>
<log type="coverage-html" target="coverage" title="lncd/OAuth" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="90"/>
<log type="coverage-text" target="php://stdout" title="lncd/OAuth" charset="UTF-8" yui="true" highlight="true" lowUpperBound="50" highLowerBound="90"/>
<log type="coverage-clover" target="logs/clover.xml"/>
<log type="junit" target="logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
</phpunit>

View File

@@ -1,30 +1,38 @@
{
"name": "lncd/oauth2",
"description": "OAuth 2.0 Framework",
"version": "1.0.5",
"homepage": "https://github.com/lncd/OAuth2",
"name": "league/oauth2-server",
"description": "A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.",
"homepage": "http://oauth2.thephpleague.com/",
"license": "MIT",
"require": {
"php": ">=5.3.0"
"php": ">=5.4.0",
"symfony/http-foundation": "~2.5",
"league/event": "1.0.*"
},
"require-dev": {
"phpunit/phpunit": "*",
"mockery/mockery": ">=0.7.2"
"phpunit/phpunit": "4.3.*",
"mockery/mockery": "0.9.*"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/lncd/OAuth2"
"url": "https://github.com/thephpleague/oauth2-server.git"
}
],
"keywords": [
"oauth",
"oauth2",
"oauth 2",
"oauth 2.0",
"server",
"auth",
"authorization",
"authorisation",
"authentication",
"resource",
"api"
"api",
"auth",
"protect",
"secure"
],
"authors": [
{
@@ -34,10 +42,23 @@
"role": "Developer"
}
],
"replace": {
"lncd/oauth2": "*",
"league/oauth2server": "*"
},
"autoload": {
"psr-0": {
"OAuth2": "src/"
"psr-4": {
"League\\OAuth2\\Server\\": "src/"
}
},
"suggest": {}
"autoload-dev": {
"psr-4": {
"LeagueTests\\": "tests/unit/"
}
},
"extra": {
"branch-alias": {
"dev-develop": "4.0.x-dev"
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace RelationalExample\Model;
use Illuminate\Database\Capsule\Manager as Capsule;
class Users
{
public function get($username = null)
{
$query = Capsule::table('users')->select(['username', 'password', 'name', 'email', 'photo']);
if ($username !== null) {
$query->where('username', '=', $username);
}
$result = $query->get();
if (count($result) > 0) {
return $result;
}
return null;
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace RelationalExample\Storage;
use League\OAuth2\Server\Storage\AccessTokenInterface;
use League\OAuth2\Server\Storage\Adapter;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\AbstractTokenEntity;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Entity\ScopeEntity;
use Illuminate\Database\Capsule\Manager as Capsule;
class AccessTokenStorage extends Adapter implements AccessTokenInterface
{
/**
* {@inheritdoc}
*/
public function get($token)
{
$result = Capsule::table('oauth_access_tokens')
->where('access_token', $token)
->get();
if (count($result) === 1) {
$token = (new AccessTokenEntity($this->server))
->setId($result[0]['access_token'])
->setExpireTime($result[0]['expire_time']);
return $token;
}
return null;
}
/**
* {@inheritdoc}
*/
public function getScopes(AbstractTokenEntity $token)
{
$result = Capsule::table('oauth_access_token_scopes')
->select(['oauth_scopes.id', 'oauth_scopes.description'])
->join('oauth_scopes', 'oauth_access_token_scopes.scope', '=', 'oauth_scopes.id')
->where('access_token', $token->getId())
->get();
$response = [];
if (count($result) > 0) {
foreach ($result as $row) {
$scope = (new ScopeEntity($this->server))->hydrate([
'id' => $row['id'],
'description' => $row['description']
]);
$response[] = $scope;
}
}
return $response;
}
/**
* {@inheritdoc}
*/
public function create($token, $expireTime, $sessionId)
{
Capsule::table('oauth_access_tokens')
->insert([
'access_token' => $token,
'session_id' => $sessionId,
'expire_time' => $expireTime
]);
}
/**
* {@inheritdoc}
*/
public function associateScope(AbstractTokenEntity $token, ScopeEntity $scope)
{
Capsule::table('oauth_access_token_scopes')
->insert([
'access_token' => $token->getId(),
'scope' => $scope->getId()
]);
}
/**
* {@inheritdoc}
*/
public function delete(AbstractTokenEntity $token)
{
Capsule::table('oauth_access_token_scopes')
->where('access_token', $token->getId())
->delete();
}
}

View File

@@ -0,0 +1,92 @@
<?php
namespace RelationalExample\Storage;
use League\OAuth2\Server\Storage\AuthCodeInterface;
use League\OAuth2\Server\Storage\Adapter;
use League\OAuth2\Server\Entity\AuthCodeEntity;
use League\OAuth2\Server\Entity\ScopeEntity;
use Illuminate\Database\Capsule\Manager as Capsule;
class AuthCodeStorage extends Adapter implements AuthCodeInterface
{
/**
* {@inheritdoc}
*/
public function get($code)
{
$result = Capsule::table('oauth_auth_codes')
->where('auth_code', $code)
->where('expire_time', '>=', time())
->get();
if (count($result) === 1) {
$token = new AuthCodeEntity($this->server);
$token->setId($result[0]['auth_code']);
$token->setRedirectUri($result[0]['client_redirect_uri']);
return $token;
}
return null;
}
public function create($token, $expireTime, $sessionId, $redirectUri)
{
Capsule::table('oauth_auth_codes')
->insert([
'auth_code' => $token,
'client_redirect_uri' => $redirectUri,
'session_id' => $sessionId,
'expire_time' => $expireTime
]);
}
/**
* {@inheritdoc}
*/
public function getScopes(AuthCodeEntity $token)
{
$result = Capsule::table('oauth_auth_code_scopes')
->select(['oauth_scopes.id', 'oauth_scopes.description'])
->join('oauth_scopes', 'oauth_auth_code_scopes.scope', '=', 'oauth_scopes.id')
->where('auth_code', $token->getId())
->get();
$response = [];
if (count($result) > 0) {
foreach ($result as $row) {
$scope = (new ScopeEntity($this->server))->hydrate([
'id' => $row['id'],
'description' => $row['description']
]);
$response[] = $scope;
}
}
return $response;
}
/**
* {@inheritdoc}
*/
public function associateScope(AuthCodeEntity $token, ScopeEntity $scope)
{
Capsule::table('oauth_auth_code_scopes')
->insert([
'auth_code' => $token->getId(),
'scope' => $scope->getId()
]);
}
/**
* {@inheritdoc}
*/
public function delete(AuthCodeEntity $token)
{
Capsule::table('oauth_auth_codes')
->where('auth_code', $token->getId())
->delete();
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace RelationalExample\Storage;
use League\OAuth2\Server\Storage\ClientInterface;
use League\OAuth2\Server\Storage\Adapter;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use Illuminate\Database\Capsule\Manager as Capsule;
class ClientStorage extends Adapter implements ClientInterface
{
/**
* {@inheritdoc}
*/
public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null)
{
$query = Capsule::table('oauth_clients')
->select('oauth_clients.*')
->where('oauth_clients.id', $clientId);
if ($clientSecret !== null) {
$query->where('oauth_clients.secret', $clientSecret);
}
if ($redirectUri) {
$query->join('oauth_client_redirect_uris', 'oauth_clients.id', '=', 'oauth_client_redirect_uris.client_id')
->select(['oauth_clients.*', 'oauth_client_redirect_uris.*'])
->where('oauth_client_redirect_uris.redirect_uri', $redirectUri);
}
$result = $query->get();
if (count($result) === 1) {
$client = new ClientEntity($this->server);
$client->hydrate([
'id' => $result[0]['id'],
'name' => $result[0]['name']
]);
return $client;
}
return null;
}
/**
* {@inheritdoc}
*/
public function getBySession(SessionEntity $session)
{
$result = Capsule::table('oauth_clients')
->select(['oauth_clients.id', 'oauth_clients.name'])
->join('oauth_sessions', 'oauth_clients.id', '=', 'oauth_sessions.client_id')
->where('oauth_sessions.id', $session->getId())
->get();
if (count($result) === 1) {
$client = new ClientEntity($this->server);
$client->hydrate([
'id' => $result[0]['id'],
'name' => $result[0]['name']
]);
return $client;
}
return null;
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace RelationalExample\Storage;
use League\OAuth2\Server\Storage\RefreshTokenInterface;
use League\OAuth2\Server\Storage\Adapter;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use Illuminate\Database\Capsule\Manager as Capsule;
class RefreshTokenStorage extends Adapter implements RefreshTokenInterface
{
/**
* {@inheritdoc}
*/
public function get($token)
{
$result = Capsule::table('oauth_refresh_tokens')
->where('refresh_token', $token)
->get();
if (count($result) === 1) {
$token = (new RefreshTokenEntity($this->server))
->setId($result[0]['refresh_token'])
->setExpireTime($result[0]['expire_time'])
->setAccessTokenId($result[0]['access_token']);
return $token;
}
return null;
}
/**
* {@inheritdoc}
*/
public function create($token, $expireTime, $accessToken)
{
Capsule::table('oauth_refresh_tokens')
->insert([
'refresh_token' => $token,
'access_token' => $accessToken,
'expire_time' => $expireTime
]);
}
/**
* {@inheritdoc}
*/
public function delete(RefreshTokenEntity $token)
{
Capsule::table('oauth_refresh_tokens')
->where('refresh_token', $token->getId())
->delete();
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace RelationalExample\Storage;
use League\OAuth2\Server\Storage\ScopeInterface;
use League\OAuth2\Server\Storage\Adapter;
use League\OAuth2\Server\Entity\ScopeEntity;
use Illuminate\Database\Capsule\Manager as Capsule;
class ScopeStorage extends Adapter implements ScopeInterface
{
/**
* {@inheritdoc}
*/
public function get($scope, $grantType = null, $clientId = null)
{
$result = Capsule::table('oauth_scopes')
->where('id', $scope)
->get();
if (count($result) === 0) {
return null;
}
return (new ScopeEntity($this->server))->hydrate([
'id' => $result[0]['id'],
'description' => $result[0]['description']
]);
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace RelationalExample\Storage;
use League\OAuth2\Server\Storage\SessionInterface;
use League\OAuth2\Server\Storage\Adapter;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\AuthCodeEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Entity\ScopeEntity;
use Illuminate\Database\Capsule\Manager as Capsule;
class SessionStorage extends Adapter implements SessionInterface
{
/**
* {@inheritdoc}
*/
public function getByAccessToken(AccessTokenEntity $accessToken)
{
$result = Capsule::table('oauth_sessions')
->select(['oauth_sessions.id', 'oauth_sessions.owner_type', 'oauth_sessions.owner_id', 'oauth_sessions.client_id', 'oauth_sessions.client_redirect_uri'])
->join('oauth_access_tokens', 'oauth_access_tokens.session_id', '=', 'oauth_sessions.id')
->where('oauth_access_tokens.access_token', $accessToken->getId())
->get();
if (count($result) === 1) {
$session = new SessionEntity($this->server);
$session->setId($result[0]['id']);
$session->setOwner($result[0]['owner_type'], $result[0]['owner_id']);
return $session;
}
return null;
}
/**
* {@inheritdoc}
*/
public function getByAuthCode(AuthCodeEntity $authCode)
{
$result = Capsule::table('oauth_sessions')
->select(['oauth_sessions.id', 'oauth_sessions.owner_type', 'oauth_sessions.owner_id', 'oauth_sessions.client_id', 'oauth_sessions.client_redirect_uri'])
->join('oauth_auth_codes', 'oauth_auth_codes.session_id', '=', 'oauth_sessions.id')
->where('oauth_auth_codes.auth_code', $authCode->getId())
->get();
if (count($result) === 1) {
$session = new SessionEntity($this->server);
$session->setId($result[0]['id']);
$session->setOwner($result[0]['owner_type'], $result[0]['owner_id']);
return $session;
}
return null;
}
/**
* {@inheritdoc}
*/
public function getScopes(SessionEntity $session)
{
$result = Capsule::table('oauth_sessions')
->select('oauth_scopes.*')
->join('oauth_session_scopes', 'oauth_sessions.id', '=', 'oauth_session_scopes.session_id')
->join('oauth_scopes', 'oauth_scopes.id', '=', 'oauth_session_scopes.scope')
->where('oauth_sessions.id', $session->getId())
->get();
$scopes = [];
foreach ($result as $scope) {
$scopes[] = (new ScopeEntity($this->server))->hydrate([
'id' => $scope['id'],
'description' => $scope['description']
]);
}
return $scopes;
}
/**
* {@inheritdoc}
*/
public function create($ownerType, $ownerId, $clientId, $clientRedirectUri = null)
{
$id = Capsule::table('oauth_sessions')
->insertGetId([
'owner_type' => $ownerType,
'owner_id' => $ownerId,
'client_id' => $clientId
]);
return $id;
}
/**
* {@inheritdoc}
*/
public function associateScope(SessionEntity $session, ScopeEntity $scope)
{
Capsule::table('oauth_session_scopes')
->insert([
'session_id' => $session->getId(),
'scope' => $scope->getId()
]);
}
}

145
examples/relational/api.php Normal file
View File

@@ -0,0 +1,145 @@
<?php
use \Orno\Http\Request;
use \Orno\Http\Response;
use \Orno\Http\JsonResponse;
use \Orno\Http\Exception\NotFoundException;
use \League\OAuth2\Server\ResourceServer;
use \RelationalExample\Storage;
use \RelationalExample\Model;
use Illuminate\Database\Capsule\Manager as Capsule;
use \League\Event\Emitter;
include __DIR__.'/vendor/autoload.php';
// Routing setup
$request = (new Request)->createFromGlobals();
$router = new \Orno\Route\RouteCollection;
$router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY);
// Set up the OAuth 2.0 resource server
$sessionStorage = new Storage\SessionStorage();
$accessTokenStorage = new Storage\AccessTokenStorage();
$clientStorage = new Storage\ClientStorage();
$scopeStorage = new Storage\ScopeStorage();
$server = new ResourceServer(
$sessionStorage,
$accessTokenStorage,
$clientStorage,
$scopeStorage
);
// Routing setup
$request = (new Request)->createFromGlobals();
$router = new \Orno\Route\RouteCollection;
// GET /tokeninfo
$router->get('/tokeninfo', function (Request $request) use ($server) {
$token = [
'owner_id' => $server->getOwnerId(),
'owner_type' => $server->getOwnerType(),
'access_token' => $server->getAccessToken(),
'client_id' => $server->getClientId(),
'scopes' => $server->getScopes()
];
return new Response(json_encode($token));
});
// GET /users
$router->get('/users', function (Request $request) use ($server) {
$results = (new Model\Users())->get();
$users = [];
foreach ($results as $result) {
$user = [
'username' => $result['username'],
'name' => $result['name']
];
if ($server->hasScope('email')) {
$user['email'] = $result['email'];
}
if ($server->hasScope('photo')) {
$user['photo'] = $result['photo'];
}
$users[] = $user;
}
return new Response(json_encode($users));
});
// GET /users/{username}
$router->get('/users/{username}', function (Request $request, $args) use ($server) {
$result = (new Model\Users())->get($args['username']);
if (count($result) === 0) {
throw new NotFoundException();
}
$user = [
'username' => $result[0]['username'],
'name' => $result[0]['name']
];
if ($server->hasScope('email')) {
$user['email'] = $result[0]['email'];
}
if ($server->hasScope('photo')) {
$user['photo'] = $result[0]['photo'];
}
return new Response(json_encode($user));
});
$dispatcher = $router->getDispatcher();
try {
// Check that access token is present
$server->isValidRequest(false);
// A successful response
$response = $dispatcher->dispatch(
$request->getMethod(),
$request->getPathInfo()
);
} catch (\Orno\Http\Exception $e) {
// A failed response
$response = $e->getJsonResponse();
$response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()]));
} catch (\League\OAuth2\Server\Exception\OAuthException $e) {
$response = new Response(json_encode([
'error' => $e->errorType,
'message' => $e->getMessage()
]), $e->httpStatusCode);
foreach ($e->getHttpHeaders() as $header) {
$response->headers($header);
}
} catch (\Exception $e) {
$response = new Orno\Http\Response;
$response->setStatusCode(500);
$response->setContent(json_encode(['status_code' => 500, 'message' => $e->getMessage()]));
} finally {
// Return the response
$response->headers->set('Content-type', 'application/json');
$response->send();
}

View File

@@ -0,0 +1,139 @@
<?php
use \Orno\Http\Request;
use \Orno\Http\Response;
use \Orno\Http\JsonResponse;
use \Orno\Http\Exception\NotFoundException;
use \League\OAuth2\Server\ResourceServer;
use \RelationalExample\Storage;
use \RelationalExample\Model;
use Illuminate\Database\Capsule\Manager as Capsule;
use \League\Event\Emitter;
include __DIR__.'/vendor/autoload.php';
// Routing setup
$request = (new Request)->createFromGlobals();
$router = new \Orno\Route\RouteCollection;
$router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY);
// Set up the OAuth 2.0 authorization server
$server = new \League\OAuth2\Server\AuthorizationServer;
$server->setSessionStorage(new Storage\SessionStorage);
$server->setAccessTokenStorage(new Storage\AccessTokenStorage);
$server->setRefreshTokenStorage(new Storage\RefreshTokenStorage);
$server->setClientStorage(new Storage\ClientStorage);
$server->setScopeStorage(new Storage\ScopeStorage);
$server->setAuthCodeStorage(new Storage\AuthCodeStorage);
$authCodeGrant = new \League\OAuth2\Server\Grant\AuthCodeGrant();
$server->addGrantType($authCodeGrant);
$refrehTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant();
$server->addGrantType($refrehTokenGrant);
// Routing setup
$request = (new Request)->createFromGlobals();
$router = new \Orno\Route\RouteCollection;
$router->get('/authorize', function (Request $request) use ($server) {
// First ensure the parameters in the query string are correct
try {
$authParams = $server->getGrantType('authorization_code')->checkAuthorizeParams();
} catch (\Exception $e) {
return new Response(
json_encode([
'error' => $e->errorType,
'message' => $e->getMessage()
]),
$e->httpStatusCode,
$e->getHttpHeaders()
);
}
// Normally at this point you would show the user a sign-in screen and ask them to authorize the requested scopes
// ...
// ...
// ...
// Create a new authorize request which will respond with a redirect URI that the user will be redirected to
$redirectUri = $server->getGrantType('authorization_code')->newAuthorizeRequest('user', 1, $authParams);
$response = new Response('', 200, [
'Location' => $redirectUri
]);
return $response;
});
$router->post('/access_token', function (Request $request) use ($server) {
try {
$response = $server->issueAccessToken();
return new Response(json_encode($response), 200);
} catch (\Exception $e) {
return new Response(
json_encode([
'error' => $e->errorType,
'message' => $e->getMessage()
]),
$e->httpStatusCode,
$e->getHttpHeaders()
);
}
});
$dispatcher = $router->getDispatcher();
try {
// A successful response
$response = $dispatcher->dispatch(
$request->getMethod(),
$request->getPathInfo()
);
} catch (\Orno\Http\Exception $e) {
// A failed response
$response = $e->getJsonResponse();
$response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()]));
} catch (\League\OAuth2\Server\Exception\OAuthException $e) {
$response = new Response(json_encode([
'error' => $e->errorType,
'message' => $e->getMessage()
]), $e->httpStatusCode);
foreach ($e->getHttpHeaders() as $header) {
$response->headers($header);
}
} catch (\Exception $e) {
$response = new Orno\Http\Response;
$response->setStatusCode(500);
$response->setContent(json_encode(['status_code' => 500, 'message' => $e->getMessage()]));
} finally {
// Return the response
$response->headers->set('Content-type', 'application/json');
$response->send();
}

View File

@@ -0,0 +1,17 @@
{
"require": {
"illuminate/database": "4.1.*",
"orno/route": "1.*",
"ircmaxell/password-compat": "1.0.2",
"league/event": "0.2.0"
},
"autoload": {
"psr-4": {
"League\\OAuth2\\Server\\": "../../src/",
"RelationalExample\\": "."
},
"files": [
"config/db.php"
]
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace RelationalExample\Config;
use Illuminate\Database\Capsule\Manager as Capsule;
include __DIR__.'/../vendor/autoload.php';
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'sqlite',
'database' => __DIR__.'/oauth2.sqlite3',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci'
]);
$capsule->setAsGlobal();

View File

@@ -0,0 +1,249 @@
<?php
namespace RelationalExample\Config;
use Illuminate\Database\Capsule\Manager as Capsule;
include __DIR__.'/../vendor/autoload.php';
@unlink(__DIR__.'/oauth2.sqlite3');
touch(__DIR__.'/oauth2.sqlite3');
Capsule::statement('PRAGMA foreign_keys = ON');
/******************************************************************************/
print 'Creating users table'.PHP_EOL;
Capsule::schema()->create('users', function ($table) {
$table->increments('id');
$table->string('username');
$table->string('password');
$table->string('name');
$table->string('email');
$table->string('photo');
});
Capsule::table('users')->insert([
'username' => 'alexbilbie',
'password' => password_hash('whisky', PASSWORD_DEFAULT),
'name' => 'Alex Bilbie',
'email' => 'hello@alexbilbie.com',
'photo' => 'https://s.gravatar.com/avatar/14902eb1dac66b8458ebbb481d80f0a3'
]);
Capsule::table('users')->insert([
'username' => 'philsturgeon',
'password' => password_hash('cider', PASSWORD_DEFAULT),
'name' => 'Phil Sturgeon',
'email' => 'email@philsturgeon.co.uk',
'photo' => 'https://s.gravatar.com/avatar/14df293d6c5cd6f05996dfc606a6a951'
]);
/******************************************************************************/
print 'Creating clients table'.PHP_EOL;
Capsule::schema()->create('oauth_clients', function ($table) {
$table->string('id');
$table->string('secret');
$table->string('name');
$table->primary('id');
});
Capsule::table('oauth_clients')->insert([
'id' => 'testclient',
'secret' => 'secret',
'name' => 'Test Client'
]);
/******************************************************************************/
print 'Creating client redirect uris table'.PHP_EOL;
Capsule::schema()->create('oauth_client_redirect_uris', function ($table) {
$table->increments('id');
$table->string('client_id');
$table->string('redirect_uri');
});
Capsule::table('oauth_client_redirect_uris')->insert([
'client_id' => 'testclient',
'redirect_uri' => 'http://example.com/redirect'
]);
/******************************************************************************/
print 'Creating scopes table'.PHP_EOL;
Capsule::schema()->create('oauth_scopes', function ($table) {
$table->string('id');
$table->string('description');
$table->primary('id');
});
Capsule::table('oauth_scopes')->insert([
'id' => 'basic',
'description' => 'Basic details about your account'
]);
Capsule::table('oauth_scopes')->insert([
'id' => 'email',
'description' => 'Your email address'
]);
Capsule::table('oauth_scopes')->insert([
'id' => 'photo',
'description' => 'Your photo'
]);
/******************************************************************************/
print 'Creating sessions table'.PHP_EOL;
Capsule::schema()->create('oauth_sessions', function ($table) {
$table->increments('id');
$table->string('owner_type');
$table->string('owner_id');
$table->string('client_id');
$table->string('client_redirect_uri')->nullable();
$table->foreign('client_id')->references('id')->on('oauth_clients')->onDelete('cascade');
});
Capsule::table('oauth_sessions')->insert([
'owner_type' => 'client',
'owner_id' => 'testclient',
'client_id' => 'testclient'
]);
Capsule::table('oauth_sessions')->insert([
'owner_type' => 'user',
'owner_id' => '1',
'client_id' => 'testclient'
]);
Capsule::table('oauth_sessions')->insert([
'owner_type' => 'user',
'owner_id' => '2',
'client_id' => 'testclient'
]);
/******************************************************************************/
print 'Creating access tokens table'.PHP_EOL;
Capsule::schema()->create('oauth_access_tokens', function ($table) {
$table->string('access_token')->primary();
$table->integer('session_id');
$table->integer('expire_time');
$table->foreign('session_id')->references('id')->on('oauth_sessions')->onDelete('cascade');
});
Capsule::table('oauth_access_tokens')->insert([
'access_token' => 'iamgod',
'session_id' => '1',
'expire_time' => time() + 86400
]);
Capsule::table('oauth_access_tokens')->insert([
'access_token' => 'iamalex',
'session_id' => '2',
'expire_time' => time() + 86400
]);
Capsule::table('oauth_access_tokens')->insert([
'access_token' => 'iamphil',
'session_id' => '3',
'expire_time' => time() + 86400
]);
/******************************************************************************/
print 'Creating refresh tokens table'.PHP_EOL;
Capsule::schema()->create('oauth_refresh_tokens', function ($table) {
$table->string('refresh_token')->primary();
$table->integer('expire_time');
$table->string('access_token');
$table->foreign('access_token')->references('id')->on('oauth_access_tokens')->onDelete('cascade');
});
/******************************************************************************/
print 'Creating auth codes table'.PHP_EOL;
Capsule::schema()->create('oauth_auth_codes', function ($table) {
$table->string('auth_code')->primary();
$table->integer('session_id');
$table->integer('expire_time');
$table->string('client_redirect_uri');
$table->foreign('session_id')->references('id')->on('oauth_sessions')->onDelete('cascade');
});
/******************************************************************************/
print 'Creating oauth access token scopes table'.PHP_EOL;
Capsule::schema()->create('oauth_access_token_scopes', function ($table) {
$table->increments('id');
$table->string('access_token');
$table->string('scope');
$table->foreign('access_token')->references('access_token')->on('oauth_access_tokens')->onDelete('cascade');
$table->foreign('scope')->references('id')->on('oauth_scopes')->onDelete('cascade');
});
Capsule::table('oauth_access_token_scopes')->insert([
'access_token' => 'iamgod',
'scope' => 'basic'
]);
Capsule::table('oauth_access_token_scopes')->insert([
'access_token' => 'iamgod',
'scope' => 'email'
]);
Capsule::table('oauth_access_token_scopes')->insert([
'access_token' => 'iamgod',
'scope' => 'photo'
]);
Capsule::table('oauth_access_token_scopes')->insert([
'access_token' => 'iamphil',
'scope' => 'email'
]);
Capsule::table('oauth_access_token_scopes')->insert([
'access_token' => 'iamalex',
'scope' => 'photo'
]);
/******************************************************************************/
print 'Creating oauth auth code scopes table'.PHP_EOL;
Capsule::schema()->create('oauth_auth_code_scopes', function ($table) {
$table->increments('id');
$table->string('auth_code');
$table->string('scope');
$table->foreign('auth_code')->references('auth_code')->on('oauth_auth_codes')->onDelete('cascade');
$table->foreign('scope')->references('id')->on('oauth_scopes')->onDelete('cascade');
});
/******************************************************************************/
print 'Creating oauth session scopes table'.PHP_EOL;
Capsule::schema()->create('oauth_session_scopes', function ($table) {
$table->increments('id');
$table->string('session_id');
$table->string('scope');
$table->foreign('session_id')->references('id')->on('oauth_sessions')->onDelete('cascade');
$table->foreign('scope')->references('id')->on('oauth_scopes')->onDelete('cascade');
});

View File

@@ -0,0 +1,114 @@
<?php
use \Orno\Http\Request;
use \Orno\Http\Response;
use \Orno\Http\JsonResponse;
use \Orno\Http\Exception\NotFoundException;
use \League\OAuth2\Server\ResourceServer;
use \RelationalExample\Storage;
use \RelationalExample\Model;
use Illuminate\Database\Capsule\Manager as Capsule;
use \League\Event\Emitter;
include __DIR__.'/vendor/autoload.php';
// Routing setup
$request = (new Request)->createFromGlobals();
$router = new \Orno\Route\RouteCollection;
$router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY);
// Set up the OAuth 2.0 authorization server
$server = new \League\OAuth2\Server\AuthorizationServer;
$server->setSessionStorage(new Storage\SessionStorage);
$server->setAccessTokenStorage(new Storage\AccessTokenStorage);
$server->setRefreshTokenStorage(new Storage\RefreshTokenStorage);
$server->setClientStorage(new Storage\ClientStorage);
$server->setScopeStorage(new Storage\ScopeStorage);
$server->setAuthCodeStorage(new Storage\AuthCodeStorage);
$clientCredentials = new \League\OAuth2\Server\Grant\ClientCredentialsGrant();
$server->addGrantType($clientCredentials);
$passwordGrant = new \League\OAuth2\Server\Grant\PasswordGrant();
$passwordGrant->setVerifyCredentialsCallback(function ($username, $password) {
$result = (new Model\Users())->get($username);
if (count($result) !== 1) {
return false;
}
if (password_verify($password, $result[0]['password'])) {
return $username;
}
return false;
});
$server->addGrantType($passwordGrant);
$refrehTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant();
$server->addGrantType($refrehTokenGrant);
// Routing setup
$request = (new Request)->createFromGlobals();
$router = new \Orno\Route\RouteCollection;
$router->post('/access_token', function (Request $request) use ($server) {
try {
$response = $server->issueAccessToken();
return new Response(json_encode($response), 200);
} catch (\Exception $e) {
return new Response(
json_encode([
'error' => $e->errorType,
'message' => $e->getMessage()
]),
$e->httpStatusCode,
$e->getHttpHeaders()
);
}
});
$dispatcher = $router->getDispatcher();
try {
// A successful response
$response = $dispatcher->dispatch(
$request->getMethod(),
$request->getPathInfo()
);
} catch (\Orno\Http\Exception $e) {
// A failed response
$response = $e->getJsonResponse();
$response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()]));
} catch (\League\OAuth2\Server\Exception\OAuthException $e) {
$response = new Response(json_encode([
'error' => $e->errorType,
'message' => $e->getMessage()
]), $e->httpStatusCode);
foreach ($e->getHttpHeaders() as $header) {
$response->headers($header);
}
} catch (\Exception $e) {
$response = new Orno\Http\Response;
$response->setStatusCode(500);
$response->setContent(json_encode(['status_code' => 500, 'message' => $e->getMessage()]));
} finally {
// Return the response
$response->headers->set('Content-type', 'application/json');
$response->send();
}

View File

@@ -1,20 +1,20 @@
MIT License
Copyright (C) 2012 University of Lincoln
Copyright (C) Alex Bilbie
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
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
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
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
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.

17
phpunit.xml Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnError="true" stopOnFailure="true" stopOnIncomplete="false" stopOnSkipped="false" bootstrap="tests/unit/Bootstrap.php">
<testsuites>
<testsuite name="Tests">
<directory>./tests/unit/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<!-- <log type="coverage-text" target="php://stdout" title="thephpleague/oauth2-server" charset="UTF-8" yui="true" highlight="true" lowUpperBound="60" highLowerBound="90"/> -->
<log type="coverage-html" target="build/coverage" title="thephpleague/oauth2-server" charset="UTF-8" yui="true" highlight="true" lowUpperBound="60" highLowerBound="90"/>
</logging>
</phpunit>

View File

View File

@@ -1,53 +0,0 @@
CREATE TABLE `oauth_clients` (
`id` varchar(40) NOT NULL DEFAULT '',
`secret` varchar(40) NOT NULL DEFAULT '',
`name` varchar(255) NOT NULL DEFAULT '',
`auto_approve` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `oauth_client_endpoints` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`client_id` varchar(40) NOT NULL DEFAULT '',
`redirect_uri` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `client_id` (`client_id`),
CONSTRAINT `oauth_client_endpoints_ibfk_1` FOREIGN KEY (`client_id`) REFERENCES `oauth_clients` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `oauth_sessions` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`client_id` varchar(40) NOT NULL DEFAULT '',
`redirect_uri` varchar(250) DEFAULT '',
`owner_type` enum('user','client') NOT NULL DEFAULT 'user',
`owner_id` varchar(255) DEFAULT '',
`auth_code` varchar(40) DEFAULT '',
`access_token` varchar(40) DEFAULT '',
`refresh_token` varchar(40) DEFAULT '',
`access_token_expires` int(10) DEFAULT NULL,
`stage` enum('requested','granted') NOT NULL DEFAULT 'requested',
`first_requested` int(10) unsigned NOT NULL,
`last_updated` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `client_id` (`client_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `oauth_scopes` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`scope` varchar(255) NOT NULL DEFAULT '',
`name` varchar(255) NOT NULL DEFAULT '',
`description` varchar(255) DEFAULT '',
PRIMARY KEY (`id`),
UNIQUE KEY `scope` (`scope`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `oauth_session_scopes` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`session_id` int(11) unsigned NOT NULL,
`scope_id` int(11) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `session_id` (`session_id`),
KEY `scope_id` (`scope_id`),
CONSTRAINT `oauth_session_scopes_ibfk_5` FOREIGN KEY (`scope_id`) REFERENCES `oauth_scopes` (`id`) ON DELETE CASCADE,
CONSTRAINT `oauth_session_scopes_ibfk_4` FOREIGN KEY (`session_id`) REFERENCES `oauth_sessions` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

302
src/AbstractServer.php Normal file
View File

@@ -0,0 +1,302 @@
<?php
/**
* OAuth 2.0 Abstract Server
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\TokenType\TokenTypeInterface;
use League\OAuth2\Server\Storage\SessionInterface;
use League\OAuth2\Server\Storage\AccessTokenInterface;
use League\OAuth2\Server\Storage\RefreshTokenInterface;
use League\OAuth2\Server\Storage\AuthCodeInterface;
use League\OAuth2\Server\Storage\ScopeInterface;
use League\OAuth2\Server\Storage\ClientInterface;
use Symfony\Component\HttpFoundation\Request;
use League\Event\Emitter;
/**
* OAuth 2.0 Resource Server
*/
abstract class AbstractServer
{
/**
* The request object
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* Session storage
* @var \League\OAuth2\Server\Storage\SessionInterface
*/
protected $sessionStorage;
/**
* Access token storage
* @var \League\OAuth2\Server\Storage\AccessTokenInterface
*/
protected $accessTokenStorage;
/**
* Refresh token storage
* @var \League\OAuth2\Server\Storage\RefreshTokenInterface
*/
protected $refreshTokenStorage;
/**
* Auth code storage
* @var \League\OAuth2\Server\Storage\AuthCodeInterface
*/
protected $authCodeStorage;
/**
* Scope storage
* @var \League\OAuth2\Server\Storage\ScopeInterface
*/
protected $scopeStorage;
/**
* Client storage
* @var \League\OAuth2\Server\Storage\ClientInterface
*/
protected $clientStorage;
/**
* Token type
* @var \League\OAuth2\Server\TokenType\TokenTypeInterface
*/
protected $tokenType;
/**
* Event emitter
* @var \League\Event\Emitter
*/
protected $eventEmitter;
/**
* Abstract server constructor
*/
public function __construct()
{
$this->setEventEmitter();
}
/**
* Set an event emitter
* @param object $emitter Event emitter object
*/
public function setEventEmitter($emitter = null)
{
if ($emitter === null) {
$this->eventEmitter = new Emitter;
} else {
$this->eventEmitter = $emitter;
}
}
/**
* Add an event listener to the event emitter
* @param string $eventName Event name
* @param callable $listener Callable function or method
*/
public function addEventListener($eventName, callable $listener)
{
$this->eventEmitter->addListener($eventName, $listener);
}
/**
* Returns the event emitter
* @return \League\Event\Emitter
*/
public function getEventEmitter()
{
return $this->eventEmitter;
}
/**
* Sets the Request Object
* @param \Symfony\Component\HttpFoundation\Request The Request Object
* @return self
*/
public function setRequest($request)
{
$this->request = $request;
return $this;
}
/**
* Gets the Request object. It will create one from the globals if one is not set.
* @return \Symfony\Component\HttpFoundation\Request
*/
public function getRequest()
{
if ($this->request === null) {
$this->request = Request::createFromGlobals();
}
return $this->request;
}
/**
* Set the client storage
* @param \League\OAuth2\Server\Storage\ClientInterface $storage
* @return self
*/
public function setClientStorage(ClientInterface $storage)
{
$storage->setServer($this);
$this->clientStorage = $storage;
return $this;
}
/**
* Set the session storage
* @param \League\OAuth2\Server\Storage\SessionInterface $storage
* @return self
*/
public function setSessionStorage(SessionInterface $storage)
{
$storage->setServer($this);
$this->sessionStorage = $storage;
return $this;
}
/**
* Set the access token storage
* @param \League\OAuth2\Server\Storage\AccessTokenInterface $storage
* @return self
*/
public function setAccessTokenStorage(AccessTokenInterface $storage)
{
$storage->setServer($this);
$this->accessTokenStorage = $storage;
return $this;
}
/**
* Set the refresh token storage
* @param \League\OAuth2\Server\Storage\RefreshTokenInteface $storage
* @return self
*/
public function setRefreshTokenStorage(RefreshTokenInterface $storage)
{
$storage->setServer($this);
$this->refreshTokenStorage = $storage;
return $this;
}
/**
* Set the auth code storage
* @param \League\OAuth2\Server\Storage\AuthCodeInterface $authCode
* @return self
*/
public function setAuthCodeStorage(AuthCodeInterface $storage)
{
$storage->setServer($this);
$this->authCodeStorage = $storage;
return $this;
}
/**
* Set the scope storage
* @param \League\OAuth2\Server\Storage\ScopeInterface $storage
* @return self
*/
public function setScopeStorage(ScopeInterface $storage)
{
$storage->setServer($this);
$this->scopeStorage = $storage;
return $this;
}
/**
* Return the client storage
* @return \League\OAuth2\Server\Storage\ClientInterface
*/
public function getClientStorage()
{
return $this->clientStorage;
}
/**
* Return the scope storage
* @return \League\OAuth2\Server\Storage\ScopeInterface
*/
public function getScopeStorage()
{
return $this->scopeStorage;
}
/**
* Return the session storage
* @return \League\OAuth2\Server\Storage\SessionInterface
*/
public function getSessionStorage()
{
return $this->sessionStorage;
}
/**
* Return the refresh token storage
* @return \League\OAuth2\Server\Storage\RefreshTokenInterface
*/
public function getRefreshTokenStorage()
{
return $this->refreshTokenStorage;
}
/**
* Return the access token storage
* @return \League\OAuth2\Server\Storage\AccessTokenInterface
*/
public function getAccessTokenStorage()
{
return $this->accessTokenStorage;
}
/**
* Return the auth code storage
* @return \League\OAuth2\Server\Storage\AuthCodeInterface
*/
public function getAuthCodeStorage()
{
return $this->authCodeStorage;
}
/**
* Set the access token type
* @param TokenTypeInterface $tokenType The token type
* @return void
*/
public function setTokenType(TokenTypeInterface $tokenType)
{
$tokenType->setServer($this);
$this->tokenType = $tokenType;
}
/**
* Get the access token type
* @return TokenTypeInterface
*/
public function getTokenType()
{
return $this->tokenType;
}
}

266
src/AuthorizationServer.php Normal file
View File

@@ -0,0 +1,266 @@
<?php
/**
* OAuth 2.0 Authorization Server
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server;
use League\OAuth2\Server\Grant\GrantTypeInterface;
use League\OAuth2\Server\Storage\ClientInterface;
use League\OAuth2\Server\Storage\AccessTokenInterface;
use League\OAuth2\Server\Storage\AuthCodeInterface;
use League\OAuth2\Server\Storage\RefreshTokenInterface;
use League\OAuth2\Server\Storage\SessionInterface;
use League\OAuth2\Server\Storage\ScopeInterface;
use League\OAuth2\Server\TokenType\Bearer;
use Symfony\Component\HttpFoundation\Request;
/**
* OAuth 2.0 authorization server class
*/
class AuthorizationServer extends AbstractServer
{
/**
* The delimeter between scopes specified in the scope query string parameter
* The OAuth 2 specification states it should be a space but most use a comma
* @var string
*/
protected $scopeDelimeter = ' ';
/**
* The TTL (time to live) of an access token in seconds (default: 3600)
* @var integer
*/
protected $accessTokenTTL = 3600;
/**
* The registered grant response types
* @var array
*/
protected $responseTypes = [];
/**
* The registered grant types
* @var array
*/
protected $grantTypes = [];
/**
* Require the "scope" parameter to be in checkAuthoriseParams()
* @var boolean
*/
protected $requireScopeParam = false;
/**
* Default scope(s) to be used if none is provided
* @var string|array
*/
protected $defaultScope;
/**
* Require the "state" parameter to be in checkAuthoriseParams()
* @var boolean
*/
protected $requireStateParam = false;
/**
* Create a new OAuth2 authorization server
* @return self
*/
public function __construct()
{
// Set Bearer as the default token type
$this->setTokenType(new Bearer);
parent::__construct();
return $this;
}
/**
* Enable support for a grant
* @param GrantTypeInterface $grantType A grant class which conforms to Interface/GrantTypeInterface
* @param null|string $identifier An identifier for the grant (autodetected if not passed)
* @return self
*/
public function addGrantType(GrantTypeInterface $grantType, $identifier = null)
{
if (is_null($identifier)) {
$identifier = $grantType->getIdentifier();
}
// Inject server into grant
$grantType->setAuthorizationServer($this);
$this->grantTypes[$identifier] = $grantType;
if (!is_null($grantType->getResponseType())) {
$this->responseTypes[] = $grantType->getResponseType();
}
return $this;
}
/**
* Check if a grant type has been enabled
* @param string $identifier The grant type identifier
* @return boolean Returns "true" if enabled, "false" if not
*/
public function hasGrantType($identifier)
{
return (array_key_exists($identifier, $this->grantTypes));
}
/**
* Returns response types
* @return array
*/
public function getResponseTypes()
{
return $this->responseTypes;
}
/**
* Require the "scope" paremter in checkAuthoriseParams()
* @param boolean $require
* @return self
*/
public function requireScopeParam($require = true)
{
$this->requireScopeParam = $require;
return $this;
}
/**
* Is the scope parameter required?
* @return bool
*/
public function scopeParamRequired()
{
return $this->requireScopeParam;
}
/**
* Default scope to be used if none is provided and requireScopeParam() is false
* @param string $default Name of the default scope
* @param self
*/
public function setDefaultScope($default = null)
{
$this->defaultScope = $default;
return $this;
}
/**
* Default scope to be used if none is provided and requireScopeParam is false
* @return string|null
*/
public function getDefaultScope()
{
return $this->defaultScope;
}
/**
* Require the "state" paremter in checkAuthoriseParams()
* @param boolean $require
* @return void
*/
public function stateParamRequired()
{
return $this->requireStateParam;
}
/**
* Require the "state" paremter in checkAuthoriseParams()
* @param boolean $require
* @return void
*/
public function requireStateParam($require = true)
{
$this->requireStateParam = $require;
return $this;
}
/**
* Get the scope delimeter
* @return string The scope delimiter (default: ",")
*/
public function getScopeDelimeter()
{
return $this->scopeDelimeter;
}
/**
* Set the scope delimiter
* @param string $scopeDelimeter
*/
public function setScopeDelimeter($scopeDelimeter = ' ')
{
$this->scopeDelimeter = $scopeDelimeter;
return $this;
}
/**
* Get the TTL for an access token
* @return int The TTL
*/
public function getAccessTokenTTL()
{
return $this->accessTokenTTL;
}
/**
* Set the TTL for an access token
* @param int $accessTokenTTL The new TTL
*/
public function setAccessTokenTTL($accessTokenTTL = 3600)
{
$this->accessTokenTTL = $accessTokenTTL;
return $this;
}
/**
* Issue an access token
* @return array Authorise request parameters
*/
public function issueAccessToken()
{
$grantType = $this->getRequest()->request->get('grant_type');
if (is_null($grantType)) {
throw new Exception\InvalidRequestException('grant_type');
}
// Ensure grant type is one that is recognised and is enabled
if (!in_array($grantType, array_keys($this->grantTypes))) {
throw new Exception\UnsupportedGrantTypeException($grantType);
}
// Complete the flow
return $this->getGrantType($grantType)->completeFlow();
}
/**
* Return a grant type class
* @param string $grantType The grant type identifer
* @return Grant\GrantTypeInterface
*/
public function getGrantType($grantType)
{
if (isset($this->grantTypes[$grantType])) {
return $this->grantTypes[$grantType];
}
throw new Exception\InvalidGrantException($grantType);
}
}

View File

@@ -0,0 +1,187 @@
<?php
/**
* OAuth 2.0 Abstract token
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Entity;
use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\AbstractServer;
use Symfony\Component\HttpFoundation\ParameterBag;
use League\OAuth2\Server\Entity\SessionEntity;
/**
* Abstract token class
*/
abstract class AbstractTokenEntity
{
/**
* Token identifier
* @var string
*/
protected $id;
/**
* Associated session
* @var \League\OAuth2\Server\Entity\SessionEntity
*/
protected $session;
/**
* Session scopes
* @var \League\OAuth2\Server\Entity\ScopeEntity[]
*/
protected $scopes;
/**
* Token expire time
* @var int
*/
protected $expireTime = 0;
/**
* Authorization or resource server
* @var \League\OAuth2\Server\AbstractServer
*/
protected $server;
/**
* __construct
* @param \League\OAuth2\Server\AbstractServer $server
* @return self
*/
public function __construct(AbstractServer $server)
{
$this->server = $server;
return $this;
}
/**
* Set session
* @param \League\OAuth2\Server\Entity\SessionEntity $session
* @return self
*/
public function setSession(SessionEntity $session)
{
$this->session = $session;
return $this;
}
/**
* Set the expire time of the token
* @param integer $expireTime Unix time stamp
* @return self
*/
public function setExpireTime($expireTime)
{
$this->expireTime = $expireTime;
return $this;
}
/**
* Return token expire time
* @return int
*/
public function getExpireTime()
{
return $this->expireTime;
}
/**
* Is the token expired?
* @return bool
*/
public function isExpired()
{
return ((time() - $this->expireTime) > 0);
}
/**
* Set token ID
* @param string $token Token ID
* @return self
*/
public function setId($id = null)
{
$this->id = ($id !== null) ? $id : SecureKey::generate();
return $this;
}
/**
* Get the token ID
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Associate a scope
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope
* @return self
*/
public function associateScope(ScopeEntity $scope)
{
if (!isset($this->scopes[$scope->getId()])) {
$this->scopes[$scope->getId()] = $scope;
}
return $this;
}
/**
* Format the local scopes array
* @param \League\OAuth2\Server\Entity\ScopeEntity[]
* @return array
*/
protected function formatScopes($unformatted = [])
{
if (is_null($unformatted)) {
return [];
}
$scopes = [];
foreach ($unformatted as $scope) {
if ($scope instanceof ScopeEntity) {
$scopes[$scope->getId()] = $scope;
}
}
return $scopes;
}
/**
* Returns the token as a string if the object is cast as a string
* @return string
*/
public function __toString()
{
if ($this->id === null) {
return '';
}
return $this->id;
}
/**
* Expire the token
* @return void
*/
abstract public function expire();
/**
* Save the token
* @return void
*/
abstract public function save();
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* OAuth 2.0 Access token entity
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Entity;
/**
* Access token entity class
*/
class AccessTokenEntity extends AbstractTokenEntity
{
/**
* Get session
* @return \League\OAuth2\Server\Entity\SessionEntity
*/
public function getSession()
{
if ($this->session instanceof SessionEntity) {
return $this->session;
}
$this->session = $this->server->getSessionStorage()->getByAccessToken($this);
return $this->session;
}
/**
* Check if access token has an associated scope
* @param string $scope Scope to check
* @return bool
*/
public function hasScope($scope)
{
if ($this->scopes === null) {
$this->getScopes();
}
return isset($this->scopes[$scope]);
}
/**
* Return all scopes associated with the access token
* @return \League\OAuth2\Server\Entity\Scope[]
*/
public function getScopes()
{
if ($this->scopes === null) {
$this->scopes = $this->formatScopes(
$this->server->getAccessTokenStorage()->getScopes($this)
);
}
return $this->scopes;
}
/**
* {@inheritdoc}
*/
public function save()
{
$this->server->getAccessTokenStorage()->create(
$this->getId(),
$this->getExpireTime(),
$this->getSession()->getId()
);
// Associate the scope with the token
foreach ($this->getScopes() as $scope) {
$this->server->getAccessTokenStorage()->associateScope($this, $scope);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function expire()
{
$this->server->getAccessTokenStorage()->delete($this);
}
}

View File

@@ -0,0 +1,120 @@
<?php
/**
* OAuth 2.0 Auth code entity
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Entity;
/**
* Access token entity class
*/
class AuthCodeEntity extends AbstractTokenEntity
{
/**
* Redirect URI
* @var string
*/
protected $redirectUri = '';
/**
* Set the redirect URI for the authorization request
* @param string $redirectUri
* @return self
*/
public function setRedirectUri($redirectUri)
{
$this->redirectUri = $redirectUri;
return $this;
}
/**
* Get the redirect URI
* @return string
*/
public function getRedirectUri()
{
return $this->redirectUri;
}
/**
* Generate a redirect URI
* @param string $state The state parameter if set by the client
* @param string $queryDelimeter The query delimiter ('?' for auth code grant, '#' for implicit grant)
* @return string
*/
public function generateRedirectUri($state = null, $queryDelimeter = '?')
{
$uri = $this->getRedirectUri();
$uri .= (strstr($this->getRedirectUri(), $queryDelimeter) === false) ? $queryDelimeter : '&';
return $uri.http_build_query([
'code' => $this->getId(),
'state' => $state
]);
}
/**
* Get session
* @return \League\OAuth2\Server\Entity\SessionEntity
*/
public function getSession()
{
if ($this->session instanceof SessionEntity) {
return $this->session;
}
$this->session = $this->server->getSessionStorage()->getByAuthCode($this);
return $this->session;
}
/**
* Return all scopes associated with the session
* @return \League\OAuth2\Server\Entity\Scope[]
*/
public function getScopes()
{
if ($this->scopes === null) {
$this->scopes = $this->formatScopes(
$this->server->getAuthCodeStorage()->getScopes($this)
);
}
return $this->scopes;
}
/**
* {@inheritdoc}
*/
public function save()
{
$this->server->getAuthCodeStorage()->create(
$this->getId(),
$this->getExpireTime(),
$this->getSession()->getId(),
$this->getRedirectUri()
);
// Associate the scope with the token
foreach ($this->getScopes() as $scope) {
$this->server->getAuthCodeStorage()->associateScope($this, $scope);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function expire()
{
$this->server->getAuthCodeStorage()->delete($this);
}
}

100
src/Entity/ClientEntity.php Normal file
View File

@@ -0,0 +1,100 @@
<?php
/**
* OAuth 2.0 Client entity
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Entity;
use League\OAuth2\Server\AbstractServer;
/**
* Client entity class
*/
class ClientEntity
{
use EntityTrait;
/**
* Client identifier
* @var string
*/
protected $id = null;
/**
* Client secret
* @var string
*/
protected $secret = null;
/**
* Client name
* @var string
*/
protected $name = null;
/**
* Client redirect URI
* @var string
*/
protected $redirectUri = null;
/**
* Authorization or resource server
* @var \League\OAuth2\Server\AbstractServer
*/
protected $server;
/**
* __construct
* @param \League\OAuth2\Server\AbstractServer $server
* @return self
*/
public function __construct(AbstractServer $server)
{
$this->server = $server;
return $this;
}
/**
* Return the client identifier
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Return the client secret
* @return string
*/
public function getSecret()
{
return $this->secret;
}
/**
* Get the client name
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Returnt the client redirect URI
* @return string
*/
public function getRedirectUri()
{
return $this->redirectUri;
}
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* OAuth 2.0 Entity trait
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Entity;
trait EntityTrait
{
/**
* Hydrate an entity with properites
* @param array $properties
*/
public function hydrate(array $properties)
{
foreach ($properties as $prop => $val) {
if (property_exists($this, $prop)) {
$this->{$prop} = $val;
}
}
return $this;
}
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* OAuth 2.0 Refresh token entity
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Entity;
/**
* Refresh token entity class
*/
class RefreshTokenEntity extends AbstractTokenEntity
{
/**
* Access token associated to refresh token
* @var \League\OAuth2\Server\Entity\AccessTokenEntity
*/
protected $accessTokenEntity;
/**
* Id of the access token
* @var string
*/
protected $accessTokenId;
/**
* Set the ID of the associated access token
* @param string $accessToken
* @return self
*/
public function setAccessTokenId($accessTokenId)
{
$this->accessTokenId = $accessTokenId;
return $this;
}
/**
* Associate an access token
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken
* @return self
*/
public function setAccessToken(AccessTokenEntity $accessTokenEntity)
{
$this->accessTokenEntity = $accessTokenEntity;
return $this;
}
/**
* Return access token
* @return AccessToken
*/
public function getAccessToken()
{
if (! $this->accessTokenEntity instanceof AccessTokenEntity) {
$this->accessTokenEntity = $this->server->getAccessTokenStorage()->get($this->accessTokenId);
}
return $this->accessTokenEntity;
}
/**
* {@inheritdoc}
*/
public function save()
{
$this->server->getRefreshTokenStorage()->create(
$this->getId(),
$this->getExpireTime(),
$this->getAccessToken()->getId()
);
}
/**
* {@inheritdoc}
*/
public function expire()
{
$this->server->getRefreshTokenStorage()->delete($this);
}
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* OAuth 2.0 scope entity
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Entity;
use League\OAuth2\Server\AbstractServer;
/**
* Scope entity class
*/
class ScopeEntity implements \JsonSerializable
{
use EntityTrait;
/**
* Scope identifier
* @var string
*/
protected $id;
/**
* Scope description
* @var string
*/
protected $description;
/**
* Authorization or resource server
* @var \League\OAuth2\Server\AbstractServer
*/
protected $server;
/**
* __construct
* @param \League\OAuth2\Server\AbstractServer $server
* @return self
*/
public function __construct(AbstractServer $server)
{
$this->server = $server;
return $this;
}
/**
* Return the scope identifer
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Return the scope's description
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* Returns a JSON object when entity is passed into json_encode
* @return array
*/
public function jsonSerialize()
{
return [
'id' => $this->getId(),
'description' => $this->getDescription()
];
}
}

View File

@@ -0,0 +1,276 @@
<?php
/**
* OAuth 2.0 session entity
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Entity;
use League\OAuth2\Server\AbstractServer;
use League\OAuth2\Server\Event;
use Symfony\Component\HttpFoundation\ParameterBag;
/**
* Session entity grant
*/
class SessionEntity
{
/**
* Session identifier
* @var string
*/
protected $id;
/**
* Client identifier
* @var \League\OAuth2\Server\Entity\ClientEntity
*/
protected $client;
/**
* Session owner identifier
* @var string
*/
protected $ownerId;
/**
* Session owner type (e.g. "user")
* @var string
*/
protected $ownerType;
/**
* Auth code
* @var \League\OAuth2\Server\Entity\AuthCodeEntity
*/
protected $authCode;
/**
* Access token
* @var \League\OAuth2\Server\Entity\AccessTokenEntity
*/
protected $accessToken;
/**
* Refresh token
* @var \League\OAuth2\Server\Entity\RefreshTokenEntity
*/
protected $refreshToken;
/**
* Session scopes
* @var \Symfony\Component\HttpFoundation\ParameterBag
*/
protected $scopes;
/**
* Authorization or resource server
* @var \League\OAuth2\Server\AuthorizationServer|\League\OAuth2\Server\ResourceServer
*/
protected $server;
/**
* __construct
* @param \League\OAuth2\Server\AbstractServer $server
* @return self
*/
public function __construct(AbstractServer $server)
{
$this->server = $server;
return $this;
}
/**
* Set the session identifier
* @param string $id
* @return self
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* Return the session identifier
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* Associate a scope
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope
* @return self
*/
public function associateScope(ScopeEntity $scope)
{
if (!isset($this->scopes[$scope->getId()])) {
$this->scopes[$scope->getId()] = $scope;
}
return $this;
}
/**
* Check if access token has an associated scope
* @param string $scope Scope to check
* @return bool
*/
public function hasScope($scope)
{
if ($this->scopes === null) {
$this->getScopes();
}
return isset($this->scopes[$scope]);
}
/**
* Return all scopes associated with the session
* @return \League\OAuth2\Server\Entity\Scope[]
*/
public function getScopes()
{
if ($this->scopes === null) {
$this->scopes = $this->formatScopes($this->server->getSessionStorage()->getScopes($this));
}
return $this->scopes;
}
/**
* Format the local scopes array
* @param \League\OAuth2\Server\Entity\Scope[]
* @return array
*/
private function formatScopes($unformated = [])
{
$scopes = [];
if (is_array($unformated)) {
foreach ($unformated as $scope) {
if ($scope instanceof ScopeEntity) {
$scopes[$scope->getId()] = $scope;
}
}
}
return $scopes;
}
/**
* Associate an access token with the session
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken
* @return self
*/
public function associateAccessToken(AccessTokenEntity $accessToken)
{
$this->accessToken = $accessToken;
return $this;
}
/**
* Associate a refresh token with the session
* @param \League\OAuth2\Server\Entity\RefreshTokenEntity $refreshToken
* @return self
*/
public function associateRefreshToken(RefreshTokenEntity $refreshToken)
{
$this->refreshToken = $refreshToken;
return $this;
}
/**
* Associate a client with the session
* @param \League\OAuth2\Server\Entity\ClientEntity $client The client
* @return self
*/
public function associateClient(ClientEntity $client)
{
$this->client = $client;
return $this;
}
/**
* Return the session client
* @return \League\OAuth2\Server\Entity\ClientEntity
*/
public function getClient()
{
if ($this->client instanceof ClientEntity) {
return $this->client;
}
$this->client = $this->server->getClientStorage()->getBySession($this);
return $this->client;
}
/**
* Set the session owner
* @param string $type The type of the owner (e.g. user, app)
* @param string $id The identifier of the owner
* @return self
*/
public function setOwner($type, $id)
{
$this->ownerType = $type;
$this->ownerId = $id;
$this->server->getEventEmitter()->emit(new Event\SessionOwnerEvent($this));
return $this;
}
/**
* Return session owner identifier
* @return string
*/
public function getOwnerId()
{
return $this->ownerId;
}
/**
* Return session owner type
* @return string
*/
public function getOwnerType()
{
return $this->ownerType;
}
/**
* Save the session
* @return void
*/
public function save()
{
// Save the session and get an identifier
$id = $this->server->getSessionStorage()->create(
$this->getOwnerType(),
$this->getOwnerId(),
$this->getClient()->getId(),
$this->getClient()->getRedirectUri()
);
$this->setId($id);
// Associate the scope with the session
foreach ($this->getScopes() as $scope) {
$this->server->getSessionStorage()->associateScope($this, $scope);
}
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* OAuth 2.0 client authentication failed event
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Event;
use League\Event\AbstractEvent;
use Symfony\Component\HttpFoundation\Request;
class ClientAuthenticationFailedEvent extends AbstractEvent
{
/**
* Request
* @var \Symfony\Component\HttpFoundation\Request
*/
private $request;
/**
* Init the event with a request
* @param \Symfony\Component\HttpFoundation\Requesty $request
*/
public function __construct(Request $request)
{
$this->request = $request;
}
/**
* The name of the event
* @return string
*/
public function getName()
{
return 'error.auth.client';
}
/**
* Return request
* @return \Symfony\Component\HttpFoundation\Request
*/
public function getRequest()
{
return $this->request;
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* OAuth 2.0 session owner event
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Event;
use League\Event\AbstractEvent;
use League\OAuth2\Server\Entity\SessionEntity;
class SessionOwnerEvent extends AbstractEvent
{
/**
* Session entity
* @var \League\OAuth2\Server\Entity\SessionEntity
*/
private $session;
/**
* Init the event with a session
* @param \League\OAuth2\Server\Entity\SessionEntity $session
*/
public function __construct(SessionEntity $session)
{
$this->session = $session;
}
/**
* The name of the event
* @return string
*/
public function getName()
{
return 'session.owner';
}
/**
* Return session
* @return \League\OAuth2\Server\Entity\SessionEntity
*/
public function getSession()
{
return $this->session;
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* OAuth 2.0 user authentication failed event
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Event;
use League\Event\AbstractEvent;
use Symfony\Component\HttpFoundation\Request;
class UserAuthenticationFailedEvent extends AbstractEvent
{
/**
* Request
* @var \Symfony\Component\HttpFoundation\Request
*/
private $request;
/**
* Init the event with a request
* @param \Symfony\Component\HttpFoundation\Requesty $request
*/
public function __construct(Request $request)
{
$this->request = $request;
}
/**
* The name of the event
* @return string
*/
public function getName()
{
return 'error.auth.user';
}
/**
* Return request
* @return \Symfony\Component\HttpFoundation\Request
*/
public function getRequest()
{
return $this->request;
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* OAuth 2.0 Access Denied Exception
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Exception;
/**
* Exception class
*/
class AccessDeniedException extends OAuthException
{
/**
* {@inheritdoc}
*/
public $httpStatusCode = 401;
/**
* {@inheritdoc}
*/
public $errorType = 'access_denied';
/**
* {@inheritdoc}
*/
public function __construct()
{
parent::__construct('The resource owner or authorization server denied the request.');
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* OAuth 2.0 Invalid Client Exception
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Exception;
/**
* Exception class
*/
class InvalidClientException extends OAuthException
{
/**
* {@inheritdoc}
*/
public $httpStatusCode = 401;
/**
* {@inheritdoc}
*/
public $errorType = 'invalid_client';
/**
* {@inheritdoc}
*/
public function __construct()
{
parent::__construct('Client authentication failed.');
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* OAuth 2.0 Invalid Credentials Exception
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Exception;
/**
* Exception class
*/
class InvalidCredentialsException extends OAuthException
{
/**
* {@inheritdoc}
*/
public $httpStatusCode = 401;
/**
* {@inheritdoc}
*/
public $errorType = 'invalid_credentials';
/**
* {@inheritdoc}
*/
public function __construct()
{
parent::__construct('The user credentials were incorrect.');
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* OAuth 2.0 Invalid Grant Exception
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Exception;
/**
* Exception class
*/
class InvalidGrantException extends OAuthException
{
/**
* {@inheritdoc}
*/
public $httpStatusCode = 400;
/**
* {@inheritdoc}
*/
public $errorType = 'invalid_grant';
/**
* {@inheritdoc}
*/
public function __construct($parameter)
{
parent::__construct(
sprintf(
'The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client. Check the "%s" parameter.',
$parameter
)
);
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* OAuth 2.0 Invalid Refresh Exception
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Exception;
/**
* Exception class
*/
class InvalidRefreshException extends OAuthException
{
/**
* {@inheritdoc}
*/
public $httpStatusCode = 400;
/**
* {@inheritdoc}
*/
public $errorType = 'invalid_request';
/**
* {@inheritdoc}
*/
public function __construct()
{
parent::__construct('The refresh token is invalid.');
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* OAuth 2.0 Invalid Request Exception
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Exception;
/**
* Exception class
*/
class InvalidRequestException extends OAuthException
{
/**
* {@inheritdoc}
*/
public $httpStatusCode = 400;
/**
* {@inheritdoc}
*/
public $errorType = 'invalid_request';
/**
* {@inheritdoc}
*/
public function __construct($parameter, $redirectUri = null)
{
parent::__construct(
sprintf(
'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "%s" parameter.',
$parameter
)
);
$this->redirectUri = $redirectUri;
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* OAuth 2.0 Invalid Scope Exception
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Exception;
/**
* Exception class
*/
class InvalidScopeException extends OAuthException
{
/**
* {@inheritdoc}
*/
public $httpStatusCode = 400;
/**
* {@inheritdoc}
*/
public $errorType = 'invalid_scope';
/**
* {@inheritdoc}
*/
public function __construct($parameter, $redirectUri = null)
{
parent::__construct(
sprintf(
'The requested scope is invalid, unknown, or malformed. Check the "%s" scope.',
$parameter
)
);
$this->redirectUri = $redirectUri;
}
}

View File

@@ -0,0 +1,123 @@
<?php
/**
* OAuth 2.0 Base Exception
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Exception;
use Symfony\Component\HttpFoundation\Request;
/**
* Exception class
*/
class OAuthException extends \Exception
{
/**
* The HTTP status code for this exception that should be sent in the response
*/
public $httpStatusCode = 400;
/**
* Redirect URI if the server should redirect back to the client
* @var string|null
*/
public $redirectUri = null;
/**
* The exception type
*/
public $errorType = '';
/**
* Throw a new exception
*/
public function __construct($msg = 'An error occured')
{
parent::__construct($msg);
}
/**
* Should the server redirect back to the client?
* @return bool
*/
public function shouldRedirect()
{
return is_null($this->redirectUri) ? false : true;
}
/**
* Return redirect URI if set
* @return string|null
*/
public function getRedirectUri()
{
return \League\OAuth2\Server\Util\RedirectUri::make(
$this->redirectUri,
[
'error' => $this->errorType,
'message' => $this->getMessage(),
]
);
}
/**
* Get all headers that have to be send with the error response
* @return array Array with header values
*/
public function getHttpHeaders()
{
$headers = [];
switch ($this->httpStatusCode) {
case 401:
$headers[] = 'HTTP/1.1 401 Unauthorized';
break;
case 500:
$headers[] = 'HTTP/1.1 500 Internal Server Error';
break;
case 501:
$headers[] = 'HTTP/1.1 501 Not Implemented';
break;
case 400:
default:
$headers[] = 'HTTP/1.1 400 Bad Request';
break;
}
// Add "WWW-Authenticate" header
//
// RFC 6749, section 5.2.:
// "If the client attempted to authenticate via the 'Authorization'
// request header field, the authorization server MUST
// respond with an HTTP 401 (Unauthorized) status code and
// include the "WWW-Authenticate" response header field
// matching the authentication scheme used by the client.
// @codeCoverageIgnoreStart
if ($this->errorType === 'invalid_client') {
$authScheme = null;
$request = new Request();
if ($request->getUser() !== null) {
$authScheme = 'Basic';
} else {
$authHeader = $request->headers->get('Authorization');
if ($authHeader !== null) {
if (strpos($authHeader, 'Bearer') === 0) {
$authScheme = 'Bearer';
} elseif (strpos($authHeader, 'Basic') === 0) {
$authScheme = 'Basic';
}
}
}
if ($authScheme !== null) {
$headers[] = 'WWW-Authenticate: '.$authScheme.' realm=""';
}
}
// @codeCoverageIgnoreEnd
return $headers;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* OAuth 2.0 Server Error Exception
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Exception;
/**
* Exception class
*/
class ServerErrorException extends OAuthException
{
/**
* {@inheritdoc}
*/
public $httpStatusCode = 500;
/**
* {@inheritdoc}
*/
public $errorType = 'server_error';
/**
* {@inheritdoc}
*/
public function __construct($parameter = null)
{
$parameter = is_null($parameter) ? 'The authorization server encountered an unexpected condition which prevented it from fulfilling the request.' : $parameter;
parent::__construct($parameter);
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* OAuth 2.0 Unauthorized Client Exception
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Exception;
/**
* Exception class
*/
class UnauthorizedClientException extends OAuthException
{
/**
* {@inheritdoc}
*/
public $httpStatusCode = 400;
/**
* {@inheritdoc}
*/
public $errorType = 'unauthorized_client';
/**
* {@inheritdoc}
*/
public function __construct()
{
parent::__construct('The client is not authorized to request an access token using this method.');
}
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* OAuth 2.0 Invalid Request Exception
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Exception;
/**
* Exception class
*/
class UnsupportedGrantTypeException extends OAuthException
{
/**
* {@inheritdoc}
*/
public $httpStatusCode = 400;
/**
* {@inheritdoc}
*/
public $errorType = 'unsupported_grant_type';
/**
* {@inheritdoc}
*/
public function __construct($parameter)
{
parent::__construct(
sprintf(
'The authorization grant type "%s" is not supported by the authorization server.',
$parameter
)
);
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* OAuth 2.0 Unsupported Response Type Exception
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Exception;
/**
* Exception class
*/
class UnsupportedResponseTypeException extends OAuthException
{
/**
* {@inheritdoc}
*/
public $httpStatusCode = 400;
/**
* {@inheritdoc}
*/
public $errorType = 'unsupported_response_type';
/**
* {@inheritdoc}
*/
public function __construct($parameter, $redirectUri = null)
{
parent::__construct('The authorization server does not support obtaining an access token using this method.');
$this->redirectUri = $redirectUri;
}
}

189
src/Grant/AbstractGrant.php Normal file
View File

@@ -0,0 +1,189 @@
<?php
/**
* OAuth 2.0 Abstract grant
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Grant;
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Entity\ScopeEntity;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Exception;
/**
* Abstract grant class
*/
abstract class AbstractGrant implements GrantTypeInterface
{
/**
* Grant identifier
* @var string
*/
protected $identifier = '';
/**
* Response type
* @var string
*/
protected $responseType;
/**
* Callback to authenticate a user's name and password
* @var function
*/
protected $callback;
/**
* AuthServer instance
* @var \League\OAuth2\Server\AuthorizationServer
*/
protected $server;
/**
* Access token expires in override
* @var int
*/
protected $accessTokenTTL;
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the identifier
* @param string $identifier
* @return self
*/
public function setIdentifier($identifier)
{
$this->identifier = $identifier;
return $this;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
/**
* Get the TTL for an access token
* @return int The TTL
*/
public function getAccessTokenTTL()
{
if ($this->accessTokenTTL) {
return $this->accessTokenTTL;
}
return $this->server->getAccessTokenTTL();
}
/**
* Override the default access token expire time
* @param int $accessTokenTTL
* @return self
*/
public function setAccessTokenTTL($accessTokenTTL)
{
$this->accessTokenTTL = $accessTokenTTL;
return $this;
}
/**
* Inject the authorization server into the grant
* @param \League\OAuth2\Server\AuthorizationServer $server The authorization server instance
* @return self
*/
public function setAuthorizationServer(AuthorizationServer $server)
{
$this->server = $server;
return $this;
}
/**
* Given a list of scopes, validate them and return an array of Scope entities
* @param string $scopeParam A string of scopes (e.g. "profile email birthday")
* @param \League\OAuth2\Server\Entity\ClientEntity $client Client entity
* @param string|null $redirectUri The redirect URI to return the user to
* @return \League\OAuth2\Server\Entity\ScopeEntity[]
* @throws \League\OAuth2\Server\Exception\InvalidScopeException If scope is invalid, or no scopes passed when required
*/
public function validateScopes($scopeParam = '', ClientEntity $client, $redirectUri = null)
{
$scopesList = explode($this->server->getScopeDelimeter(), $scopeParam);
for ($i = 0; $i < count($scopesList); $i++) {
$scopesList[$i] = trim($scopesList[$i]);
if ($scopesList[$i] === '') {
unset($scopesList[$i]); // Remove any junk scopes
}
}
if (
$this->server->scopeParamRequired() === true
&& $this->server->getDefaultScope() === null
&& count($scopesList) === 0
) {
throw new Exception\InvalidRequestException('scope');
} elseif (count($scopesList) === 0 && $this->server->getDefaultScope() !== null) {
if (is_array($this->server->getDefaultScope())) {
$scopesList = $this->server->getDefaultScope();
} else {
$scopesList = [0 => $this->server->getDefaultScope()];
}
}
$scopes = [];
foreach ($scopesList as $scopeItem) {
$scope = $this->server->getScopeStorage()->get(
$scopeItem,
$this->getIdentifier(),
$client->getId()
);
if (($scope instanceof ScopeEntity) === false) {
throw new Exception\InvalidScopeException($scopeItem, $redirectUri);
}
$scopes[$scope->getId()] = $scope;
}
return $scopes;
}
/**
* Format the local scopes array
* @param \League\OAuth2\Server\Entity\ScopeEntity[]
* @return array
*/
protected function formatScopes($unformated = [])
{
$scopes = [];
foreach ($unformated as $scope) {
if ($scope instanceof ScopeEntity) {
$scopes[$scope->getId()] = $scope;
}
}
return $scopes;
}
}

267
src/Grant/AuthCodeGrant.php Normal file
View File

@@ -0,0 +1,267 @@
<?php
/**
* OAuth 2.0 Auth code grant
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Grant;
use League\OAuth2\Server\Request;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\AuthCodeEntity;
use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\Event;
/**
* Auth code grant class
*/
class AuthCodeGrant extends AbstractGrant
{
/**
* Grant identifier
* @var string
*/
protected $identifier = 'authorization_code';
/**
* Response type
* @var string
*/
protected $responseType = 'code';
/**
* AuthServer instance
* @var AuthServer
*/
protected $server = null;
/**
* Access token expires in override
* @var int
*/
protected $accessTokenTTL = null;
/**
* The TTL of the auth token
* @var integer
*/
protected $authTokenTTL = 600;
/**
* Override the default access token expire time
* @param int $authTokenTTL
* @return void
*/
public function setAuthTokenTTL($authTokenTTL)
{
$this->authTokenTTL = $authTokenTTL;
}
/**
* Check authorize parameters
*
* @return array Authorize request parameters
*/
public function checkAuthorizeParams()
{
// Get required params
$clientId = $this->server->getRequest()->query->get('client_id', null);
if (is_null($clientId)) {
throw new Exception\InvalidRequestException('client_id');
}
$redirectUri = $this->server->getRequest()->query->get('redirect_uri', null);
if (is_null($redirectUri)) {
throw new Exception\InvalidRequestException('redirect_uri');
}
// Validate client ID and redirect URI
$client = $this->server->getClientStorage()->get(
$clientId,
null,
$redirectUri,
$this->getIdentifier()
);
if (($client instanceof ClientEntity) === false) {
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
throw new Exception\InvalidClientException();
}
$state = $this->server->getRequest()->query->get('state', null);
if ($this->server->stateParamRequired() === true && is_null($state)) {
throw new Exception\InvalidRequestException('state', $redirectUri);
}
$responseType = $this->server->getRequest()->query->get('response_type', null);
if (is_null($responseType)) {
throw new Exception\InvalidRequestException('response_type', $redirectUri);
}
// Ensure response type is one that is recognised
if (!in_array($responseType, $this->server->getResponseTypes())) {
throw new Exception\UnsupportedResponseTypeException($responseType, $redirectUri);
}
// Validate any scopes that are in the request
$scopeParam = $this->server->getRequest()->query->get('scope', '');
$scopes = $this->validateScopes($scopeParam, $client, $redirectUri);
return [
'client' => $client,
'redirect_uri' => $redirectUri,
'state' => $state,
'response_type' => $responseType,
'scopes' => $scopes
];
}
/**
* Parse a new authorize request
*
* @param string $type The session owner's type
* @param string $typeId The session owner's ID
* @param array $authParams The authorize request $_GET parameters
* @return string An authorisation code
*/
public function newAuthorizeRequest($type, $typeId, $authParams = [])
{
// Create a new session
$session = new SessionEntity($this->server);
$session->setOwner($type, $typeId);
$session->associateClient($authParams['client']);
$session->save();
// Create a new auth code
$authCode = new AuthCodeEntity($this->server);
$authCode->setId(SecureKey::generate());
$authCode->setRedirectUri($authParams['redirect_uri']);
$authCode->setExpireTime(time() + $this->authTokenTTL);
foreach ($authParams['scopes'] as $scope) {
$authCode->associateScope($scope);
}
$authCode->setSession($session);
$authCode->save();
return $authCode->generateRedirectUri($authParams['state']);
}
/**
* Complete the auth code grant
* @return array
*/
public function completeFlow()
{
// Get the required params
$clientId = $this->server->getRequest()->request->get('client_id', null);
if (is_null($clientId)) {
$clientId = $this->server->getRequest()->getUser();
if (is_null($clientId)) {
throw new Exception\InvalidRequestException('client_id');
}
}
$clientSecret = $this->server->getRequest()->request->get('client_secret', null);
if (is_null($clientSecret)) {
$clientSecret = $this->server->getRequest()->getPassword();
if (is_null($clientSecret)) {
throw new Exception\InvalidRequestException('client_secret');
}
}
$redirectUri = $this->server->getRequest()->request->get('redirect_uri', null);
if (is_null($redirectUri)) {
throw new Exception\InvalidRequestException('redirect_uri');
}
// Validate client ID and client secret
$client = $this->server->getClientStorage()->get(
$clientId,
$clientSecret,
$redirectUri,
$this->getIdentifier()
);
if (($client instanceof ClientEntity) === false) {
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
throw new Exception\InvalidClientException();
}
// Validate the auth code
$authCode = $this->server->getRequest()->request->get('code', null);
if (is_null($authCode)) {
throw new Exception\InvalidRequestException('code');
}
$code = $this->server->getAuthCodeStorage()->get($authCode);
if (($code instanceof AuthCodeEntity) === false) {
throw new Exception\InvalidRequestException('code');
}
// Ensure the auth code hasn't expired
if ($code->isExpired() === true) {
throw new Exception\InvalidRequestException('code');
}
// Check redirect URI presented matches redirect URI originally used in authorize request
if ($code->getRedirectUri() !== $redirectUri) {
throw new Exception\InvalidRequestException('redirect_uri');
}
$session = $code->getSession();
$session->associateClient($client);
$authCodeScopes = $code->getScopes();
// Generate the access token
$accessToken = new AccessTokenEntity($this->server);
$accessToken->setId(SecureKey::generate());
$accessToken->setExpireTime($this->getAccessTokenTTL() + time());
foreach ($authCodeScopes as $authCodeScope) {
$session->associateScope($authCodeScope);
}
foreach ($session->getScopes() as $scope) {
$accessToken->associateScope($scope);
}
$this->server->getTokenType()->setSession($session);
$this->server->getTokenType()->setParam('access_token', $accessToken->getId());
$this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
// Associate a refresh token if set
if ($this->server->hasGrantType('refresh_token')) {
$refreshToken = new RefreshTokenEntity($this->server);
$refreshToken->setId(SecureKey::generate());
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
$this->server->getTokenType()->setParam('refresh_token', $refreshToken->getId());
}
// Expire the auth code
$code->expire();
// Save all the things
$session->save();
$accessToken->setSession($session);
$accessToken->save();
if ($this->server->hasGrantType('refresh_token')) {
$refreshToken->setAccessToken($accessToken);
$refreshToken->save();
}
return $this->server->getTokenType()->generateResponse();
}
}

View File

@@ -0,0 +1,120 @@
<?php
/**
* OAuth 2.0 Client credentials grant
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Grant;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\Event;
/**
* Client credentials grant class
*/
class ClientCredentialsGrant extends AbstractGrant
{
/**
* Grant identifier
* @var string
*/
protected $identifier = 'client_credentials';
/**
* Response type
* @var string
*/
protected $responseType = null;
/**
* AuthServer instance
* @var AuthServer
*/
protected $server = null;
/**
* Access token expires in override
* @var int
*/
protected $accessTokenTTL = null;
/**
* Complete the client credentials grant
* @return array
*/
public function completeFlow()
{
// Get the required params
$clientId = $this->server->getRequest()->request->get('client_id', null);
if (is_null($clientId)) {
$clientId = $this->server->getRequest()->getUser();
if (is_null($clientId)) {
throw new Exception\InvalidRequestException('client_id');
}
}
$clientSecret = $this->server->getRequest()->request->get('client_secret', null);
if (is_null($clientSecret)) {
$clientSecret = $this->server->getRequest()->getPassword();
if (is_null($clientSecret)) {
throw new Exception\InvalidRequestException('client_secret');
}
}
// Validate client ID and client secret
$client = $this->server->getClientStorage()->get(
$clientId,
$clientSecret,
null,
$this->getIdentifier()
);
if (($client instanceof ClientEntity) === false) {
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
throw new Exception\InvalidClientException();
}
// Validate any scopes that are in the request
$scopeParam = $this->server->getRequest()->request->get('scope', '');
$scopes = $this->validateScopes($scopeParam, $client);
// Create a new session
$session = new SessionEntity($this->server);
$session->setOwner('client', $client->getId());
$session->associateClient($client);
// Generate an access token
$accessToken = new AccessTokenEntity($this->server);
$accessToken->setId(SecureKey::generate());
$accessToken->setExpireTime($this->getAccessTokenTTL() + time());
// Associate scopes with the session and access token
foreach ($scopes as $scope) {
$session->associateScope($scope);
}
foreach ($session->getScopes() as $scope) {
$accessToken->associateScope($scope);
}
// Save everything
$session->save();
$accessToken->setSession($session);
$accessToken->save();
$this->server->getTokenType()->setSession($session);
$this->server->getTokenType()->setParam('access_token', $accessToken->getId());
$this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
return $this->server->getTokenType()->generateResponse();
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* OAuth 2.0 Grant type interface
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Grant;
/**
* Grant type interface
*/
interface GrantTypeInterface
{
/**
* Complete the grant flow
* @return array
*/
public function completeFlow();
}

175
src/Grant/PasswordGrant.php Normal file
View File

@@ -0,0 +1,175 @@
<?php
/**
* OAuth 2.0 Password grant
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Grant;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\Event;
/**
* Password grant class
*/
class PasswordGrant extends AbstractGrant
{
/**
* Grant identifier
* @var string
*/
protected $identifier = 'password';
/**
* Response type
* @var string
*/
protected $responseType;
/**
* Callback to authenticate a user's name and password
* @var callable
*/
protected $callback;
/**
* Access token expires in override
* @var int
*/
protected $accessTokenTTL;
/**
* Set the callback to verify a user's username and password
* @param callable $callback The callback function
* @return void
*/
public function setVerifyCredentialsCallback(callable $callback)
{
$this->callback = $callback;
}
/**
* Return the callback function
* @return callable
*/
protected function getVerifyCredentialsCallback()
{
if (is_null($this->callback) || ! is_callable($this->callback)) {
throw new Exception\ServerErrorException('Null or non-callable callback set on Password grant');
}
return $this->callback;
}
/**
* Complete the password grant
* @return array
*/
public function completeFlow()
{
// Get the required params
$clientId = $this->server->getRequest()->request->get('client_id', null);
if (is_null($clientId)) {
$clientId = $this->server->getRequest()->getUser();
if (is_null($clientId)) {
throw new Exception\InvalidRequestException('client_id');
}
}
$clientSecret = $this->server->getRequest()->request->get('client_secret', null);
if (is_null($clientSecret)) {
$clientSecret = $this->server->getRequest()->getPassword();
if (is_null($clientSecret)) {
throw new Exception\InvalidRequestException('client_secret');
}
}
// Validate client ID and client secret
$client = $this->server->getClientStorage()->get(
$clientId,
$clientSecret,
null,
$this->getIdentifier()
);
if (($client instanceof ClientEntity) === false) {
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
throw new Exception\InvalidClientException();
}
$username = $this->server->getRequest()->request->get('username', null);
if (is_null($username)) {
throw new Exception\InvalidRequestException('username');
}
$password = $this->server->getRequest()->request->get('password', null);
if (is_null($password)) {
throw new Exception\InvalidRequestException('password');
}
// Check if user's username and password are correct
$userId = call_user_func($this->getVerifyCredentialsCallback(), $username, $password);
if ($userId === false) {
$this->server->getEventEmitter()->emit(new Event\UserAuthenticationFailedEvent($this->server->getRequest()));
throw new Exception\InvalidCredentialsException();
}
// Validate any scopes that are in the request
$scopeParam = $this->server->getRequest()->request->get('scope', '');
$scopes = $this->validateScopes($scopeParam, $client);
// Create a new session
$session = new SessionEntity($this->server);
$session->setOwner('user', $userId);
$session->associateClient($client);
// Generate an access token
$accessToken = new AccessTokenEntity($this->server);
$accessToken->setId(SecureKey::generate());
$accessToken->setExpireTime($this->getAccessTokenTTL() + time());
// Associate scopes with the session and access token
foreach ($scopes as $scope) {
$session->associateScope($scope);
}
foreach ($session->getScopes() as $scope) {
$accessToken->associateScope($scope);
}
$this->server->getTokenType()->setSession($session);
$this->server->getTokenType()->setParam('access_token', $accessToken->getId());
$this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
// Associate a refresh token if set
if ($this->server->hasGrantType('refresh_token')) {
$refreshToken = new RefreshTokenEntity($this->server);
$refreshToken->setId(SecureKey::generate());
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
$this->server->getTokenType()->setParam('refresh_token', $refreshToken->getId());
}
// Save everything
$session->save();
$accessToken->setSession($session);
$accessToken->save();
if ($this->server->hasGrantType('refresh_token')) {
$refreshToken->setAccessToken($accessToken);
$refreshToken->save();
}
return $this->server->getTokenType()->generateResponse();
}
}

View File

@@ -0,0 +1,160 @@
<?php
/**
* OAuth 2.0 Refresh token grant
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Grant;
use League\OAuth2\Server\Request;
use League\OAuth2\Server\Exception;
use League\OAuth2\Server\Util\SecureKey;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Event;
/**
* Referesh token grant
*/
class RefreshTokenGrant extends AbstractGrant
{
/**
* {@inheritdoc}
*/
protected $identifier = 'refresh_token';
/**
* Refresh token TTL (default = 604800 | 1 week)
* @var integer
*/
protected $refreshTokenTTL = 604800;
/**
* Set the TTL of the refresh token
* @param int $refreshTokenTTL
* @return void
*/
public function setRefreshTokenTTL($refreshTokenTTL)
{
$this->refreshTokenTTL = $refreshTokenTTL;
}
/**
* Get the TTL of the refresh token
* @return int
*/
public function getRefreshTokenTTL()
{
return $this->refreshTokenTTL;
}
/**
* {@inheritdoc}
*/
public function completeFlow()
{
$clientId = $this->server->getRequest()->request->get('client_id', null);
if (is_null($clientId)) {
$clientId = $this->server->getRequest()->getUser();
if (is_null($clientId)) {
throw new Exception\InvalidRequestException('client_id');
}
}
$clientSecret = $this->server->getRequest()->request->get('client_secret', null);
if (is_null($clientSecret)) {
$clientSecret = $this->server->getRequest()->getPassword();
if (is_null($clientSecret)) {
throw new Exception\InvalidRequestException('client_secret');
}
}
// Validate client ID and client secret
$client = $this->server->getClientStorage()->get(
$clientId,
$clientSecret,
null,
$this->getIdentifier()
);
if (($client instanceof ClientEntity) === false) {
$this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
throw new Exception\InvalidClientException();
}
$oldRefreshTokenParam = $this->server->getRequest()->request->get('refresh_token', null);
if ($oldRefreshTokenParam === null) {
throw new Exception\InvalidRequestException('refresh_token');
}
// Validate refresh token
$oldRefreshToken = $this->server->getRefreshTokenStorage()->get($oldRefreshTokenParam);
if (($oldRefreshToken instanceof RefreshTokenEntity) === false) {
throw new Exception\InvalidRefreshException();
}
$oldAccessToken = $oldRefreshToken->getAccessToken();
// Get the scopes for the original session
$session = $oldAccessToken->getSession();
$scopes = $this->formatScopes($session->getScopes());
// Get and validate any requested scopes
$requestedScopesString = $this->server->getRequest()->request->get('scope', '');
$requestedScopes = $this->validateScopes($requestedScopesString, $client);
// If no new scopes are requested then give the access token the original session scopes
if (count($requestedScopes) === 0) {
$newScopes = $scopes;
} else {
// The OAuth spec says that a refreshed access token can have the original scopes or fewer so ensure
// the request doesn't include any new scopes
foreach ($requestedScopes as $requestedScope) {
if (!isset($scopes[$requestedScope->getId()])) {
throw new Exception\InvalidScopeException($requestedScope->getId());
}
}
$newScopes = $requestedScopes;
}
// Generate a new access token and assign it the correct sessions
$newAccessToken = new AccessTokenEntity($this->server);
$newAccessToken->setId(SecureKey::generate());
$newAccessToken->setExpireTime($this->getAccessTokenTTL() + time());
$newAccessToken->setSession($session);
foreach ($newScopes as $newScope) {
$newAccessToken->associateScope($newScope);
}
// Expire the old token and save the new one
$oldAccessToken->expire();
$newAccessToken->save();
$this->server->getTokenType()->setSession($session);
$this->server->getTokenType()->setParam('access_token', $newAccessToken->getId());
$this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
// Expire the old refresh token
$oldRefreshToken->expire();
// Generate a new refresh token
$newRefreshToken = new RefreshTokenEntity($this->server);
$newRefreshToken->setId(SecureKey::generate());
$newRefreshToken->setExpireTime($this->getRefreshTokenTTL() + time());
$newRefreshToken->setAccessToken($newAccessToken);
$newRefreshToken->save();
$this->server->getTokenType()->setParam('refresh_token', $newRefreshToken->getId());
return $this->server->getTokenType()->generateResponse();
}
}

View File

@@ -1,388 +0,0 @@
<?php
/**
* OAuth 2.0 Authorization Server
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2;
use OAuth2\Util\Request;
use OAuth2\Util\SecureKey;
use OAuth2\Storage\SessionInterface;
use OAuth2\Storage\ClientInterface;
use OAuth2\Storage\ScopeInterface;
use OAuth2\Grant\GrantTypeInterface;
/**
* OAuth 2.0 authorization server class
*/
class AuthServer
{
/**
* The delimeter between scopes specified in the scope query string parameter
*
* The OAuth 2 specification states it should be a space but that is stupid
* and everyone excepted Google use a comma instead.
*
* @var string
*/
protected $scopeDelimeter = ',';
/**
* The TTL (time to live) of an access token in seconds (default: 3600)
* @var integer
*/
static protected $expiresIn = 3600;
/**
* The registered grant response types
* @var array
*/
protected $responseTypes = array();
/**
* The client, scope and session storage classes
* @var array
*/
static protected $storages = array();
/**
* The registered grant types
* @var array
*/
static protected $grantTypes = array();
/**
* The request object
* @var Util\RequestInterface
*/
static protected $request = null;
/**
* Exception error codes
* @var array
*/
protected static $exceptionCodes = array(
0 => 'invalid_request',
1 => 'unauthorized_client',
2 => 'access_denied',
3 => 'unsupported_response_type',
4 => 'invalid_scope',
5 => 'server_error',
6 => 'temporarily_unavailable',
7 => 'unsupported_grant_type',
8 => 'invalid_client',
9 => 'invalid_grant'
);
/**
* Exception error messages
* @var array
*/
static protected $exceptionMessages = array(
'invalid_request' => 'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "%s" parameter.',
'unauthorized_client' => 'The client is not authorized to request an access token using this method.',
'access_denied' => 'The resource owner or authorization server denied the request.',
'unsupported_response_type' => 'The authorization server does not support obtaining an access token using this method.',
'invalid_scope' => 'The requested scope is invalid, unknown, or malformed. Check the "%s" scope.',
'server_error' => 'The authorization server encountered an unexpected condition which prevented it from fulfilling the request.',
'temporarily_unavailable' => 'The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.',
'unsupported_grant_type' => 'The authorization grant type "%s" is not supported by the authorization server',
'invalid_client' => 'Client authentication failed',
'invalid_grant' => 'The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client. Check the "%s" parameter.',
'invalid_credentials' => 'The user credentials were incorrect.',
'invalid_refresh' => 'The refresh token is invalid.',
);
/**
* Get an exception message
*
* @param string $error The error message key
* @return string The error message
*/
public static function getExceptionMessage($error = '')
{
return self::$exceptionMessages[$error];
}
/**
* Get an exception code
*
* @param integer $code The exception code
* @return string The exception code type
*/
public static function getExceptionType($code = 0)
{
return self::$exceptionCodes[$code];
}
/**
* Create a new OAuth2 authorization server
*
* @param ClientInterface $client A class which inherits from Storage/ClientInterface
* @param SessionInterface $session A class which inherits from Storage/SessionInterface
* @param ScopeInterface $scope A class which inherits from Storage/ScopeInterface
*/
public function __construct(ClientInterface $client, SessionInterface $session, ScopeInterface $scope)
{
self::$storages = array(
'client' => $client,
'session' => $session,
'scope' => $scope
);
}
/**
* Enable support for a grant
* @param GrantTypeInterface $grantType A grant class which conforms to Interface/GrantTypeInterface
* @param null|string $identifier An identifier for the grant (autodetected if not passed)
*/
public function addGrantType(GrantTypeInterface $grantType, $identifier = null)
{
if (is_null($identifier)) {
$identifier = $grantType->getIdentifier();
}
self::$grantTypes[$identifier] = $grantType;
if ( ! is_null($grantType->getResponseType())) {
$this->responseTypes[] = $grantType->getResponseType();
}
}
/**
* Check if a grant type has been enabled
* @param string $identifier The grant type identifier
* @return boolean Returns "true" if enabled, "false" if not
*/
public static function hasGrantType($identifier)
{
return (array_key_exists($identifier, self::$grantTypes));
}
/**
* Get the scope delimeter
*
* @return string The scope delimiter (default: ",")
*/
public function getScopeDelimeter()
{
return $this->scopeDelimeter;
}
/**
* Set the scope delimiter
*
* @param string $scopeDelimeter
*/
public function setScopeDelimeter($scopeDelimeter)
{
$this->scopeDelimeter = $scopeDelimeter;
}
/**
* Get the TTL for an access token
* @return int The TTL
*/
public static function getExpiresIn()
{
return self::$expiresIn;
}
/**
* Set the TTL for an access token
* @param int $expiresIn The new TTL
*/
public function setExpiresIn($expiresIn)
{
self::$expiresIn = $expiresIn;
}
/**
* Sets the Request Object
*
* @param Util\RequestInterface The Request Object
*/
public function setRequest(Util\RequestInterface $request)
{
self::$request = $request;
}
/**
* Gets the Request object. It will create one from the globals if one is not set.
*
* @return Util\RequestInterface
*/
public static function getRequest()
{
if (self::$request === null) {
// @codeCoverageIgnoreStart
self::$request = Request::buildFromGlobals();
}
// @codeCoverageIgnoreEnd
return self::$request;
}
/**
* Return a storage class
* @param string $obj The class required
* @return Storage\ClientInterface|Storage\ScopeInterface|Storage\SessionInterface
*/
public static function getStorage($obj)
{
return self::$storages[$obj];
}
/**
* Check authorise parameters
*
* @param array $inputParams Optional array of parsed $_GET keys
* @throws \OAuth2\Exception\ClientException
* @return array Authorise request parameters
*/
public function checkAuthoriseParams($inputParams = array())
{
// Auth params
$authParams = self::getParam(array('client_id', 'redirect_uri', 'response_type', 'scope'), 'get', $inputParams);
if (is_null($authParams['client_id'])) {
throw new Exception\ClientException(sprintf(self::$exceptionMessages['invalid_request'], 'client_id'), 0);
}
if (is_null($authParams['redirect_uri'])) {
throw new Exception\ClientException(sprintf(self::$exceptionMessages['invalid_request'], 'redirect_uri'), 0);
}
// Validate client ID and redirect URI
$clientDetails = self::getStorage('client')->getClient($authParams['client_id'], null, $authParams['redirect_uri']);
if ($clientDetails === false) {
throw new Exception\ClientException(self::$exceptionMessages['invalid_client'], 8);
}
$authParams['client_details'] = $clientDetails;
if (is_null($authParams['response_type'])) {
throw new Exception\ClientException(sprintf(self::$exceptionMessages['invalid_request'], 'response_type'), 0);
}
// Ensure response type is one that is recognised
if ( ! in_array($authParams['response_type'], $this->responseTypes)) {
throw new Exception\ClientException(self::$exceptionMessages['unsupported_response_type'], 3);
}
// Validate scopes
$scopes = explode($this->scopeDelimeter, $authParams['scope']);
for ($i = 0; $i < count($scopes); $i++) {
$scopes[$i] = trim($scopes[$i]);
if ($scopes[$i] === '') unset($scopes[$i]); // Remove any junk scopes
}
if (count($scopes) === 0) {
throw new Exception\ClientException(sprintf(self::$exceptionMessages['invalid_request'], 'scope'), 0);
}
$authParams['scopes'] = array();
foreach ($scopes as $scope) {
$scopeDetails = self::getStorage('scope')->getScope($scope);
if ($scopeDetails === false) {
throw new Exception\ClientException(sprintf(self::$exceptionMessages['invalid_scope'], $scope), 4);
}
$authParams['scopes'][] = $scopeDetails;
}
return $authParams;
}
/**
* Parse a new authorise request
*
* @param string $type The session owner's type
* @param string $typeId The session owner's ID
* @param array $authParams The authorise request $_GET parameters
* @return string An authorisation code
*/
public function newAuthoriseRequest($type, $typeId, $authParams = array())
{
// Generate an auth code
$authCode = SecureKey::make();
// Remove any old sessions the user might have
self::getStorage('session')->deleteSession($authParams['client_id'], $type, $typeId);
// Create a new session
$sessionId = self::getStorage('session')->createSession($authParams['client_id'], $authParams['redirect_uri'], $type, $typeId, $authCode);
// Associate scopes with the new session
foreach ($authParams['scopes'] as $scope)
{
self::getStorage('session')->associateScope($sessionId, $scope['id']);
}
return $authCode;
}
/**
* Issue an access token
*
* @param array $inputParams Optional array of parsed $_POST keys
* @return array Authorise request parameters
*/
public function issueAccessToken($inputParams = array())
{
$grantType = self::getParam('grant_type', 'post', $inputParams);
if (is_null($grantType)) {
throw new Exception\ClientException(sprintf(self::$exceptionMessages['invalid_request'], 'grant_type'), 0);
}
// Ensure grant type is one that is recognised and is enabled
if ( ! in_array($grantType, array_keys(self::$grantTypes))) {
throw new Exception\ClientException(sprintf(self::$exceptionMessages['unsupported_grant_type'], $grantType), 7);
}
// Complete the flow
return $this->getGrantType($grantType)->completeFlow($inputParams);
}
/**
* Return a grant type class
* @param string $grantType The grant type identifer
* @return class
*/
protected function getGrantType($grantType)
{
return self::$grantTypes[$grantType];
}
/**
* Get a parameter from passed input parameters or the Request class
* @param string|array $param Requried parameter
* @param string $method Get/put/post/delete
* @param array $inputParams Passed input parameters
* @return mixed 'Null' if parameter is missing
*/
public static function getParam($param = '', $method = 'get', $inputParams = array())
{
if (is_string($param)) {
return (isset($inputParams[$param])) ? $inputParams[$param] : self::getRequest()->{$method}($param);
} else {
$response = array();
foreach ($param as $p) {
$response[$p] = self::getParam($p, $method, $inputParams);
}
return $response;
}
}
}

View File

@@ -1,20 +0,0 @@
<?php
/**
* OAuth 2.0 Client Exception
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2\Exception;
/**
* ClientException Exception
*/
class ClientException extends OAuth2Exception
{
}

View File

@@ -1,20 +0,0 @@
<?php
/**
* OAuth 2.0 Invalid Access Token Exception
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2\Exception;
/**
* InvalidAccessToken Exception
*/
class InvalidAccessTokenException extends OAuth2Exception
{
}

View File

@@ -1,20 +0,0 @@
<?php
/**
* OAuth 2.0 Invalid Grant Type Exception
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2\Exception;
/**
* InvalidGrantTypeException Exception
*/
class InvalidGrantTypeException extends OAuth2Exception
{
}

View File

@@ -1,20 +0,0 @@
<?php
/**
* OAuth 2.0 Base Exception
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2\Exception;
/**
* Exception class
*/
class OAuth2Exception extends \Exception
{
}

View File

@@ -1,132 +0,0 @@
<?php
/**
* OAuth 2.0 Auth code grant
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2\Grant;
use OAuth2\Request;
use OAuth2\AuthServer;
use OAuth2\Exception;
use OAuth2\Util\SecureKey;
use OAuth2\Storage\SessionInterface;
use OAuth2\Storage\ClientInterface;
use OAuth2\Storage\ScopeInterface;
/**
* Auth code grant class
*/
class AuthCode implements GrantTypeInterface {
/**
* Grant identifier
* @var string
*/
protected $identifier = 'authorization_code';
/**
* Response type
* @var string
*/
protected $responseType = 'code';
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
/**
* Complete the auth code grant
* @param null|array $inputParams
* @return array
*/
public function completeFlow($inputParams = null)
{
// Get the required params
$authParams = AuthServer::getParam(array('client_id', 'client_secret', 'redirect_uri', 'code'), 'post', $inputParams);
if (is_null($authParams['client_id'])) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_id'), 0);
}
if (is_null($authParams['client_secret'])) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_secret'), 0);
}
if (is_null($authParams['redirect_uri'])) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'redirect_uri'), 0);
}
// Validate client ID and redirect URI
$clientDetails = AuthServer::getStorage('client')->getClient($authParams['client_id'], $authParams['client_secret'], $authParams['redirect_uri']);
if ($clientDetails === false) {
throw new Exception\ClientException(AuthServer::getExceptionMessage('invalid_client'), 8);
}
$authParams['client_details'] = $clientDetails;
// Validate the authorization code
if (is_null($authParams['code'])) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'code'), 0);
}
// Verify the authorization code matches the client_id and the request_uri
$session = AuthServer::getStorage('session')->validateAuthCode($authParams['client_id'], $authParams['redirect_uri'], $authParams['code']);
if ( ! $session) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_grant'), 'code'), 9);
}
// A session ID was returned so update it with an access token,
// remove the authorisation code, change the stage to 'granted'
$accessToken = SecureKey::make();
$refreshToken = (AuthServer::hasGrantType('refresh_token')) ? SecureKey::make() : null;
$accessTokenExpires = time() + AuthServer::getExpiresIn();
$accessTokenExpiresIn = AuthServer::getExpiresIn();
AuthServer::getStorage('session')->updateSession(
$session['id'],
null,
$accessToken,
$refreshToken,
$accessTokenExpires,
'granted'
);
$response = array(
'access_token' => $accessToken,
'token_type' => 'bearer',
'expires' => $accessTokenExpires,
'expires_in' => $accessTokenExpiresIn
);
if (AuthServer::hasGrantType('refresh_token')) {
$response['refresh_token'] = $refreshToken;
}
return $response;
}
}

View File

@@ -1,121 +0,0 @@
<?php
/**
* OAuth 2.0 Auth code grant
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2\Grant;
use OAuth2\Request;
use OAuth2\AuthServer;
use OAuth2\Exception;
use OAuth2\Util\SecureKey;
use OAuth2\Storage\SessionInterface;
use OAuth2\Storage\ClientInterface;
use OAuth2\Storage\ScopeInterface;
/**
* Client credentials grant class
*/
class ClientCredentials implements GrantTypeInterface {
/**
* Grant identifier
* @var string
*/
protected $identifier = 'client_credentials';
/**
* Response type
* @var string
*/
protected $responseType = null;
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
/**
* Complete the client credentials grant
* @param null|array $inputParams
* @return array
*/
public function completeFlow($inputParams = null)
{
// Get the required params
$authParams = AuthServer::getParam(array('client_id', 'client_secret'), 'post', $inputParams);
if (is_null($authParams['client_id'])) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_id'), 0);
}
if (is_null($authParams['client_secret'])) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_secret'), 0);
}
// Validate client ID and client secret
$clientDetails = AuthServer::getStorage('client')->getClient($authParams['client_id'], $authParams['client_secret']);
if ($clientDetails === false) {
throw new Exception\ClientException(AuthServer::getExceptionMessage('invalid_client'), 8);
}
$authParams['client_details'] = $clientDetails;
// Generate an access token
$accessToken = SecureKey::make();
$refreshToken = (AuthServer::hasGrantType('refresh_token')) ? SecureKey::make() : null;
$accessTokenExpires = time() + AuthServer::getExpiresIn();
$accessTokenExpiresIn = AuthServer::getExpiresIn();
// Delete any existing sessions just to be sure
AuthServer::getStorage('session')->deleteSession($authParams['client_id'], 'client', $authParams['client_id']);
// Create a new session
AuthServer::getStorage('session')->createSession(
$authParams['client_id'],
null,
'client',
$authParams['client_id'],
null,
$accessToken,
$refreshToken,
$accessTokenExpires,
'granted'
);
$response = array(
'access_token' => $accessToken,
'token_type' => 'bearer',
'expires' => $accessTokenExpires,
'expires_in' => $accessTokenExpiresIn
);
if (AuthServer::hasGrantType('refresh_token')) {
$response['refresh_token'] = $refreshToken;
}
return $response;
}
}

View File

@@ -1,54 +0,0 @@
<?php
/**
* OAuth 2.0 Grant type interface
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2\Grant;
use OAuth2\Request;
use OAuth2\AuthServer;
use OAuth2\Exception;
use OAuth2\Util\SecureKey;
use OAuth2\Storage\SessionInterface;
use OAuth2\Storage\ClientInterface;
use OAuth2\Storage\ScopeInterface;
interface GrantTypeInterface
{
/**
* Returns the grant identifier (used to validate grant_type in OAuth2\AuthServer\issueAccessToken())
* @return string
*/
public function getIdentifier();
/**
* Returns the response type (used to validate response_type in OAuth2\AuthServer\checkAuthoriseParams())
* @return null|string
*/
public function getResponseType();
/**
* Complete the grant flow
*
* Example response:
* <code>
* array(
* 'access_token' => (string), // The access token
* 'refresh_token' => (string), // The refresh token (only set if the refresh token grant is enabled)
* 'token_type' => 'bearer', // Almost always "bearer" (exceptions: JWT, SAML)
* 'expires' => (int), // The timestamp of when the access token will expire
* 'expires_in' => (int) // The number of seconds before the access token will expire
* )
* </code>
*
* @param null|array $inputParams Null unless the input parameters have been manually set
* @return array An array of parameters to be passed back to the client
*/
public function completeFlow($inputParams = null);
}

View File

@@ -1,164 +0,0 @@
<?php
/**
* OAuth 2.0 Password grant
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2\Grant;
use OAuth2\Request;
use OAuth2\AuthServer;
use OAuth2\Exception;
use OAuth2\Util\SecureKey;
use OAuth2\Storage\SessionInterface;
use OAuth2\Storage\ClientInterface;
use OAuth2\Storage\ScopeInterface;
/**
* Password grant class
*/
class Password implements GrantTypeInterface {
/**
* Grant identifier
* @var string
*/
protected $identifier = 'password';
/**
* Response type
* @var string
*/
protected $responseType = null;
/**
* Callback to authenticate a user's name and password
* @var function
*/
protected $callback = null;
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
/**
* Set the callback to verify a user's username and password
* @param function $callback The callback function
*/
public function setVerifyCredentialsCallback($callback)
{
$this->callback = $callback;
}
/**
* Return the callback function
* @return function
*/
protected function getVerifyCredentialsCallback()
{
if (is_null($this->callback) || ! is_callable($this->callback)) {
throw new Exception\InvalidGrantTypeException('Null or non-callable callback set');
}
return $this->callback;
}
/**
* Complete the password grant
* @param null|array $inputParams
* @return array
*/
public function completeFlow($inputParams = null)
{
// Get the required params
$authParams = AuthServer::getParam(array('client_id', 'client_secret', 'username', 'password'), 'post', $inputParams);
if (is_null($authParams['client_id'])) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_id'), 0);
}
if (is_null($authParams['client_secret'])) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_secret'), 0);
}
// Validate client ID and redirect URI
$clientDetails = AuthServer::getStorage('client')->getClient($authParams['client_id'], $authParams['client_secret']);
if ($clientDetails === false) {
throw new Exception\ClientException(AuthServer::getExceptionMessage('invalid_client'), 8);
}
$authParams['client_details'] = $clientDetails;
if (is_null($authParams['username'])) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'username'), 0);
}
if (is_null($authParams['password'])) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'password'), 0);
}
// Check if user's username and password are correct
$userId = call_user_func($this->getVerifyCredentialsCallback(), $authParams['username'], $authParams['password']);
if ($userId === false) {
throw new Exception\ClientException(AuthServer::getExceptionMessage('invalid_credentials'), 0);
}
// Generate an access token
$accessToken = SecureKey::make();
$refreshToken = (AuthServer::hasGrantType('refresh_token')) ? SecureKey::make() : null;
$accessTokenExpires = time() + AuthServer::getExpiresIn();
$accessTokenExpiresIn = AuthServer::getExpiresIn();
// Delete any existing sessions just to be sure
AuthServer::getStorage('session')->deleteSession($authParams['client_id'], 'user', $userId);
// Create a new session
AuthServer::getStorage('session')->createSession(
$authParams['client_id'],
null,
'user',
$userId,
null,
$accessToken,
$refreshToken,
$accessTokenExpires,
'granted'
);
$response = array(
'access_token' => $accessToken,
'token_type' => 'bearer',
'expires' => $accessTokenExpires,
'expires_in' => $accessTokenExpiresIn
);
if (AuthServer::hasGrantType('refresh_token')) {
$response['refresh_token'] = $refreshToken;
}
return $response;
}
}

View File

@@ -1,116 +0,0 @@
<?php
/**
* OAuth 2.0 Refresh token grant
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2\Grant;
use OAuth2\Request;
use OAuth2\AuthServer;
use OAuth2\Exception;
use OAuth2\Util\SecureKey;
use OAuth2\Storage\SessionInterface;
use OAuth2\Storage\ClientInterface;
use OAuth2\Storage\ScopeInterface;
/**
* Referesh token grant
*/
class RefreshToken implements GrantTypeInterface {
/**
* Grant identifier
* @var string
*/
protected $identifier = 'refresh_token';
/**
* Response type
* @var string
*/
protected $responseType = null;
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
/**
* Complete the refresh token grant
* @param null|array $inputParams
* @return array
*/
public function completeFlow($inputParams = null)
{
// Get the required params
$authParams = AuthServer::getParam(array('client_id', 'client_secret', 'refresh_token'), 'post', $inputParams);
if (is_null($authParams['client_id'])) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_id'), 0);
}
if (is_null($authParams['client_secret'])) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'client_secret'), 0);
}
// Validate client ID and client secret
$clientDetails = AuthServer::getStorage('client')->getClient($authParams['client_id'], $authParams['client_secret']);
if ($clientDetails === false) {
throw new Exception\ClientException(AuthServer::getExceptionMessage('invalid_client'), 8);
}
$authParams['client_details'] = $clientDetails;
if (is_null($authParams['refresh_token'])) {
throw new Exception\ClientException(sprintf(AuthServer::getExceptionMessage('invalid_request'), 'refresh_token'), 0);
}
// Validate refresh token
$sessionId = AuthServer::getStorage('client')->validateRefreshToken(
$authParams['refresh_token'],
$authParams['client_id']
);
if ($sessionId === false) {
throw new Exception\ClientException(AuthServer::getExceptionMessage('invalid_refresh'), 0);
}
// Generate new tokens
$accessToken = SecureKey::make();
$refreshToken = (AuthServer::hasGrantType('refresh_token')) ? SecureKey::make() : null;
$accessTokenExpires = time() + AuthServer::getExpiresIn();
$accessTokenExpiresIn = AuthServer::getExpiresIn();
AuthServer::getStorage('session')->updateRefreshToken($sessionId, $accessToken, $refreshToken, $accessTokenExpires);
return array(
'access_token' => $accessToken,
'refresh_token' => $refreshToken,
'token_type' => 'bearer',
'expires' => $accessTokenExpires,
'expires_in' => $accessTokenExpiresIn
);
}
}

View File

@@ -1,232 +0,0 @@
<?php
/**
* OAuth 2.0 Resource Server
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2;
use OutOfBoundsException;
use OAuth2\Storage\SessionInterface;
use OAuth2\Storage\SessionScopeInterface;
use OAuth2\Util\RequestInterface;
use OAuth2\Util\Request;
/**
* OAuth 2.0 Resource Server
*/
class ResourceServer
{
/**
* The access token
* @var string
*/
protected $accessToken = null;
/**
* The session ID
* @var string
*/
protected $sessionId = null;
/**
* The type of the owner of the access token
* @var string
*/
protected $ownerType = null;
/**
* The ID of the owner of the access token
* @var string
*/
protected $ownerId = null;
/**
* The scopes associated with the access token
* @var array
*/
protected $sessionScopes = array();
/**
* The client, scope and session storage classes
* @var array
*/
protected $storages = array();
/**
* The request object
* @var Util\RequestInterface
*/
protected $request = null;
/**
* The query string key which is used by clients to present the access token (default: access_token)
* @var string
*/
protected $tokenKey = 'access_token';
/**
* Sets up the Resource
*
* @param SessionInterface The Session Storage Object
*/
public function __construct(SessionInterface $session)
{
$this->storages['session'] = $session;
}
/**
* Sets the Request Object
*
* @param RequestInterface The Request Object
*/
public function setRequest(RequestInterface $request)
{
$this->request = $request;
}
/**
* Gets the Request object. It will create one from the globals if one is not set.
*
* @return Util\RequestInterface
*/
public function getRequest()
{
if ($this->request === null) {
// @codeCoverageIgnoreStart
$this->request = Request::buildFromGlobals();
}
// @codeCoverageIgnoreEnd
return $this->request;
}
/**
* Returns the query string key for the access token.
*
* @return string
*/
public function getTokenKey()
{
return $this->tokenKey;
}
/**
* Sets the query string key for the access token.
*
* @param $key The new query string key
*/
public function setTokenKey($key)
{
$this->tokenKey = $key;
}
/**
* Gets the access token owner ID.
*
* @return string
*/
public function getOwnerId()
{
return $this->ownerId;
}
/**
* Gets the owner type.
*
* @return string
*/
public function getOwnerType()
{
return $this->ownerType;
}
/**
* Gets the access token.
*
* @return string
*/
public function getAccessToken()
{
return $this->accessToken;
}
/**
* Checks if the access token is valid or not.
*
* @throws Exception\InvalidAccessTokenException Thrown if the presented access token is not valid
* @return bool
*/
public function isValid()
{
$access_token = $this->determineAccessToken();
$result = $this->storages['session']->validateAccessToken($access_token);
if ( ! $result) {
throw new Exception\InvalidAccessTokenException('Access token is not valid');
}
$this->accessToken = $access_token;
$this->sessionId = $result['id'];
$this->ownerType = $result['owner_type'];
$this->ownerId = $result['owner_id'];
$this->sessionScopes = $this->storages['session']->getScopes($this->sessionId);
return true;
}
/**
* Checks if the presented access token has the given scope(s).
*
* @param array|string An array of scopes or a single scope as a string
* @return bool Returns bool if all scopes are found, false if any fail
*/
public function hasScope($scopes)
{
if (is_string($scopes)) {
if (in_array($scopes, $this->sessionScopes)) {
return true;
}
return false;
} elseif (is_array($scopes)) {
foreach ($scopes as $scope) {
if ( ! in_array($scope, $this->sessionScopes)) {
return false;
}
}
return true;
}
return false;
}
/**
* Reads in the access token from the headers.
*
* @throws Exception\MissingAccessTokenException Thrown if there is no access token presented
* @return string
*/
protected function determineAccessToken()
{
if ($header = $this->getRequest()->header('Authorization')) {
$access_token = base64_decode(trim(str_replace('Bearer', '', $header)));
} else {
$method = $this->getRequest()->server('REQUEST_METHOD');
$access_token = $this->getRequest()->{$method}($this->tokenKey);
}
if (empty($access_token)) {
throw new Exception\InvalidAccessTokenException('Access token is missing');
}
return $access_token;
}
}

View File

@@ -1,54 +0,0 @@
<?php
/**
* OAuth 2.0 Client storage interface
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2\Storage;
interface ClientInterface
{
/**
* Validate a client
*
* Example SQL query:
*
* <code>
* # Client ID + redirect URI
* SELECT oauth_clients.id FROM oauth_clients LEFT JOIN client_endpoints ON client_endpoints.client_id
* = oauth_clients.id WHERE oauth_clients.id = $clientId AND client_endpoints.redirect_uri = $redirectUri
*
* # Client ID + client secret
* SELECT oauth_clients.id FROM oauth_clients WHERE oauth_clients.id = $clientId AND
* oauth_clients.secret = $clientSecret
*
* # Client ID + client secret + redirect URI
* SELECT oauth_clients.id FROM oauth_clients LEFT JOIN client_endpoints ON client_endpoints.client_id
* = oauth_clients.id WHERE oauth_clients.id = $clientId AND oauth_clients.secret = $clientSecret
* AND client_endpoints.redirect_uri = $redirectUri
* </code>
*
* Response:
*
* <code>
* Array
* (
* [client_id] => (string) The client ID
* [client secret] => (string) The client secret
* [redirect_uri] => (string) The redirect URI used in this request
* [name] => (string) The name of the client
* )
* </code>
*
* @param string $clientId The client's ID
* @param string $clientSecret The client's secret (default = "null")
* @param string $redirectUri The client's redirect URI (default = "null")
* @return bool|array Returns false if the validation fails, array on success
*/
public function getClient($clientId = null, $clientSecret = null, $redirectUri = null);
}

View File

@@ -1,41 +0,0 @@
<?php
/**
* OAuth 2.0 Scope storage interface
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2\Storage;
interface ScopeInterface
{
/**
* Return information about a scope
*
* Example SQL query:
*
* <code>
* SELECT * FROM oauth_scopes WHERE scope = $scope
* </code>
*
* Response:
*
* <code>
* Array
* (
* [id] => (int) The scope's ID
* [scope] => (string) The scope itself
* [name] => (string) The scope's name
* [description] => (string) The scope's description
* )
* </code>
*
* @param string $scope The scope
* @return bool|array If the scope doesn't exist return false
*/
public function getScope($scope);
}

View File

@@ -1,250 +0,0 @@
<?php
/**
* OAuth 2.0 Session storage interface
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2\Storage;
interface SessionInterface
{
/**
* Create a new OAuth session
*
* Example SQL query:
*
* <code>
* INSERT INTO oauth_sessions (client_id, redirect_uri, owner_type,
* owner_id, auth_code, access_token, refresh_token, stage, first_requested,
* last_updated) VALUES ($clientId, $redirectUri, $type, $typeId, $authCode,
* $accessToken, $stage, UNIX_TIMESTAMP(NOW()), UNIX_TIMESTAMP(NOW()))
* </code>
*
* @param string $clientId The client ID
* @param string $redirectUri The redirect URI
* @param string $type The session owner's type (default = "user")
* @param string $typeId The session owner's ID (default = "null")
* @param string $authCode The authorisation code (default = "null")
* @param string $accessToken The access token (default = "null")
* @param string $refreshToken The refresh token (default = "null")
* @param int $accessTokenExpire The expiry time of an access token as a unix timestamp
* @param string $stage The stage of the session (default ="request")
* @return int The session ID
*/
public function createSession(
$clientId,
$redirectUri,
$type = 'user',
$typeId = null,
$authCode = null,
$accessToken = null,
$refreshToken = null,
$accessTokenExpire = null,
$stage = 'requested'
);
/**
* Update an OAuth session
*
* Example SQL query:
*
* <code>
* UPDATE oauth_sessions SET auth_code = $authCode, access_token =
* $accessToken, stage = $stage, last_updated = UNIX_TIMESTAMP(NOW()) WHERE
* id = $sessionId
* </code>
*
* @param string $sessionId The session ID
* @param string $authCode The authorisation code (default = "null")
* @param string $accessToken The access token (default = "null")
* @param string $refreshToken The refresh token (default = "null")
* @param int $accessTokenExpire The expiry time of an access token as a unix timestamp
* @param string $stage The stage of the session (default ="request")
* @return void
*/
public function updateSession(
$sessionId,
$authCode = null,
$accessToken = null,
$refreshToken = null,
$accessTokenExpire = null,
$stage = 'requested'
);
/**
* Delete an OAuth session
*
* <code>
* DELETE FROM oauth_sessions WHERE client_id = $clientId AND owner_type =
* $type AND owner_id = $typeId
* </code>
*
* @param string $clientId The client ID
* @param string $type The session owner's type
* @param string $typeId The session owner's ID
* @return void
*/
public function deleteSession(
$clientId,
$type,
$typeId
);
/**
* Validate that an authorisation code is valid
*
* Example SQL query:
*
* <code>
* SELECT id FROM oauth_sessions WHERE client_id = $clientID AND
* redirect_uri = $redirectUri AND auth_code = $authCode
* </code>
*
* Response:
*
* <code>
* Array
* (
* [id] => (int) The session ID
* [client_id] => (string) The client ID
* [redirect_uri] => (string) The redirect URI
* [owner_type] => (string) The session owner type
* [owner_id] => (string) The session owner's ID
* [auth_code] => (string) The authorisation code
* [stage] => (string) The session's stage
* [first_requested] => (int) Unix timestamp of the time the session was
* first generated
* [last_updated] => (int) Unix timestamp of the time the session was
* last updated
* )
* </code>
*
* @param string $clientId The client ID
* @param string $redirectUri The redirect URI
* @param string $authCode The authorisation code
* @return int|bool Returns the session ID if the auth code
* is valid otherwise returns false
*/
public function validateAuthCode(
$clientId,
$redirectUri,
$authCode
);
/**
* Validate an access token
*
* Example SQL query:
*
* <code>
* SELECT id, owner_id, owner_type FROM oauth_sessions WHERE access_token = $accessToken
* </code>
*
* Response:
*
* <code>
* Array
* (
* [id] => (int) The session ID
* [owner_type] => (string) The owner type
* [owner_id] => (string) The owner ID
* )
* </code>
*
* @param [type] $accessToken [description]
* @return [type] [description]
*/
public function validateAccessToken($accessToken);
/**
* Return the access token for a given session
*
* Example SQL query:
*
* <code>
* SELECT access_token FROM oauth_sessions WHERE id = $sessionId
* </code>
*
* @param int $sessionId The OAuth session ID
* @return string|null Returns the access token as a string if
* found otherwise returns null
*/
public function getAccessToken($sessionId);
/**
* Validate a refresh token
* @param string $refreshToken The refresh token
* @param string $clientId The client ID
* @return int The session ID
*/
public function validateRefreshToken($refreshToken, $clientId);
/**
* Update the refresh token
*
* Example SQL query:
*
* <code>
* UPDATE oauth_sessions SET access_token = $newAccessToken, refresh_token =
* $newRefreshToken, access_toke_expires = $accessTokenExpires, last_updated = UNIX_TIMESTAMP(NOW()) WHERE
* id = $sessionId
* </code>
*
* @param string $sessionId The session ID
* @param string $newAccessToken The new access token for this session
* @param string $newRefreshToken The new refresh token for the session
* @param int $accessTokenExpires The UNIX timestamp of when the new token expires
* @return void
*/
public function updateRefreshToken($sessionId, $newAccessToken, $newRefreshToken, $accessTokenExpires);
/**
* Associates a session with a scope
*
* Example SQL query:
*
* <code>
* INSERT INTO oauth_session_scopes (session_id, scope_id) VALUE ($sessionId,
* $scopeId)
* </code>
*
* @param int $sessionId The session ID
* @param string $scopeId The scope ID
* @return void
*/
public function associateScope($sessionId, $scopeId);
/**
* Return the scopes associated with an access token
*
* Example SQL query:
*
* <code>
* SELECT oauth_scopes.scope FROM oauth_session_scopes JOIN oauth_scopes ON
* oauth_session_scopes.scope_id = oauth_scopes.id WHERE
* session_id = $sessionId
* </code>
*
* Response:
*
* <code>
* Array
* (
* [0] => (string) The scope
* [1] => (string) The scope
* [2] => (string) The scope
* ...
* ...
* )
* </code>
*
* @param int $sessionId The session ID
* @return array
*/
public function getScopes($sessionId);
}

View File

@@ -1,31 +0,0 @@
<?php
/**
* OAuth 2.0 Redirect URI generator
*
* @package lncd/oauth2
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
*/
namespace OAuth2\Util;
/**
* RedirectUri class
*/
class RedirectUri
{
/**
* Generate a new redirect uri
* @param string $uri The base URI
* @param array $params The query string parameters
* @param string $queryDelimeter The query string delimeter (default: "?")
* @return string The updated URI
*/
public static function make($uri, $params = array(), $queryDelimeter = '?')
{
$uri .= (strstr($uri, $queryDelimeter) === false) ? $queryDelimeter : '&';
return $uri.http_build_query($params);
}
}

View File

@@ -1,100 +0,0 @@
<?php
namespace OAuth2\Util;
use OutOfBoundsException;
use InvalidMethodCallException;
use InvalidArgumentException;
class Request implements RequestInterface
{
protected $get = array();
protected $post = array();
protected $cookies = array();
protected $files = array();
protected $server = array();
protected $headers = array();
public static function buildFromGlobals()
{
return new static($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);
}
public function __construct(array $get = array(), array $post = array(), array $cookies = array(), array $files = array(), array $server = array(), $headers = array())
{
$this->get = $get;
$this->post = $post;
$this->cookies = $cookies;
$this->files = $files;
$this->server = $server;
if (empty($headers)) {
$this->headers = $this->readHeaders();
}
}
public function get($index = null, $default = null)
{
return $this->getPropertyValue('get', $index, $default);
}
public function post($index = null, $default = null)
{
return $this->getPropertyValue('post', $index, $default);
}
public function file($index = null, $default = null)
{
return $this->getPropertyValue('files', $index, $default);
}
public function cookie($index = null, $default = null)
{
return $this->getPropertyValue('cookies', $index, $default);
}
public function server($index = null, $default = null)
{
return $this->getPropertyValue('server', $index, $default);
}
public function header($index = null, $default = null)
{
return $this->getPropertyValue('headers', $index, $default);
}
protected function readHeaders()
{
if (function_exists('getallheaders')) {
// @codeCoverageIgnoreStart
$headers = getallheaders();
} else {
// @codeCoverageIgnoreEnd
$headers = array();
foreach ($this->server() as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
$headers[$name] = $value;
}
}
}
return $headers;
}
protected function getPropertyValue($property, $index = null, $default = null)
{
if ( ! isset($this->{$property})) {
throw new InvalidArgumentException("Property '$property' does not exist.");
}
if (is_null($index)) {
return $this->{$property};
}
if ( ! array_key_exists($index, $this->{$property})) {
return $default;
}
return $this->{$property}[$index];
}
}

View File

@@ -1,24 +0,0 @@
<?php
namespace OAuth2\Util;
interface RequestInterface
{
public static function buildFromGlobals();
public function __construct(array $get = array(), array $post = array(), array $cookies = array(), array $files = array(), array $server = array(), $headers = array());
public function get($index = null);
public function post($index = null);
public function cookie($index = null);
public function file($index = null);
public function server($index = null);
public function header($index = null);
}

138
src/ResourceServer.php Normal file
View File

@@ -0,0 +1,138 @@
<?php
/**
* OAuth 2.0 Resource Server
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server;
use League\OAuth2\Server\Storage\ClientInterface;
use League\OAuth2\Server\Storage\AccessTokenInterface;
use League\OAuth2\Server\Storage\SessionInterface;
use League\OAuth2\Server\Storage\ScopeInterface;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\TokenType\Bearer;
use League\OAuth2\Server\Exception;
use Symfony\Component\HttpFoundation\Request;
/**
* OAuth 2.0 Resource Server
*/
class ResourceServer extends AbstractServer
{
/**
* The access token
* @var \League\OAuth2\Server\Entity\AccessTokenEntity
*/
protected $accessToken;
/**
* The query string key which is used by clients to present the access token (default: access_token)
* @var string
*/
protected $tokenKey = 'access_token';
/**
* Initialise the resource server
* @param SessionInterface $sessionStorage
* @param AccessTokenInteface $accessTokenStorage
* @param ClientInterface $clientStorage
* @param ScopeInterface $scopeStorage
* @return self
*/
public function __construct(
SessionInterface $sessionStorage,
AccessTokenInterface $accessTokenStorage,
ClientInterface $clientStorage,
ScopeInterface $scopeStorage
) {
$this->setSessionStorage($sessionStorage);
$this->setAccessTokenStorage($accessTokenStorage);
$this->setClientStorage($clientStorage);
$this->setScopeStorage($scopeStorage);
// Set Bearer as the default token type
$this->setTokenType(new Bearer);
parent::__construct();
return $this;
}
/**
* Sets the query string key for the access token.
* @param $key The new query string key
* @return self
*/
public function setIdKey($key)
{
$this->tokenKey = $key;
return $this;
}
/**
* Gets the access token
* @return string
*/
public function getAccessToken()
{
return $this->accessToken->getId();
}
/**
* Checks if the access token is valid or not
* @param $headersOnly Limit Access Token to Authorization header only
* @return bool
*/
public function isValidRequest($headersOnly = true, $accessToken = null)
{
$accessTokenString = ($accessToken !== null)
? $accessToken
: $this->determineAccessToken($headersOnly);
// Set the access token
$this->accessToken = $this->getAccessTokenStorage()->get($accessTokenString);
// Ensure the access token exists
if (!$this->accessToken instanceof AccessTokenEntity) {
throw new Exception\AccessDeniedException;
}
// Check the access token hasn't expired
// Ensure the auth code hasn't expired
if ($this->accessToken->isExpired() === true) {
throw new Exception\AccessDeniedException;
}
return true;
}
/**
* Reads in the access token from the headers
* @param $headersOnly Limit Access Token to Authorization header only
* @throws Exception\MissingAccessTokenException Thrown if there is no access token presented
* @return string
*/
public function determineAccessToken($headersOnly = false)
{
if ($this->getRequest()->headers->get('Authorization') !== null) {
$accessToken = $this->getTokenType()->determineAccessTokenInHeader($this->getRequest());
} elseif ($headersOnly === false) {
$accessToken = ($this->getRequest()->server->get('REQUEST_METHOD') === 'GET')
? $this->getRequest()->query->get($this->tokenKey)
: $this->getRequest()->request->get($this->tokenKey);
}
if (empty($accessToken)) {
throw new Exception\InvalidRequestException('access token');
}
return $accessToken;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* OAuth 2.0 abstract storage
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Storage;
use League\OAuth2\Server\AbstractServer;
/**
* Abstract storage class
*/
abstract class AbstractStorage implements StorageInterface
{
/**
* Server
* @var \League\OAuth2\Server\AbstractServer $server
*/
protected $server;
/**
* Set the server
* @param \League\OAuth2\Server\AbstractServer $server
*/
public function setServer(AbstractServer $server)
{
$this->server = $server;
return $this;
}
/**
* Return the server
* @return \League\OAuth2\Server\AbstractServer
*/
protected function getServer()
{
return $this->server;
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* OAuth 2.0 Access token storage interface
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Storage;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\AbstractTokenEntity;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Entity\ScopeEntity;
/**
* Access token interface
*/
interface AccessTokenInterface extends StorageInterface
{
/**
* Get an instance of Entity\AccessTokenEntity
* @param string $token The access token
* @return \League\OAuth2\Server\Entity\AccessTokenEntity
*/
public function get($token);
/**
* Get the scopes for an access token
* @param \League\OAuth2\Server\Entity\AbstractTokenEntity $token The access token
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity
*/
public function getScopes(AbstractTokenEntity $token);
/**
* Creates a new access token
* @param string $token The access token
* @param integer $expireTime The expire time expressed as a unix timestamp
* @param string|integer $sessionId The session ID
* @return \League\OAuth2\Server\Entity\AccessToken
*/
public function create($token, $expireTime, $sessionId);
/**
* Associate a scope with an acess token
* @param \League\OAuth2\Server\Entity\AbstractTokenEntity $token The access token
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope
* @return void
*/
public function associateScope(AbstractTokenEntity $token, ScopeEntity $scope);
/**
* Delete an access token
* @param \League\OAuth2\Server\Entity\AbstractTokenEntity $token The access token to delete
* @return void
*/
public function delete(AbstractTokenEntity $token);
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* OAuth 2.0 Auth code storage interface
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Storage;
use League\OAuth2\Server\Entity\AuthCodeEntity;
use League\OAuth2\Server\Entity\ScopeEntity;
/**
* Auth code storage interface
*/
interface AuthCodeInterface extends StorageInterface
{
/**
* Get the auth code
* @param string $code
* @return \League\OAuth2\Server\Entity\AuthCodeEntity
*/
public function get($code);
/**
* Create an auth code.
* @param string $token The token ID
* @param integer $expireTime Token expire time
* @param integer $sessionId Session identifier
* @param string $redirectUri Client redirect uri
*
* @return void
*/
public function create($token, $expireTime, $sessionId, $redirectUri);
/**
* Get the scopes for an access token
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The auth code
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity
*/
public function getScopes(AuthCodeEntity $token);
/**
* Associate a scope with an acess token
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The auth code
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope
* @return void
*/
public function associateScope(AuthCodeEntity $token, ScopeEntity $scope);
/**
* Delete an access token
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $token The access token to delete
* @return void
*/
public function delete(AuthCodeEntity $token);
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* OAuth 2.0 Client storage interface
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Storage;
use League\OAuth2\Server\Entity\SessionEntity;
/**
* Client storage interface
*/
interface ClientInterface extends StorageInterface
{
/**
* Validate a client
* @param string $clientId The client's ID
* @param string $clientSecret The client's secret (default = "null")
* @param string $redirectUri The client's redirect URI (default = "null")
* @param string $grantType The grant type used (default = "null")
* @return League\OAuth2\Server\Entity\ClientEntity
*/
public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null);
/**
* Get the client associated with a session
* @param \League\OAuth2\Server\Entity\SessionEntity $session The session
* @return \League\OAuth2\Server\Entity\ClientEntity
*/
public function getBySession(SessionEntity $session);
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* OAuth 2.0 Refresh token storage interface
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Storage;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
/**
* Refresh token interface
*/
interface RefreshTokenInterface extends StorageInterface
{
/**
* Return a new instance of \League\OAuth2\Server\Entity\RefreshTokenEntity
* @param string $token
* @return \League\OAuth2\Server\Entity\RefreshTokenEntity
*/
public function get($token);
/**
* Create a new refresh token_name
* @param string $token
* @param integer $expireTime
* @param string $accessToken
* @return \League\OAuth2\Server\Entity\RefreshTokenEntity
*/
public function create($token, $expireTime, $accessToken);
/**
* Delete the refresh token
* @param \League\OAuth2\Server\Entity\RefreshTokenEntity $token
* @return void
*/
public function delete(RefreshTokenEntity $token);
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* OAuth 2.0 Scope storage interface
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Storage;
/**
* Scope interface
*/
interface ScopeInterface extends StorageInterface
{
/**
* Return information about a scope
* @param string $scope The scope
* @param string $grantType The grant type used in the request (default = "null")
* @param string $clientId The client sending the request (default = "null")
* @return \League\OAuth2\Server\Entity\ScopeEntity
*/
public function get($scope, $grantType = null, $clientId = null);
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* OAuth 2.0 Session storage interface
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Storage;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\AuthCodeEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Entity\ScopeEntity;
/**
* Session storage interface
*/
interface SessionInterface extends StorageInterface
{
/**
* Get a session from an access token
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken The access token
* @return \League\OAuth2\Server\Entity\SessionEntity
*/
public function getByAccessToken(AccessTokenEntity $accessToken);
/**
* Get a session from an auth code
* @param \League\OAuth2\Server\Entity\AuthCodeEntity $authCode The auth code
* @return \League\OAuth2\Server\Entity\SessionEntity
*/
public function getByAuthCode(AuthCodeEntity $authCode);
/**
* Get a session's scopes
* @param \League\OAuth2\Server\Entity\SessionEntity
* @return array Array of \League\OAuth2\Server\Entity\ScopeEntity
*/
public function getScopes(SessionEntity $session);
/**
* Create a new session
* @param string $ownerType Session owner's type (user, client)
* @param string $ownerId Session owner's ID
* @param string $clientId Client ID
* @param string $clientRedirectUri Client redirect URI (default = null)
* @return integer The session's ID
*/
public function create($ownerType, $ownerId, $clientId, $clientRedirectUri = null);
/**
* Associate a scope with a session
* @param \League\OAuth2\Server\Entity\SessionEntity $scope The scope
* @param \League\OAuth2\Server\Entity\ScopeEntity $scope The scope
* @return void
*/
public function associateScope(SessionEntity $session, ScopeEntity $scope);
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* OAuth 2.0 Storage interface
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Storage;
use League\OAuth2\Server\AbstractServer;
/**
* Storage interface
*/
interface StorageInterface
{
/**
* Set the server
* @param \League\OAuth2\Server\AbstractServer $server
*/
public function setServer(AbstractServer $server);
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* OAuth 2.0 Abstract Token Type
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\TokenType;
use Symfony\Component\HttpFoundation\Request;
use League\OAuth2\Server\AbstractServer;
use League\OAuth2\Server\Entity\SessionEntity;
abstract class AbstractTokenType
{
/**
* Response array
* @var array
*/
protected $response = [];
/**
* Server
* @var \League\OAuth2\Server\AbstractServer $server
*/
protected $server;
/**
* Server
* @var \League\OAuth2\Server\Entity\SessionEntity $session
*/
protected $session;
/**
* Set the server
* @param \League\OAuth2\Server\AbstractServer $server
*/
public function setServer(AbstractServer $server)
{
$this->server = $server;
return $this;
}
/**
* Set the session entity
* @param \League\OAuth2\Server\Entity\SessionEntity $session
*/
public function setSession(SessionEntity $session)
{
$this->session = $session;
return $this;
}
/**
* Set a key/value response pair
* @param string $key
* @param mixed $value
*/
public function setParam($key, $value)
{
$this->response[$key] = $value;
}
/**
* Get a key from the response array
* @param string $key
* @return mixed
*/
public function getParam($key)
{
return isset($this->response[$key]) ? $this->response[$key] : null;
}
/**
* Determine the access token in the authorization header
* @param \Symfony\Component\HttpFoundation\Request $request
* @return string
*/
abstract public function determineAccessTokenInHeader(Request $request);
}

46
src/TokenType/Bearer.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
/**
* OAuth 2.0 Bearer Token Type
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\TokenType;
use Symfony\Component\HttpFoundation\Request;
class Bearer extends AbstractTokenType implements TokenTypeInterface
{
/**
* {@inheritdoc}
*/
public function generateResponse()
{
$return = [
'access_token' => $this->getParam('access_token'),
'token_type' => 'Bearer',
'expires_in' => $this->getParam('expires_in')
];
if (!is_null($this->getParam('refresh_token'))) {
$return['refresh_token'] = $this->getParam('refresh_token');
}
return $return;
}
/**
* {@inheritdoc}
*/
public function determineAccessTokenInHeader(Request $request)
{
$header = $request->headers->get('Authorization');
$accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $header));
return ($accessToken === 'Bearer') ? '' : $accessToken;
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* OAuth 2.0 Token Type Interface
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\TokenType;
interface TokenTypeInterface
{
/**
* Generate a response
* @return array
*/
public function generateResponse();
}

View File

@@ -1,27 +1,22 @@
<?php
/**
* OAuth 2.0 Secure key generator
* OAuth 2.0 Secure key interface
*
* @package lncd/oauth2
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 University of Lincoln
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link http://github.com/lncd/oauth2
* @link https://github.com/thephpleague/oauth2-server
*/
namespace OAuth2\Util;
namespace League\OAuth2\Server\Util\KeyAlgorithm;
/**
* SecureKey class
*/
class SecureKey
class DefaultAlgorithm implements KeyAlgorithmInterface
{
/**
* Generate a new unique code
* @param integer $len Length of the generated code
* @return string
* {@inheritdoc}
*/
public static function make($len = 40)
public function generate($len = 40)
{
// We generate twice as many bytes here because we want to ensure we have
// enough after we base64 encode it to get the length we need because we
@@ -37,4 +32,4 @@ class SecureKey
return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $len);
}
}
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* OAuth 2.0 Secure key interface
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Util\KeyAlgorithm;
interface KeyAlgorithmInterface
{
/**
* Generate a new unique code
* @param integer $len Length of the generated code
* @return string
*/
public function generate($len);
}

32
src/Util/RedirectUri.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
/**
* OAuth 2.0 Redirect URI generator
*
* @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) Alex Bilbie
* @license http://mit-license.org/
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\Util;
/**
* RedirectUri class
*/
class RedirectUri
{
/**
* Generate a new redirect uri
* @param string $uri The base URI
* @param array $params The query string parameters
* @param string $queryDelimeter The query string delimeter (default: "?")
* @return string The updated URI
*/
public static function make($uri, $params = array(), $queryDelimeter = '?')
{
$uri .= (strstr($uri, $queryDelimeter) === false) ? $queryDelimeter : '&';
return $uri.http_build_query($params);
}
}

53
src/Util/SecureKey.php Normal file
View File

@@ -0,0 +1,53 @@
<?php
/**
* OAuth 2.0 Secure key generator
*
* @package php-loep/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com>
* @copyright Copyright (c) 2013 PHP League of Extraordinary Packages
* @license http://mit-license.org/
* @link http://github.com/php-loep/oauth2-server
*/
namespace League\OAuth2\Server\Util;
use League\OAuth2\Server\Util\KeyAlgorithm\DefaultAlgorithm;
use League\OAuth2\Server\Util\KeyAlgorithm\KeyAlgorithmInterface;
/**
* SecureKey class
*/
class SecureKey
{
protected static $algorithm;
/**
* Generate a new unique code
* @param integer $len Length of the generated code
* @return string
*/
public static function generate($len = 40)
{
return self::getAlgorithm()->generate($len);
}
/**
* @param KeyAlgorithmInterface $algorithm
*/
public static function setAlgorithm(KeyAlgorithmInterface $algorithm)
{
self::$algorithm = $algorithm;
}
/**
* @return KeyAlgorithmInterface
*/
public static function getAlgorithm()
{
if (is_null(self::$algorithm)) {
self::$algorithm = new DefaultAlgorithm();
}
return self::$algorithm;
}
}

View File

@@ -1,608 +0,0 @@
<?php
use \Mockery as m;
class Authorization_Server_test extends PHPUnit_Framework_TestCase
{
private $client;
private $session;
private $scope;
public function setUp()
{
$this->client = M::mock('OAuth2\Storage\ClientInterface');
$this->session = M::mock('OAuth2\Storage\SessionInterface');
$this->scope = M::mock('OAuth2\Storage\ScopeInterface');
}
private function returnDefault()
{
return new OAuth2\AuthServer($this->client, $this->session, $this->scope);
}
/**
* @expectedException PHPUnit_Framework_Error
*/
public function test__construct_NoStorage()
{
$a = new OAuth2\AuthServer;
}
public function test__contruct_WithStorage()
{
$a = $this->returnDefault();
}
public function test_getExceptionMessage()
{
$m = OAuth2\AuthServer::getExceptionMessage('access_denied');
$reflector = new ReflectionClass($this->returnDefault());
$exceptionMessages = $reflector->getProperty('exceptionMessages');
$exceptionMessages->setAccessible(true);
$v = $exceptionMessages->getValue();
$this->assertEquals($v['access_denied'], $m);
}
public function test_getExceptionCode()
{
$this->assertEquals('access_denied', OAuth2\AuthServer::getExceptionType(2));
}
public function test_hasGrantType()
{
$this->assertFalse(OAuth2\AuthServer::hasGrantType('test'));
}
public function test_addGrantType()
{
$a = $this->returnDefault();
$grant = M::mock('OAuth2\Grant\GrantTypeInterface');
$grant->shouldReceive('getResponseType')->andReturn('test');
$a->addGrantType($grant, 'test');
$this->assertTrue(OAuth2\AuthServer::hasGrantType('test'));
}
public function test_addGrantType_noIdentifier()
{
$a = $this->returnDefault();
$grant = M::mock('OAuth2\Grant\GrantTypeInterface');
$grant->shouldReceive('getIdentifier')->andReturn('test');
$grant->shouldReceive('getResponseType')->andReturn('test');
$a->addGrantType($grant);
$this->assertTrue(OAuth2\AuthServer::hasGrantType('test'));
}
public function test_getScopeDelimeter()
{
$a = $this->returnDefault();
$this->assertEquals(',', $a->getScopeDelimeter());
}
public function test_setScopeDelimeter()
{
$a = $this->returnDefault();
$a->setScopeDelimeter(';');
$this->assertEquals(';', $a->getScopeDelimeter());
}
public function test_getExpiresIn()
{
$a = $this->returnDefault();
$a->setExpiresIn(7200);
$this->assertEquals(7200, $a::getExpiresIn());
}
public function test_setExpiresIn()
{
$a = $this->returnDefault();
$a->setScopeDelimeter(';');
$this->assertEquals(';', $a->getScopeDelimeter());
}
public function test_setRequest()
{
$a = $this->returnDefault();
$request = new OAuth2\Util\Request();
$a->setRequest($request);
$reflector = new ReflectionClass($a);
$requestProperty = $reflector->getProperty('request');
$requestProperty->setAccessible(true);
$v = $requestProperty->getValue();
$this->assertTrue($v instanceof OAuth2\Util\RequestInterface);
}
public function test_getRequest()
{
$a = $this->returnDefault();
$request = new OAuth2\Util\Request();
$a->setRequest($request);
$v = $a::getRequest();
$this->assertTrue($v instanceof OAuth2\Util\RequestInterface);
}
public function test_getStorage()
{
$a = $this->returnDefault();
$this->assertTrue($a->getStorage('session') instanceof OAuth2\Storage\SessionInterface);
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_checkAuthoriseParams_noClientId()
{
$a = $this->returnDefault();
$a->checkAuthoriseParams();
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_checkAuthoriseParams_noRedirectUri()
{
$a = $this->returnDefault();
$a->checkAuthoriseParams(array(
'client_id' => 1234
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 8
*/
public function test_checkAuthoriseParams_badClient()
{
$this->client->shouldReceive('getClient')->andReturn(false);
$a = $this->returnDefault();
$a->checkAuthoriseParams(array(
'client_id' => 1234,
'redirect_uri' => 'http://foo/redirect'
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_checkAuthoriseParams_missingResponseType()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$a = $this->returnDefault();
$a->checkAuthoriseParams(array(
'client_id' => 1234,
'redirect_uri' => 'http://foo/redirect'
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 3
*/
public function test_checkAuthoriseParams_badResponseType()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$a = $this->returnDefault();
$a->checkAuthoriseParams(array(
'client_id' => 1234,
'redirect_uri' => 'http://foo/redirect',
'response_type' => 'foo'
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_checkAuthoriseParams_missingScopes()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$a->checkAuthoriseParams(array(
'client_id' => 1234,
'redirect_uri' => 'http://foo/redirect',
'response_type' => 'code',
'scope' => ''
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 4
*/
public function test_checkAuthoriseParams_badScopes()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->scope->shouldReceive('getScope')->andReturn(false);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$a->checkAuthoriseParams(array(
'client_id' => 1234,
'redirect_uri' => 'http://foo/redirect',
'response_type' => 'code',
'scope' => 'foo'
));
}
public function test_checkAuthoriseParams_passedInput()
{
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->scope->shouldReceive('getScope')->andReturn(array(
'id' => 1,
'scope' => 'foo',
'name' => 'Foo Name',
'description' => 'Foo Name Description'
));
$v = $a->checkAuthoriseParams(array(
'client_id' => 1234,
'redirect_uri' => 'http://foo/redirect',
'response_type' => 'code',
'scope' => 'foo'
));
$this->assertEquals(array(
'client_id' => 1234,
'redirect_uri' => 'http://foo/redirect',
'client_details' => array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
),
'response_type' => 'code',
'scopes' => array(
array(
'id' => 1,
'scope' => 'foo',
'name' => 'Foo Name',
'description' => 'Foo Name Description'
)
),
'scope' => 'foo'
), $v);
}
public function test_checkAuthoriseParams()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->scope->shouldReceive('getScope')->andReturn(array(
'id' => 1,
'scope' => 'foo',
'name' => 'Foo Name',
'description' => 'Foo Name Description'
));
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$_GET['client_id'] = 1234;
$_GET['redirect_uri'] = 'http://foo/redirect';
$_GET['response_type'] = 'code';
$_GET['scope'] = 'foo';
$request = new OAuth2\Util\Request($_GET);
$a->setRequest($request);
$v = $a->checkAuthoriseParams();
$this->assertEquals(array(
'client_id' => 1234,
'redirect_uri' => 'http://foo/redirect',
'client_details' => array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
),
'response_type' => 'code',
'scopes' => array(
array(
'id' => 1,
'scope' => 'foo',
'name' => 'Foo Name',
'description' => 'Foo Name Description'
)
),
'scope' => 'foo'
), $v);
}
function test_newAuthoriseRequest()
{
$this->session->shouldReceive('deleteSession')->andReturn(null);
$this->session->shouldReceive('createSession')->andReturn(1);
$this->session->shouldReceive('associateScope')->andReturn(null);
$a = $this->returnDefault();
$params = array(
'client_id' => 1234,
'redirect_uri' => 'http://foo/redirect',
'client_details' => array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
),
'response_type' => 'code',
'scopes' => array(
array(
'id' => 1,
'scope' => 'foo',
'name' => 'Foo Name',
'description' => 'Foo Name Description'
)
)
);
$v = $a->newAuthoriseRequest('user', 123, $params);
$this->assertEquals(40, strlen($v));
}
public function test_getGrantType()
{
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$reflector = new ReflectionClass($a);
$method = $reflector->getMethod('getGrantType');
$method->setAccessible(true);
$result = $method->invoke($a, 'authorization_code');
$this->assertTrue($result instanceof OAuth2\Grant\GrantTypeInterface);
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_issueAccessToken_missingGrantType()
{
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$v = $a->issueAccessToken();
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 7
*/
public function test_issueAccessToken_badGrantType()
{
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$v = $a->issueAccessToken(array('grant_type' => 'foo'));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_issueAccessToken_missingClientId()
{
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$v = $a->issueAccessToken(array(
'grant_type' => 'authorization_code'
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_issueAccessToken_missingClientSecret()
{
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$v = $a->issueAccessToken(array(
'grant_type' => 'authorization_code',
'client_id' => 1234
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_issueAccessToken_missingRedirectUri()
{
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$v = $a->issueAccessToken(array(
'grant_type' => 'authorization_code',
'client_id' => 1234,
'client_secret' => 5678
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 8
*/
public function test_issueAccessToken_badClient()
{
$this->client->shouldReceive('getClient')->andReturn(false);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$v = $a->issueAccessToken(array(
'grant_type' => 'authorization_code',
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect'
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_issueAccessToken_missingCode()
{
$this->client->shouldReceive('getClient')->andReturn(array());
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$v = $a->issueAccessToken(array(
'grant_type' => 'authorization_code',
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect'
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 9
*/
public function test_issueAccessToken_badCode()
{
$this->client->shouldReceive('getClient')->andReturn(array());
$this->session->shouldReceive('validateAuthCode')->andReturn(false);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$v = $a->issueAccessToken(array(
'grant_type' => 'authorization_code',
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'code' => 'foobar'
));
}
public function test_issueAccessToken_passedInput()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('updateSession')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$v = $a->issueAccessToken(array(
'grant_type' => 'authorization_code',
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'code' => 'foobar'
));
$this->assertArrayHasKey('access_token', $v);
$this->assertArrayHasKey('token_type', $v);
$this->assertArrayHasKey('expires', $v);
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a::getExpiresIn(), $v['expires_in']);
$this->assertEquals(time()+$a::getExpiresIn(), $v['expires']);
}
public function test_issueAccessToken()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('updateSession')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$_POST['grant_type'] = 'authorization_code';
$_POST['client_id'] = 1234;
$_POST['client_secret'] = 5678;
$_POST['redirect_uri'] = 'http://foo/redirect';
$_POST['code'] = 'foobar';
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken();
$this->assertArrayHasKey('access_token', $v);
$this->assertArrayHasKey('token_type', $v);
$this->assertArrayHasKey('expires', $v);
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a::getExpiresIn(), $v['expires_in']);
$this->assertEquals(time()+$a::getExpiresIn(), $v['expires']);
}
public function tearDown() {
M::close();
}
}

View File

@@ -1,189 +0,0 @@
<?php
use \Mockery as m;
class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
{
private $client;
private $session;
private $scope;
public function setUp()
{
$this->client = M::mock('OAuth2\Storage\ClientInterface');
$this->session = M::mock('OAuth2\Storage\SessionInterface');
$this->scope = M::mock('OAuth2\Storage\ScopeInterface');
}
private function returnDefault()
{
return new OAuth2\AuthServer($this->client, $this->session, $this->scope);
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_issueAccessToken_clientCredentialsGrant_missingClientId()
{
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\ClientCredentials());
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken(array(
'grant_type' => 'client_credentials'
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_issueAccessToken_clientCredentialsGrant_missingClientPassword()
{
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\ClientCredentials());
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken(array(
'grant_type' => 'client_credentials',
'client_id' => 1234
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 8
*/
public function test_issueAccessToken_clientCredentialsGrant_badClient()
{
$this->client->shouldReceive('getClient')->andReturn(false);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\ClientCredentials());
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken(array(
'grant_type' => 'client_credentials',
'client_id' => 1234,
'client_secret' => 5678
));
}
function test_issueAccessToken_clientCredentialsGrant_passedInput()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->client->shouldReceive('validateRefreshToken')->andReturn(1);
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('createSession')->andReturn(1);
$this->session->shouldReceive('deleteSession')->andReturn(null);
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\ClientCredentials());
$v = $a->issueAccessToken(array(
'grant_type' => 'client_credentials',
'client_id' => 1234,
'client_secret' => 5678
));
$this->assertArrayHasKey('access_token', $v);
$this->assertArrayHasKey('token_type', $v);
$this->assertArrayHasKey('expires', $v);
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a::getExpiresIn(), $v['expires_in']);
$this->assertEquals(time()+$a::getExpiresIn(), $v['expires']);
}
function test_issueAccessToken_clientCredentialsGrant()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->client->shouldReceive('validateRefreshToken')->andReturn(1);
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('createSession')->andReturn(1);
$this->session->shouldReceive('deleteSession')->andReturn(null);
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\ClientCredentials());
$_POST['grant_type'] = 'client_credentials';
$_POST['client_id'] = 1234;
$_POST['client_secret'] = 5678;
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken();
$this->assertArrayHasKey('access_token', $v);
$this->assertArrayHasKey('token_type', $v);
$this->assertArrayHasKey('expires', $v);
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a::getExpiresIn(), $v['expires_in']);
$this->assertEquals(time()+$a::getExpiresIn(), $v['expires']);
}
function test_issueAccessToken_clientCredentialsGrant_withRefreshToken()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->client->shouldReceive('validateRefreshToken')->andReturn(1);
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('createSession')->andReturn(1);
$this->session->shouldReceive('deleteSession')->andReturn(null);
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\ClientCredentials());
$a->addGrantType(new OAuth2\Grant\RefreshToken());
$_POST['grant_type'] = 'client_credentials';
$_POST['client_id'] = 1234;
$_POST['client_secret'] = 5678;
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken();
$this->assertArrayHasKey('access_token', $v);
$this->assertArrayHasKey('token_type', $v);
$this->assertArrayHasKey('expires', $v);
$this->assertArrayHasKey('expires_in', $v);
$this->assertArrayHasKey('refresh_token', $v);
$this->assertEquals($a::getExpiresIn(), $v['expires_in']);
$this->assertEquals(time()+$a::getExpiresIn(), $v['expires']);
}
}

View File

@@ -1,347 +0,0 @@
<?php
use \Mockery as m;
class Password_Grant_Test extends PHPUnit_Framework_TestCase
{
private $client;
private $session;
private $scope;
public function setUp()
{
$this->client = M::mock('OAuth2\Storage\ClientInterface');
$this->session = M::mock('OAuth2\Storage\SessionInterface');
$this->scope = M::mock('OAuth2\Storage\ScopeInterface');
}
private function returnDefault()
{
return new OAuth2\AuthServer($this->client, $this->session, $this->scope);
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_issueAccessToken_passwordGrant_missingClientId()
{
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\Password());
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken(array(
'grant_type' => 'password'
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_issueAccessToken_passwordGrant_missingClientPassword()
{
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\Password());
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken(array(
'grant_type' => 'password',
'client_id' => 1234
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 8
*/
public function test_issueAccessToken_passwordGrant_badClient()
{
$this->client->shouldReceive('getClient')->andReturn(false);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\Password());
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken(array(
'grant_type' => 'password',
'client_id' => 1234,
'client_secret' => 5678
));
}
/**
* @expectedException OAuth2\Exception\InvalidGrantTypeException
*/
function test_issueAccessToken_passwordGrant_invalidCallback()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->client->shouldReceive('validateRefreshToken')->andReturn(1);
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('createSession')->andReturn(1);
$this->session->shouldReceive('deleteSession')->andReturn(null);
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
$testCredentials = null;
$a = $this->returnDefault();
$pgrant = new OAuth2\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
$v = $a->issueAccessToken(array(
'grant_type' => 'password',
'client_id' => 1234,
'client_secret' => 5678,
'username' => 'foo',
'password' => 'bar'
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
function test_issueAccessToken_passwordGrant_missingUsername()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->client->shouldReceive('validateRefreshToken')->andReturn(1);
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('createSession')->andReturn(1);
$this->session->shouldReceive('deleteSession')->andReturn(null);
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
$testCredentials = function($u, $p) { return false; };
$a = $this->returnDefault();
$pgrant = new OAuth2\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
$v = $a->issueAccessToken(array(
'grant_type' => 'password',
'client_id' => 1234,
'client_secret' => 5678
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
function test_issueAccessToken_passwordGrant_missingPassword()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->client->shouldReceive('validateRefreshToken')->andReturn(1);
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('createSession')->andReturn(1);
$this->session->shouldReceive('deleteSession')->andReturn(null);
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
$testCredentials = function($u, $p) { return false; };
$a = $this->returnDefault();
$pgrant = new OAuth2\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
$v = $a->issueAccessToken(array(
'grant_type' => 'password',
'client_id' => 1234,
'client_secret' => 5678,
'username' => 'foo'
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
function test_issueAccessToken_passwordGrant_badCredentials()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->client->shouldReceive('validateRefreshToken')->andReturn(1);
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('createSession')->andReturn(1);
$this->session->shouldReceive('deleteSession')->andReturn(null);
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
$testCredentials = function($u, $p) { return false; };
$a = $this->returnDefault();
$pgrant = new OAuth2\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
$v = $a->issueAccessToken(array(
'grant_type' => 'password',
'client_id' => 1234,
'client_secret' => 5678,
'username' => 'foo',
'password' => 'bar'
));
}
function test_issueAccessToken_passwordGrant_passedInput()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->client->shouldReceive('validateRefreshToken')->andReturn(1);
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('createSession')->andReturn(1);
$this->session->shouldReceive('deleteSession')->andReturn(null);
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
$testCredentials = function($u, $p) { return 1; };
$a = $this->returnDefault();
$pgrant = new OAuth2\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
$v = $a->issueAccessToken(array(
'grant_type' => 'password',
'client_id' => 1234,
'client_secret' => 5678,
'username' => 'foo',
'password' => 'bar'
));
$this->assertArrayHasKey('access_token', $v);
$this->assertArrayHasKey('token_type', $v);
$this->assertArrayHasKey('expires', $v);
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a::getExpiresIn(), $v['expires_in']);
$this->assertEquals(time()+$a::getExpiresIn(), $v['expires']);
}
function test_issueAccessToken_passwordGrant()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->client->shouldReceive('validateRefreshToken')->andReturn(1);
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('createSession')->andReturn(1);
$this->session->shouldReceive('deleteSession')->andReturn(null);
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
$testCredentials = function($u, $p) { return 1; };
$a = $this->returnDefault();
$pgrant = new OAuth2\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
$_POST['grant_type'] = 'password';
$_POST['client_id'] = 1234;
$_POST['client_secret'] = 5678;
$_POST['username'] = 'foo';
$_POST['password'] = 'bar';
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken();
$this->assertArrayHasKey('access_token', $v);
$this->assertArrayHasKey('token_type', $v);
$this->assertArrayHasKey('expires', $v);
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a::getExpiresIn(), $v['expires_in']);
$this->assertEquals(time()+$a::getExpiresIn(), $v['expires']);
}
function test_issueAccessToken_passwordGrant_withRefreshToken()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->client->shouldReceive('validateRefreshToken')->andReturn(1);
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('createSession')->andReturn(1);
$this->session->shouldReceive('deleteSession')->andReturn(null);
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
$testCredentials = function($u, $p) { return 1; };
$a = $this->returnDefault();
$pgrant = new OAuth2\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
$a->addGrantType(new OAuth2\Grant\RefreshToken());
$_POST['grant_type'] = 'password';
$_POST['client_id'] = 1234;
$_POST['client_secret'] = 5678;
$_POST['username'] = 'foo';
$_POST['password'] = 'bar';
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken();
$this->assertArrayHasKey('access_token', $v);
$this->assertArrayHasKey('token_type', $v);
$this->assertArrayHasKey('expires', $v);
$this->assertArrayHasKey('expires_in', $v);
$this->assertArrayHasKey('refresh_token', $v);
$this->assertEquals($a::getExpiresIn(), $v['expires_in']);
$this->assertEquals(time()+$a::getExpiresIn(), $v['expires']);
}
}

View File

@@ -1,233 +0,0 @@
<?php
use \Mockery as m;
class Refresh_Token_test extends PHPUnit_Framework_TestCase
{
private $client;
private $session;
private $scope;
public function setUp()
{
$this->client = M::mock('OAuth2\Storage\ClientInterface');
$this->session = M::mock('OAuth2\Storage\SessionInterface');
$this->scope = M::mock('OAuth2\Storage\ScopeInterface');
}
private function returnDefault()
{
return new OAuth2\AuthServer($this->client, $this->session, $this->scope);
}
public function test_issueAccessToken_with_refresh_token()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('updateSession')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\AuthCode());
$a->addGrantType(new OAuth2\Grant\RefreshToken());
$_POST['grant_type'] = 'authorization_code';
$_POST['client_id'] = 1234;
$_POST['client_secret'] = 5678;
$_POST['redirect_uri'] = 'http://foo/redirect';
$_POST['code'] = 'foobar';
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken();
$this->assertArrayHasKey('access_token', $v);
$this->assertArrayHasKey('token_type', $v);
$this->assertArrayHasKey('expires', $v);
$this->assertArrayHasKey('expires_in', $v);
$this->assertArrayHasKey('refresh_token', $v);
$this->assertEquals($a::getExpiresIn(), $v['expires_in']);
$this->assertEquals(time()+$a::getExpiresIn(), $v['expires']);
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_issueAccessToken_refreshTokenGrant_missingClientId()
{
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\RefreshToken());
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken(array(
'grant_type' => 'refresh_token'
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_issueAccessToken_refreshTokenGrant_missingClientSecret()
{
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\RefreshToken());
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken(array(
'grant_type' => 'refresh_token',
'client_id' => 1234
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 8
*/
public function test_issueAccessToken_refreshTokenGrant_badClient()
{
$this->client->shouldReceive('getClient')->andReturn(false);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\RefreshToken());
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken(array(
'grant_type' => 'refresh_token',
'client_id' => 1234,
'client_secret' => 5678
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_issueAccessToken_refreshTokenGrant_missingRefreshToken()
{
$this->client->shouldReceive('getClient')->andReturn(array());
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\RefreshToken());
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken(array(
'grant_type' => 'refresh_token',
'client_id' => 1234,
'client_secret' => 5678,
//'refresh_token' =>
));
}
/**
* @expectedException OAuth2\Exception\ClientException
* @expectedExceptionCode 0
*/
public function test_issueAccessToken_refreshTokenGrant_badRefreshToken()
{
$this->client->shouldReceive('getClient')->andReturn(array());
$this->client->shouldReceive('validateRefreshToken')->andReturn(false);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\RefreshToken());
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken(array(
'grant_type' => 'refresh_token',
'client_id' => 1234,
'client_secret' => 5678,
'refresh_token' => 'abcdef'
));
}
public function test_issueAccessToken_refreshTokenGrant_passedInput()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->client->shouldReceive('validateRefreshToken')->andReturn(1);
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('updateSession')->andReturn(null);
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\RefreshToken());
$_POST['grant_type'] = 'refresh_token';
$_POST['client_id'] = 1234;
$_POST['client_secret'] = 5678;
$_POST['refresh_token'] = 'abcdef';
$request = new OAuth2\Util\Request(array(), $_POST);
$a->setRequest($request);
$v = $a->issueAccessToken();
$this->assertArrayHasKey('access_token', $v);
$this->assertArrayHasKey('token_type', $v);
$this->assertArrayHasKey('expires', $v);
$this->assertArrayHasKey('expires_in', $v);
$this->assertArrayHasKey('refresh_token', $v);
$this->assertEquals($a::getExpiresIn(), $v['expires_in']);
$this->assertEquals(time()+$a::getExpiresIn(), $v['expires']);
}
public function test_issueAccessToken_refreshTokenGrant()
{
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
'client_secret' => 5678,
'redirect_uri' => 'http://foo/redirect',
'name' => 'Example Client'
));
$this->client->shouldReceive('validateRefreshToken')->andReturn(1);
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
$this->session->shouldReceive('updateSession')->andReturn(null);
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new OAuth2\Grant\RefreshToken());
$v = $a->issueAccessToken(array(
'grant_type' => 'refresh_token',
'client_id' => 1234,
'client_secret' => 5678,
'refresh_token' => 'abcdef',
));
$this->assertArrayHasKey('access_token', $v);
$this->assertArrayHasKey('token_type', $v);
$this->assertArrayHasKey('expires', $v);
$this->assertArrayHasKey('expires_in', $v);
$this->assertArrayHasKey('refresh_token', $v);
$this->assertEquals($a::getExpiresIn(), $v['expires_in']);
$this->assertEquals(time()+$a::getExpiresIn(), $v['expires']);
}
}

View File

@@ -0,0 +1,9 @@
url: 'http://localhost:8000/authcode_grant.php/authorize?client_id=testclient&redirect_uri=http%3A%2F%2Fexample.com%2Fredirect&response_type=code&scope=basic'
request:
method: GET
response:
statusCode: 200
headers:
-
key: Location
valueRegex: /http:\/\/example.com\/redirect\?code=([a-zA-Z0-9]*)/

View File

@@ -0,0 +1,67 @@
url: 'http://localhost:8000/other_grants.php/access_token'
request:
method: POST
body:
-
key: client_id
value: testclient
missing:
response.statusCode: 400
headers.content-type: "application/json"
body.error: invalid_request
body.message: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"client_id\" parameter."
invalid:
response.statusCode: 401
headers.content-type: "application/json"
body.error: invalid_client
body.message: "Client authentication failed."
-
key: client_secret
value: secret
missing:
response.statusCode: 400
headers.content-type: "application/json"
body.error: invalid_request
body.message: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"client_secret\" parameter."
invalid:
response.statusCode: 401
headers.content-type: "application/json"
body.error: invalid_client
body.message: "Client authentication failed."
-
key: grant_type
value: client_credentials
missing:
response.statusCode: 400
headers.content-type: "application/json"
body.error: invalid_request
body.message: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"grant_type\" parameter."
invalid:
response.statusCode: 400
headers.content-type: "application/json"
body.error: unsupported_grant_type
#body.message: "The authorization grant type XXX is not supported by the authorization server."
-
key: scope
value: "basic"
invalid:
response.statusCode: 400
headers.content-type: "application/json"
body.error: invalid_scope
border.message: fooooooooo
response:
statusCode: 200
headers:
-
key: Content-type
value: application/json
body:
-
key: expires_in
valueType: integer
-
key: access_token
valueRegex: /([a-zA-Z0-9]*)/
-
key: token_type
value: Bearer

View File

@@ -0,0 +1,88 @@
url: 'http://localhost:8000/other_grants.php/access_token'
request:
method: POST
body:
-
key: client_id
value: testclient
missing:
response.statusCode: 400
headers.content-type: "application/json"
body.error: invalid_request
body.message: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"client_id\" parameter."
invalid:
response.statusCode: 401
headers.content-type: "application/json"
body.error: invalid_client
body.message: "Client authentication failed."
-
key: client_secret
value: secret
missing:
response.statusCode: 400
headers.content-type: "application/json"
body.error: invalid_request
body.message: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"client_secret\" parameter."
invalid:
response.statusCode: 401
headers.content-type: "application/json"
body.error: invalid_client
body.message: "Client authentication failed."
-
key: username
value: alexbilbie
missing:
response.statusCode: 400
headers.content-type: "application/json"
body.error: invalid_request
body.message: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"username\" parameter."
invalid:
response.statusCode: 401
headers.content-type: "application/json"
body.error: invalid_credentials
body.message: "The user credentials were incorrect."
-
key: password
value: whisky
missing:
response.statusCode: 400
headers.content-type: "application/json"
body.error: invalid_request
body.message: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"password\" parameter."
invalid:
response.statusCode: 401
headers.content-type: "application/json"
body.error: invalid_credentials
body.message: "The user credentials were incorrect."
-
key: grant_type
value: password
missing:
response.statusCode: 400
headers.content-type: "application/json"
body.error: invalid_request
body.message: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"grant_type\" parameter."
invalid:
response.statusCode: 400
headers.content-type: "application/json"
body.error: unsupported_grant_type
#body.message: "The authorization grant type XXX is not supported by the authorization server."
response:
statusCode: 200
headers:
-
key: Content-type
value: application/json
body:
-
key: expires_in
valueType: integer
-
key: access_token
valueRegex: /([a-zA-Z0-9]*)/
-
key: refresh_token
valueRegex: /([a-zA-Z0-9]*)/
-
key: token_type
value: Bearer

Some files were not shown because too many files have changed in this diff Show More