Compare commits

...

133 Commits
2.1 ... 3.1.2

Author SHA1 Message Date
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
Phil Sturgeon
8556f616d3 Ninja 5.6 test 2014-02-11 12:27:35 -05: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
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
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
35 changed files with 505 additions and 784 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

3
.gitignore vendored
View File

@@ -1,6 +1,5 @@
/vendor
/composer.lock
/build/logs
/build/coverage
/tests/coverage
/docs
/testing

View File

@@ -1,8 +1,18 @@
language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
matrix:
allow_failures:
- php: hhvm
before_script: composer install --dev
script: phpunit
before_script: composer install --prefer-source
script: phpunit --configuration phpunit.xml.dist
cache:
directories:
- vendor

View File

@@ -1,5 +1,42 @@
# Changelog
## 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)

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,23 +1,36 @@
# The League of Extraordinary Packages presents: PHP OAuth 2.0 Server
# PHP OAuth 2.0 Server
The goal of this project is to develop a standards compliant [OAuth 2.0](http://tools.ietf.org/wg/oauth/draft-ietf-oauth-v2/) authorization server and resource server.
[![Latest Stable Version](https://poser.pugx.org/league/oauth2-server/v/stable.png)](https://packagist.org/packages/league/oauth2-server) [![Coverage Status](https://coveralls.io/repos/thephpleague/oauth2-server/badge.png?branch=master)](https://coveralls.io/r/thephpleague/oauth2-server?branch=master) [![Total Downloads](https://poser.pugx.org/league/oauth2-server/downloads.png)](https://packagist.org/packages/league/oauth2-server) [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/thephpleague/oauth2-server/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
A standards compliant [OAuth 2.0](http://tools.ietf.org/wg/oauth/draft-ietf-oauth-v2/) authorization server and resource server written in PHP.
## Package Installation
The framework is provided as a Composer package which can be installed by adding the package to your composer.json file:
The framework is provided as a Composer package which can be installed by adding the package to your `composer.json` file:
```javascript
{
"require": {
"league/oauth2-server": "2.*"
"league/oauth2-server": "3.*"
}
}
```
### Framework Integrations
* [Laravel Service Provider](https://packagist.org/packages/lucadegasperi/oauth2-server-laravel) by @lucadegasperi
* [Laravel Eloquent implementation](https://github.com/ScubaClick/scubaclick-oauth2) by @ScubaClick (under development)
---
The library features 100% unit test code coverage. To run the tests yourself run `phpunit` from the project root.
[![Build Status](https://travis-ci.org/thephpleague/oauth2-server.png?branch=master)](https://travis-ci.org/thephpleague/oauth2-server) [master]
[![Build Status](https://travis-ci.org/thephpleague/oauth2-server.png?branch=develop)](https://travis-ci.org/thephpleague/oauth2-server) [develop]
## Current Features
### Authorization Server
@@ -29,7 +42,7 @@ The authorization server is a flexible class and the following core specificatio
* 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))
An overview of the different OAuth 2.0 grants can be found in the wiki [https://github.com/php-loep/oauth2-server/wiki/Which-OAuth-2.0-grant-should-I-use%3F](https://github.com/php-loep/oauth2-server/wiki/Which-OAuth-2.0-grant-should-I-use%3F).
An [overview of the different OAuth 2.0 grants](https://github.com/thephpleague/oauth2-server/wiki/Which-OAuth-2.0-grant-should-I-use%3F) can be found in the [wiki].
### Resource Server
@@ -37,31 +50,48 @@ The resource server allows you to secure your API endpoints by checking for a va
### Custom grants
Custom grants can be created easily by implementing an interface. Check out a guide here [https://github.com/php-loep/oauth2-server/wiki/Creating-custom-grants](https://github.com/php-loep/oauth2-server/wiki/Creating-custom-grants).
Custom grants can be created easily by implementing an interface. Check out the [custom grant guide](https://github.com/thephpleague/oauth2-server/wiki/Creating-custom-grants).
### PDO driver
## Tutorials and Documentation
If you are using MySQL and want to very quickly implement the library then all of the storage interfaces have been implemented with PDO classes. Check out the guide here [https://github.com/php-loep/oauth2-server/wiki/Using-the-PDO-storage-classes](https://github.com/php-loep/oauth2-server/wiki/Using-the-PDO-storage-classes).
* **[Wiki]** - The wiki has lots of guides on how to use this library.
## Tutorials and documentation
* **[Developing an OAuth-2.0 Authorization Server]** - A simple tutorial on how to use the authorization server.
The wiki has lots of guides on how to use this library, check it out - [https://github.com/php-loep/oauth2-server/wiki](https://github.com/php-loep/oauth2-server/wiki).
* **[Securing your API with OAuth 2.0]** - A simple tutorial on how to use the resource server to secure an API server.
A tutorial on how to use the authorization server can be found on the wiki - (https://github.com/php-loep/oauth2-server/wiki/Developing-an-OAuth-2.0-authorization-server)[https://github.com/php-loep/oauth2-server/wiki/Developing-an-OAuth-2.0-authorization-server].
[Wiki]: https://github.com/thephpleague/oauth2-server/wiki
[Securing your API with OAuth 2.0]: https://github.com/thephpleague/oauth2-server/wiki/Securing-your-API-with-OAuth-2.0
[Developing an OAuth-2.0 Authorization Server]: https://github.com/thephpleague/oauth2-server/wiki/Developing-an-OAuth-2.0-authorization-server
A tutorial on how to use the resource server to secure an API server can be found at [https://github.com/php-loep/oauth2-server/wiki/Securing-your-API-with-OAuth-2.0](https://github.com/php-loep/oauth2-server/wiki/Securing-your-API-with-OAuth-2.0).
## Changelog
## Future Goals
[See the project releases page](https://github.com/thephpleague/oauth2-server/releases)
### Authorization Server
## Contributing
* 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/).
Please see [CONTRIBUTING](https://github.com/thephpleague/oauth2-server/blob/master/CONTRIBUTING.md) for details.
---
## 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.
This code is principally developed and maintained by [@alexbilbie](https://twitter.com/alexbilbie).
A list of contributors can be found at [https://github.com/php-loep/oauth2-server/contributors](https://github.com/php-loep/oauth2-server/contributors).
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/thephpleague/oauth2-server/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

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,19 +1,19 @@
{
"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.",
"version": "2.1",
"homepage": "https://github.com/php-loep/oauth2-server",
"version": "3.1.2",
"license": "MIT",
"require": {
"php": ">=5.3.0"
"php": ">=5.4.0"
},
"require-dev": {
"mockery/mockery": ">=0.7.2"
"mockery/mockery": ">=0.7.2",
"league/phpunit-coverage-listener": "~1.0"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/php-loep/oauth2-server.git"
"url": "https://github.com/thephpleague/oauth2-server.git"
}
],
"keywords": [
@@ -23,7 +23,10 @@
"authorization",
"authentication",
"resource",
"api"
"api",
"auth",
"protect",
"secure"
],
"authors": [
{
@@ -34,8 +37,7 @@
}
],
"replace": {
"lncd/oauth2": "*",
"league/oauth2server": "*"
"lncd/oauth2": "*"
},
"autoload": {
"psr-0": {
@@ -43,6 +45,6 @@
}
},
"suggest": {
"zetacomponents/database": "Allows use of the build in PDO storage classes"
}
}
}

View File

@@ -15,17 +15,13 @@
<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">vendor</directory>
<directory suffix=".php">tests</directory>
<directory suffix=".php">testing</directory>
</blacklist>
</filter>
<logging>
<log type="coverage-html" target="build/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="build/logs/clover.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
<log type="coverage-text" target="php://stdout" title="lncd/OAuth" charset="UTF-8" yui="true" highlight="true" lowUpperBound="60" highLowerBound="99"/>
<log type="coverage-html" target="tests/coverage" title="lncd/OAuth" charset="UTF-8" yui="true" highlight="true" lowUpperBound="60" highLowerBound="99"/>
</logging>
</phpunit>
</phpunit>

53
phpunit.xml.dist Normal file
View File

@@ -0,0 +1,53 @@
<?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</directory>
<directory suffix=".php">tests</directory>
<directory suffix=".php">testing</directory>
</blacklist>
</filter>
<logging>
<log type="coverage-clover" target="/tmp/coverage.xml"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
</logging>
<listeners>
<listener class="League\PHPUnitCoverageListener\Listener">
<arguments>
<array>
<element key="printer">
<object class="League\PHPUnitCoverageListener\Printer\StdOut"/>
</element>
<element key="hook">
<object class="League\PHPUnitCoverageListener\Hook\Travis"/>
</element>
<element key="namespace">
<string>League\OAuth2\Server</string>
</element>
<element key="repo_token">
<string>DtNuuOrBh1QBXVyRqmVldC2Au11DVti9n</string>
</element>
<element key="target_url">
<string>https://coveralls.io/api/v1/jobs</string>
</element>
<element key="coverage_dir">
<string>/tmp</string>
</element>
</array>
</arguments>
</listener>
</listeners>
</phpunit>

View File

@@ -244,6 +244,10 @@ class Authorization
if (is_null($identifier)) {
$identifier = $grantType->getIdentifier();
}
// Inject server into grant
$grantType->setAuthorizationServer($this);
$this->grantTypes[$identifier] = $grantType;
if ( ! is_null($grantType->getResponseType())) {
@@ -261,6 +265,11 @@ class Authorization
return (array_key_exists($identifier, $this->grantTypes));
}
/**
* Returns response types
*
* @return array
*/
public function getResponseTypes()
{
return $this->responseTypes;
@@ -271,7 +280,7 @@ class Authorization
* @param boolean $require
* @return void
*/
public function requireScopeParam($require = false)
public function requireScopeParam($require = true)
{
$this->requireScopeParam = $require;
}
@@ -287,11 +296,12 @@ class Authorization
/**
* Default scope to be used if none is provided and requireScopeParam is false
* @var string|array
* @param string|array $default
*/
public function setDefaultScope($default = null)
{
$this->defaultScope = $default;
return $this;
}
/**
@@ -318,9 +328,10 @@ class Authorization
* @param boolean $require
* @return void
*/
public function requireStateParam($require = false)
public function requireStateParam($require = true)
{
$this->requireStateParam = $require;
return $this;
}
/**
@@ -341,6 +352,7 @@ class Authorization
public function setScopeDelimeter($scopeDelimeter = ' ')
{
$this->scopeDelimeter = $scopeDelimeter;
return $this;
}
/**
@@ -359,6 +371,7 @@ class Authorization
public function setAccessTokenTTL($accessTokenTTL = 3600)
{
$this->accessTokenTTL = $accessTokenTTL;
return $this;
}
/**
@@ -369,6 +382,7 @@ class Authorization
public function setRequest(Util\RequestInterface $request)
{
$this->request = $request;
return $this;
}
/**
@@ -381,7 +395,6 @@ class Authorization
if ($this->request === null) {
// @codeCoverageIgnoreStart
$this->request = Request::buildFromGlobals();
}
// @codeCoverageIgnoreEnd

View File

@@ -24,6 +24,8 @@ use League\OAuth2\Server\Storage\ScopeInterface;
*/
class AuthCode implements GrantTypeInterface {
use GrantTrait;
/**
* Grant identifier
* @var string
@@ -54,44 +56,6 @@ class AuthCode implements GrantTypeInterface {
*/
protected $authTokenTTL = 600;
/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
*/
public function __construct(Authorization $authServer)
{
$this->authServer = $authServer;
}
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
/**
* Override the default access token expire time
* @param int $accessTokenTTL
* @return void
*/
public function setAccessTokenTTL($accessTokenTTL)
{
$this->accessTokenTTL = $accessTokenTTL;
}
/**
* Override the default access token expire time
* @param int $authTokenTTL
@@ -276,7 +240,7 @@ class AuthCode implements GrantTypeInterface {
$response = array(
'access_token' => $accessToken,
'token_type' => 'bearer',
'token_type' => 'Bearer',
'expires' => $accessTokenExpires,
'expires_in' => $accessTokenExpiresIn
);
@@ -292,4 +256,4 @@ class AuthCode implements GrantTypeInterface {
return $response;
}
}
}

View File

@@ -24,6 +24,8 @@ use League\OAuth2\Server\Storage\ScopeInterface;
*/
class ClientCredentials implements GrantTypeInterface {
use GrantTrait;
/**
* Grant identifier
* @var string
@@ -48,16 +50,6 @@ class ClientCredentials implements GrantTypeInterface {
*/
protected $accessTokenTTL = null;
/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
*/
public function __construct(Authorization $authServer)
{
$this->authServer = $authServer;
}
/**
* Return the identifier
* @return string
@@ -163,7 +155,7 @@ class ClientCredentials implements GrantTypeInterface {
$response = array(
'access_token' => $accessToken,
'token_type' => 'bearer',
'token_type' => 'Bearer',
'expires' => $accessTokenExpires,
'expires_in' => $accessTokenExpiresIn
);

View File

@@ -0,0 +1,85 @@
<?php
/**
* OAuth 2.0 Client credentials grant
*
* @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\Grant;
use League\OAuth2\Server\Authorization;
trait GrantTrait {
/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
*/
public function __construct(Authorization $authServer = null)
{
// @codeCoverageIgnoreStart
if ($authServer instanceof Authorization) {
trigger_error(
'Server is now automatically injected into grant as of v3.1 of this library',
E_USER_DEPRECATED
);
} // @codeCoverageIgnoreEnd
}
/**
* 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;
}
/**
* 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 Authorization $authServer The authorization server instance
* @return self
*/
public function setAuthorizationServer(Authorization $authServer)
{
$this->authServer = $authServer;
return $this;
}
}

View File

@@ -23,22 +23,9 @@ interface GrantTypeInterface
{
/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
*/
public function __construct(Authorization $authServer);
/**
* Returns the grant identifier (used to validate grant_type in League\OAuth2\Server\Authorization::issueAccessToken())
* @return string
*/
public function getIdentifier();
/**
* Returns the response type (used to validate response_type in League\OAuth2\Server\Grant\AuthCode::checkAuthoriseParams())
* @return null|string
*/
public function getResponseType();
public function __construct(Authorization $authServer = null);
/**
* Complete the grant flow

View File

@@ -22,7 +22,9 @@ use League\OAuth2\Server\Storage\ScopeInterface;
/**
* Client credentials grant class
*/
class Implict implements GrantTypeInterface {
class Implicit implements GrantTypeInterface {
use GrantTrait;
/**
* Grant identifier
@@ -43,32 +45,10 @@ class Implict implements GrantTypeInterface {
protected $authServer = null;
/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
* Access token expires in override
* @var int
*/
public function __construct(Authorization $authServer)
{
$this->authServer = $authServer;
}
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
protected $accessTokenTTL = null;
/**
* Complete the client credentials grant
@@ -84,7 +64,8 @@ class Implict implements GrantTypeInterface {
$accessToken = SecureKey::make();
// Compute expiry time
$accessTokenExpires = time() + $this->authServer->getAccessTokenTTL();
$accessTokenExpiresIn = ($this->accessTokenTTL !== null) ? $this->accessTokenTTL : $this->authServer->getAccessTokenTTL();
$accessTokenExpires = time() + $accessTokenExpiresIn;
// Create a new session
$sessionId = $this->authServer->getStorage('session')->createSession($authParams['client_id'], 'user', $authParams['user_id']);
@@ -98,10 +79,13 @@ class Implict implements GrantTypeInterface {
}
$response = array(
'access_token' => $accessToken
'access_token' => $accessToken,
'token_type' => 'Bearer',
'expires' => $accessTokenExpires,
'expires_in' => $accessTokenExpiresIn,
);
return $response;
}
}
}

View File

@@ -24,6 +24,8 @@ use League\OAuth2\Server\Storage\ScopeInterface;
*/
class Password implements GrantTypeInterface {
use GrantTrait;
/**
* Grant identifier
* @var string
@@ -54,44 +56,6 @@ class Password implements GrantTypeInterface {
*/
protected $accessTokenTTL = null;
/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
*/
public function __construct(Authorization $authServer)
{
$this->authServer = $authServer;
}
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
/**
* Override the default access token expire time
* @param int $accessTokenTTL
* @return void
*/
public function setAccessTokenTTL($accessTokenTTL)
{
$this->accessTokenTTL = $accessTokenTTL;
}
/**
* Set the callback to verify a user's username and password
* @param callable $callback The callback function
@@ -206,7 +170,7 @@ class Password implements GrantTypeInterface {
$response = array(
'access_token' => $accessToken,
'token_type' => 'bearer',
'token_type' => 'Bearer',
'expires' => $accessTokenExpires,
'expires_in' => $accessTokenExpiresIn
);
@@ -222,4 +186,4 @@ class Password implements GrantTypeInterface {
return $response;
}
}
}

View File

@@ -24,6 +24,8 @@ use League\OAuth2\Server\Storage\ScopeInterface;
*/
class RefreshToken implements GrantTypeInterface {
use GrantTrait;
/**
* Grant identifier
* @var string
@@ -60,44 +62,6 @@ class RefreshToken implements GrantTypeInterface {
*/
protected $rotateRefreshTokens = false;
/**
* Constructor
* @param Authorization $authServer Authorization server instance
* @return void
*/
public function __construct(Authorization $authServer)
{
$this->authServer = $authServer;
}
/**
* Return the identifier
* @return string
*/
public function getIdentifier()
{
return $this->identifier;
}
/**
* Return the response type
* @return string
*/
public function getResponseType()
{
return $this->responseType;
}
/**
* Override the default access token expire time
* @param int $accessTokenTTL
* @return void
*/
public function setAccessTokenTTL($accessTokenTTL)
{
$this->accessTokenTTL = $accessTokenTTL;
}
/**
* Set the TTL of the refresh token
* @param int $refreshTokenTTL

View File

@@ -93,6 +93,7 @@ class Resource
public function setRequest(RequestInterface $request)
{
$this->request = $request;
return $this;
}
/**
@@ -129,6 +130,7 @@ class Resource
public function setTokenKey($key)
{
$this->tokenKey = $key;
return $this;
}
/**
@@ -173,16 +175,17 @@ class Resource
/**
* Checks if the access token is valid or not.
*
* @param $headersOnly Limit Access Token to Authorization header only
* @throws Exception\InvalidAccessTokenException Thrown if the presented access token is not valid
* @return bool
*/
public function isValid()
public function isValid($headersOnly = false)
{
$accessToken = $this->determineAccessToken();
$accessToken = $this->determineAccessToken($headersOnly);
$result = $this->storages['session']->validateAccessToken($accessToken);
if ( ! $result) {
if (! $result) {
throw new Exception\InvalidAccessTokenException('Access token is not valid');
}
@@ -194,7 +197,7 @@ class Resource
$sessionScopes = $this->storages['session']->getScopes($this->accessToken);
foreach ($sessionScopes as $scope) {
$this->sessionScopes[] = $scope['key'];
$this->sessionScopes[] = $scope['scope'];
}
return true;
@@ -224,7 +227,7 @@ class Resource
return false;
} elseif (is_array($scopes)) {
foreach ($scopes as $scope) {
if ( ! in_array($scope, $this->sessionScopes)) {
if (! in_array($scope, $this->sessionScopes)) {
return false;
}
}
@@ -237,12 +240,21 @@ class Resource
/**
* 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
*/
protected function determineAccessToken()
public function determineAccessToken($headersOnly = false)
{
if ($header = $this->getRequest()->header('Authorization')) {
// Try to get it directly from a header
if (! $header = $this->getRequest()->header('Authorization')) {
// Failing that try getting it from a server variable
$header = $this->getRequest()->server('HTTP_AUTHORIZATION');
}
// One of them worked
if ($header) {
// Check for special case, because cURL sometimes does an
// internal second request and doubles the authorization header,
// which always resulted in an error.
@@ -251,12 +263,12 @@ class Resource
// 2nd request: Authorization: Bearer XXX, Bearer XXX
if (strpos($header, ',') !== false) {
$headerPart = explode(',', $header);
$accessToken = preg_replace('/^(?:\s+)?Bearer(\s{1})/', '', $headerPart[0]);
$accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $headerPart[0]));
} else {
$accessToken = preg_replace('/^(?:\s+)?Bearer(\s{1})/', '', $header);
$accessToken = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $header));
}
$accessToken = ($accessToken === 'Bearer') ? '' : $accessToken;
} else {
} elseif ($headersOnly === false) {
$method = $this->getRequest()->server('REQUEST_METHOD');
$accessToken = $this->getRequest()->{$method}($this->tokenKey);
}
@@ -267,5 +279,4 @@ class Resource
return $accessToken;
}
}

View File

@@ -20,19 +20,21 @@ interface ClientInterface
*
* <code>
* # Client ID + redirect URI
* SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name
* SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name,
* oauth_clients.auto_approve
* FROM oauth_clients LEFT JOIN oauth_client_endpoints ON oauth_client_endpoints.client_id = oauth_clients.id
* WHERE oauth_clients.id = :clientId AND oauth_client_endpoints.redirect_uri = :redirectUri
*
* # Client ID + client secret
* SELECT oauth_clients.id, oauth_clients.secret, oauth_clients.name FROM oauth_clients WHERE
* oauth_clients.id = :clientId AND oauth_clients.secret = :clientSecret
* SELECT oauth_clients.id, oauth_clients.secret, oauth_clients.name, oauth_clients.auto_approve FROM oauth_clients
* WHERE oauth_clients.id = :clientId AND oauth_clients.secret = :clientSecret
*
* # Client ID + client secret + redirect URI
* SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name FROM
* oauth_clients LEFT JOIN oauth_client_endpoints ON oauth_client_endpoints.client_id = oauth_clients.id
* WHERE oauth_clients.id = :clientId AND oauth_clients.secret = :clientSecret AND
* oauth_client_endpoints.redirect_uri = :redirectUri
* SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name,
* oauth_clients.auto_approve FROM oauth_clients LEFT JOIN oauth_client_endpoints
* ON oauth_client_endpoints.client_id = oauth_clients.id
* WHERE oauth_clients.id = :clientId AND oauth_clients.secret = :clientSecret AND
* oauth_client_endpoints.redirect_uri = :redirectUri
* </code>
*
* Response:
@@ -44,14 +46,15 @@ interface ClientInterface
* [client secret] => (string) The client secret
* [redirect_uri] => (string) The redirect URI used in this request
* [name] => (string) The name of the client
* [auto_approve] => (bool) Whether the client should auto approve
* )
* </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")
* @param string $grantType The grant type used in the request
* @param string $grantType The grant type used in the request (default = "null")
* @return bool|array Returns false if the validation fails, array on success
*/
public function getClient($clientId, $clientSecret = null, $redirectUri = null, $grantType);
}
public function getClient($clientId, $clientSecret = null, $redirectUri = null, $grantType = null);
}

View File

@@ -1,45 +0,0 @@
<?php
namespace League\OAuth2\Server\Storage\PDO;
use League\OAuth2\Server\Storage\ClientInterface;
class Client implements ClientInterface
{
public function getClient($clientId, $clientSecret = null, $redirectUri = null, $grantType)
{
$db = \ezcDbInstance::get();
if ( ! is_null($redirectUri) && is_null($clientSecret)) {
$stmt = $db->prepare('SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name FROM oauth_clients LEFT JOIN oauth_client_endpoints ON oauth_client_endpoints.client_id = oauth_clients.id WHERE oauth_clients.id = :clientId AND oauth_client_endpoints.redirect_uri = :redirectUri');
$stmt->bindValue(':redirectUri', $redirectUri);
}
elseif ( ! is_null($clientSecret) && is_null($redirectUri)) {
$stmt = $db->prepare('SELECT oauth_clients.id, oauth_clients.secret, oauth_clients.name FROM oauth_clients WHERE oauth_clients.id = :clientId AND oauth_clients.secret = :clientSecret');
$stmt->bindValue(':clientSecret', $clientSecret);
}
elseif ( ! is_null($clientSecret) && ! is_null($redirectUri)) {
$stmt = $db->prepare('SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name FROM oauth_clients LEFT JOIN oauth_client_endpoints ON oauth_client_endpoints.client_id = oauth_clients.id WHERE oauth_clients.id = :clientId AND oauth_clients.secret = :clientSecret AND oauth_client_endpoints.redirect_uri = :redirectUri');
$stmt->bindValue(':redirectUri', $redirectUri);
$stmt->bindValue(':clientSecret', $clientSecret);
}
$stmt->bindValue(':clientId', $clientId);
$stmt->execute();
$row = $stmt->fetchObject();
if ($row === false) {
return false;
}
return array(
'client_id' => $row->id,
'client_secret' => $row->secret,
'redirect_uri' => (isset($row->redirect_uri)) ? $row->redirect_uri : null,
'name' => $row->name
);
}
}

View File

@@ -1,17 +0,0 @@
<?php
namespace League\OAuth2\Server\Storage\PDO;
class Db
{
/**
* Db constructor
* @param array|string $dsn Connection DSN string or array of parameters
* @return void
*/
public function __construct($dsn = '')
{
$db = \ezcDbFactory::create($dsn);
\ezcDbInstance::set($db);
}
}

View File

@@ -1,31 +0,0 @@
<?php
namespace League\OAuth2\Server\Storage\PDO;
use League\OAuth2\Server\Storage\ScopeInterface;
class Scope implements ScopeInterface
{
public function getScope($scope, $clientId = null, $grantType = null)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('SELECT * FROM oauth_scopes WHERE oauth_scopes.scope = :scope');
$stmt->bindValue(':scope', $scope);
$stmt->execute();
$row = $stmt->fetchObject();
if ($row === false) {
return false;
}
return array(
'id' => $row->id,
'scope' => $row->scope,
'name' => $row->name,
'description' => $row->description
);
}
}

View File

@@ -1,206 +0,0 @@
<?php
namespace League\OAuth2\Server\Storage\PDO;
use League\OAuth2\Server\Storage\SessionInterface;
class Session implements SessionInterface
{
public function createSession($clientId, $ownerType, $ownerId)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('INSERT INTO oauth_sessions (client_id, owner_type, owner_id) VALUE
(:clientId, :ownerType, :ownerId)');
$stmt->bindValue(':clientId', $clientId);
$stmt->bindValue(':ownerType', $ownerType);
$stmt->bindValue(':ownerId', $ownerId);
$stmt->execute();
return $db->lastInsertId();
}
public function deleteSession($clientId, $ownerType, $ownerId)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('DELETE FROM oauth_sessions WHERE client_id = :clientId AND
owner_type = :type AND owner_id = :typeId');
$stmt->bindValue(':clientId', $clientId);
$stmt->bindValue(':type', $ownerType);
$stmt->bindValue(':typeId', $ownerId);
$stmt->execute();
}
public function associateRedirectUri($sessionId, $redirectUri)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('INSERT INTO oauth_session_redirects (session_id, redirect_uri)
VALUE (:sessionId, :redirectUri)');
$stmt->bindValue(':sessionId', $sessionId);
$stmt->bindValue(':redirectUri', $redirectUri);
$stmt->execute();
}
public function associateAccessToken($sessionId, $accessToken, $expireTime)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('INSERT INTO oauth_session_access_tokens (session_id, access_token, access_token_expires)
VALUE (:sessionId, :accessToken, :accessTokenExpire)');
$stmt->bindValue(':sessionId', $sessionId);
$stmt->bindValue(':accessToken', $accessToken);
$stmt->bindValue(':accessTokenExpire', $expireTime);
$stmt->execute();
return $db->lastInsertId();
}
public function associateRefreshToken($accessTokenId, $refreshToken, $expireTime, $clientId)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('INSERT INTO oauth_session_refresh_tokens (session_access_token_id, refresh_token, refresh_token_expires, client_id) VALUE
(:accessTokenId, :refreshToken, :expireTime, :clientId)');
$stmt->bindValue(':accessTokenId', $accessTokenId);
$stmt->bindValue(':refreshToken', $refreshToken);
$stmt->bindValue(':expireTime', $expireTime);
$stmt->bindValue(':clientId', $clientId);
$stmt->execute();
}
public function associateAuthCode($sessionId, $authCode, $expireTime)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('INSERT INTO oauth_session_authcodes (session_id, auth_code, auth_code_expires)
VALUE (:sessionId, :authCode, :authCodeExpires)');
$stmt->bindValue(':sessionId', $sessionId);
$stmt->bindValue(':authCode', $authCode);
$stmt->bindValue(':authCodeExpires', $expireTime);
$stmt->execute();
return $db->lastInsertId();
}
public function removeAuthCode($sessionId)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('DELETE FROM oauth_session_authcodes WHERE session_id = :sessionId');
$stmt->bindValue(':sessionId', $sessionId);
$stmt->execute();
}
public function validateAuthCode($clientId, $redirectUri, $authCode)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('SELECT oauth_sessions.id AS session_id, oauth_session_authcodes.id AS authcode_id
FROM oauth_sessions JOIN oauth_session_authcodes ON oauth_session_authcodes.`session_id`
= oauth_sessions.id JOIN oauth_session_redirects ON oauth_session_redirects.`session_id`
= oauth_sessions.id WHERE oauth_sessions.client_id = :clientId AND oauth_session_authcodes.`auth_code`
= :authCode AND `oauth_session_authcodes`.`auth_code_expires` >= :time AND
`oauth_session_redirects`.`redirect_uri` = :redirectUri');
$stmt->bindValue(':clientId', $clientId);
$stmt->bindValue(':redirectUri', $redirectUri);
$stmt->bindValue(':authCode', $authCode);
$stmt->bindValue(':time', time());
$stmt->execute();
$result = $stmt->fetchObject();
return ($result === false) ? false : (array) $result;
}
public function validateAccessToken($accessToken)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('SELECT session_id, oauth_sessions.`client_id`, oauth_sessions.`owner_id`, oauth_sessions.`owner_type` FROM `oauth_session_access_tokens` JOIN oauth_sessions ON oauth_sessions.`id` = session_id WHERE access_token = :accessToken AND access_token_expires >= ' . time());
$stmt->bindValue(':accessToken', $accessToken);
$stmt->execute();
$result = $stmt->fetchObject();
return ($result === false) ? false : (array) $result;
}
public function removeRefreshToken($refreshToken)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('DELETE FROM `oauth_session_refresh_tokens` WHERE refresh_token = :refreshToken');
$stmt->bindValue(':refreshToken', $refreshToken);
$stmt->execute();
}
public function validateRefreshToken($refreshToken, $clientId)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('SELECT session_access_token_id FROM `oauth_session_refresh_tokens` WHERE
refresh_token = :refreshToken AND client_id = :clientId AND refresh_token_expires >= ' . time());
$stmt->bindValue(':refreshToken', $refreshToken);
$stmt->bindValue(':clientId', $clientId);
$stmt->execute();
$result = $stmt->fetchObject();
return ($result === false) ? false : $result->session_access_token_id;
}
public function getAccessToken($accessTokenId)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('SELECT * FROM `oauth_session_access_tokens` WHERE `id` = :accessTokenId');
$stmt->bindValue(':accessTokenId', $accessTokenId);
$stmt->execute();
$result = $stmt->fetchObject();
return ($result === false) ? false : (array) $result;
}
public function associateAuthCodeScope($authCodeId, $scopeId)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('INSERT INTO `oauth_session_authcode_scopes` (`oauth_session_authcode_id`, `scope_id`) VALUES (:authCodeId, :scopeId)');
$stmt->bindValue(':authCodeId', $authCodeId);
$stmt->bindValue(':scopeId', $scopeId);
$stmt->execute();
}
public function getAuthCodeScopes($oauthSessionAuthCodeId)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('SELECT scope_id FROM `oauth_session_authcode_scopes` WHERE oauth_session_authcode_id = :authCodeId');
$stmt->bindValue(':authCodeId', $oauthSessionAuthCodeId);
$stmt->execute();
return $stmt->fetchAll();
}
public function associateScope($accessTokenId, $scopeId)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('INSERT INTO `oauth_session_token_scopes` (`session_access_token_id`, `scope_id`)
VALUE (:accessTokenId, :scopeId)');
$stmt->bindValue(':accessTokenId', $accessTokenId);
$stmt->bindValue(':scopeId', $scopeId);
$stmt->execute();
}
public function getScopes($accessToken)
{
$db = \ezcDbInstance::get();
$stmt = $db->prepare('SELECT oauth_scopes.* FROM oauth_session_token_scopes JOIN oauth_session_access_tokens ON oauth_session_access_tokens.`id` = `oauth_session_token_scopes`.`session_access_token_id` JOIN oauth_scopes ON oauth_scopes.id = `oauth_session_token_scopes`.`scope_id` WHERE access_token = :accessToken');
$stmt->bindValue(':accessToken', $accessToken);
$stmt->execute();
return $stmt->fetchAll();
}
}

View File

@@ -35,8 +35,8 @@ interface ScopeInterface
* </code>
*
* @param string $scope The scope
* @param string $clientId The client ID
* @param string $grantType The grant type used in the request
* @param string $clientId The client ID (default = "null")
* @param string $grantType The grant type used in the request (default = "null")
* @return bool|array If the scope doesn't exist return false
*/
public function getScope($scope, $clientId = null, $grantType = null);

View File

@@ -74,7 +74,7 @@ interface SessionInterface
* @param int $sessionId The session ID
* @param string $accessToken The access token
* @param int $expireTime Unix timestamp of the access token expiry time
* @return void
* @return int The access token ID
*/
public function associateAccessToken($sessionId, $accessToken, $expireTime);
@@ -208,7 +208,7 @@ interface SessionInterface
* AND refresh_token_expires >= UNIX_TIMESTAMP(NOW()) AND client_id = :clientId
* </code>
*
* @param string $refreshToken The access token
* @param string $refreshToken The refresh token
* @param string $clientId The client ID
* @return int|bool The ID of the access token the refresh token is linked to (or false if invalid)
*/
@@ -315,7 +315,8 @@ interface SessionInterface
* <code>
* array (
* array(
* 'key' => (string),
* 'id' => (int),
* 'scope' => (string),
* 'name' => (string),
* 'description' => (string)
* ),

View File

@@ -39,6 +39,8 @@ class Request implements RequestInterface
if (empty($headers)) {
$this->headers = $this->readHeaders();
} else {
$this->headers = $this->normalizeHeaders($headers);
}
}
@@ -88,7 +90,7 @@ class Request implements RequestInterface
}
}
return $headers;
return $this->normalizeHeaders($headers);
}
protected function getPropertyValue($property, $index = null, $default = null)
@@ -106,4 +108,39 @@ class Request implements RequestInterface
return $this->{$property}[$index];
}
/**
* Takes all of the headers and normalizes them in a canonical form.
*
* @param array $headers The request headers.
* @return array An arry of headers with the header name normalized
*/
protected function normalizeHeaders(array $headers)
{
$normalized = array();
foreach ($headers as $key => $value) {
$normalized[ucfirst($this->normalizeKey($key))] = $value;
}
return $normalized;
}
/**
* Transform header name into canonical form
*
* Taken from the Slim codebase...
*
* @param string $key
* @return string
*/
protected function normalizeKey($key)
{
$key = strtolower($key);
$key = str_replace(array('-', '_'), ' ', $key);
$key = preg_replace('#^http #', '', $key);
$key = ucwords($key);
$key = str_replace(' ', '-', $key);
return $key;
}
}

View File

@@ -14,10 +14,6 @@ namespace League\OAuth2\Server\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);

View File

@@ -20,10 +20,26 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
return new League\OAuth2\Server\Authorization($this->client, $this->session, $this->scope);
}
public function test_setAuthTokenTTL()
/**
* @expectedException PHPUnit_Framework_Error
*/
public function test__construct()
{
$a = $this->returnDefault();
$grant = new League\OAuth2\Server\Grant\AuthCode($a);
}
public function test_setIdentifier()
{
$grant = new League\OAuth2\Server\Grant\AuthCode();
$grant->setIdentifier('foobar');
$this->assertEquals($grant->getIdentifier(), 'foobar');
}
public function test_setAuthTokenTTL()
{
$a = $this->returnDefault();
$grant = new League\OAuth2\Server\Grant\AuthCode();
$grant->setAuthTokenTTL(30);
$reflector = new ReflectionClass($grant);
@@ -41,7 +57,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
public function test_checkAuthoriseParams_noClientId()
{
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$g->checkAuthoriseParams();
}
@@ -53,7 +69,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
public function test_checkAuthoriseParams_noRedirectUri()
{
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$g->checkAuthoriseParams(array(
'client_id' => 1234
@@ -67,7 +83,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
public function test_checkAuthoriseParams_noRequiredState()
{
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->requireStateParam(true);
$g->checkAuthoriseParams(array(
@@ -86,7 +102,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
$this->client->shouldReceive('getClient')->andReturn(false);
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$g->checkAuthoriseParams(array(
'client_id' => 1234,
@@ -108,7 +124,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
));
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$g->checkAuthoriseParams(array(
'client_id' => 1234,
@@ -130,7 +146,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
));
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$g->checkAuthoriseParams(array(
'client_id' => 1234,
@@ -153,9 +169,9 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
));
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->requireScopeParam(true);
$g->checkAuthoriseParams(array(
@@ -183,9 +199,9 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
));
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->setDefaultScope('test.scope');
$a->requireScopeParam(false);
@@ -217,9 +233,9 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
));
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->setDefaultScope(array('test.scope', 'test.scope2'));
$a->requireScopeParam(false);
@@ -250,9 +266,9 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
$this->scope->shouldReceive('getScope')->andReturn(false);
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$g->checkAuthoriseParams(array(
'client_id' => 1234,
@@ -265,9 +281,9 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
public function test_checkAuthoriseParams_passedInput()
{
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$this->client->shouldReceive('getClient')->andReturn(array(
'client_id' => 1234,
@@ -331,9 +347,9 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
));
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$_GET['client_id'] = 1234;
$_GET['redirect_uri'] = 'http://foo/redirect';
@@ -380,7 +396,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateAuthCodeScope')->andReturn(null);
$a = $this->returnDefault();
$g = new League\OAuth2\Server\Grant\AuthCode($a);
$g = new League\OAuth2\Server\Grant\AuthCode();
$a->addGrantType($g);
$params = array(

View File

@@ -69,6 +69,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
$a = $this->returnDefault();
$grant = M::mock('League\OAuth2\Server\Grant\GrantTypeInterface');
$grant->shouldReceive('getResponseType')->andReturn('test');
$grant->shouldReceive('setAuthorizationServer')->andReturn($grant);
$a->addGrantType($grant, 'test');
$this->assertTrue($a->hasGrantType('test'));
@@ -80,6 +81,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
$grant = M::mock('League\OAuth2\Server\Grant\GrantTypeInterface');
$grant->shouldReceive('getIdentifier')->andReturn('test');
$grant->shouldReceive('getResponseType')->andReturn('test');
$grant->shouldReceive('setAuthorizationServer')->andReturn($grant);
$a->addGrantType($grant);
$this->assertTrue($a->hasGrantType('test'));
@@ -199,7 +201,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
public function test_getGrantType()
{
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$reflector = new ReflectionClass($a);
$method = $reflector->getMethod('getGrantType');
@@ -227,7 +229,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
public function test_issueAccessToken_missingGrantType()
{
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->issueAccessToken();
}
@@ -239,7 +241,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
public function test_issueAccessToken_badGrantType()
{
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->issueAccessToken(array('grant_type' => 'foo'));
}
@@ -251,7 +253,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
public function test_issueAccessToken_missingClientId()
{
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->issueAccessToken(array(
'grant_type' => 'authorization_code'
@@ -265,7 +267,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
public function test_issueAccessToken_missingClientSecret()
{
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->issueAccessToken(array(
'grant_type' => 'authorization_code',
@@ -280,7 +282,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
public function test_issueAccessToken_missingRedirectUri()
{
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->issueAccessToken(array(
'grant_type' => 'authorization_code',
@@ -298,7 +300,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
$this->client->shouldReceive('getClient')->andReturn(false);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->issueAccessToken(array(
'grant_type' => 'authorization_code',
@@ -317,7 +319,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
$this->client->shouldReceive('getClient')->andReturn(array());
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->issueAccessToken(array(
'grant_type' => 'authorization_code',
@@ -337,7 +339,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('validateAuthCode')->andReturn(false);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->issueAccessToken(array(
'grant_type' => 'authorization_code',
@@ -368,7 +370,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('getAuthCodeScopes')->andReturn(array('scope_id' => 1));
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$v = $a->issueAccessToken(array(
'grant_type' => 'authorization_code',
@@ -384,7 +386,6 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}
public function test_issueAccessToken()
@@ -404,7 +405,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateScope')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$_POST['grant_type'] = 'authorization_code';
$_POST['client_id'] = 1234;
@@ -423,7 +424,6 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}
public function test_issueAccessToken_customExpiresIn()
@@ -443,7 +443,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateScope')->andReturn(null);
$a = $this->returnDefault();
$grant = new League\OAuth2\Server\Grant\AuthCode($a);
$grant = new League\OAuth2\Server\Grant\AuthCode();
$grant->setAccessTokenTTL(30);
$a->addGrantType($grant);
@@ -486,7 +486,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateScope')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$_POST['grant_type'] = 'authorization_code';
$_SERVER['PHP_AUTH_USER'] = 1234;
@@ -505,7 +505,6 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}
public function tearDown() {

View File

@@ -27,7 +27,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
public function test_issueAccessToken_clientCredentialsGrant_missingClientId()
{
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a));
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials());
$request = new League\OAuth2\Server\Util\Request(array(), $_POST);
$a->setRequest($request);
@@ -44,7 +44,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
public function test_issueAccessToken_clientCredentialsGrant_missingClientPassword()
{
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a));
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials());
$request = new League\OAuth2\Server\Util\Request(array(), $_POST);
$a->setRequest($request);
@@ -64,7 +64,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->client->shouldReceive('getClient')->andReturn(false);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a));
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials());
$request = new League\OAuth2\Server\Util\Request(array(), $_POST);
$a->setRequest($request);
@@ -95,7 +95,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('deleteSession')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a));
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials());
$a->requireScopeParam(true);
$a->issueAccessToken(array(
@@ -129,7 +129,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateAccessToken')->andReturn(1);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a));
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials());
$a->requireScopeParam(false);
$a->setDefaultScope('foobar');
@@ -170,7 +170,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateAccessToken')->andReturn(1);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a));
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials());
$a->requireScopeParam(false);
$a->setDefaultScope(array('foobar', 'barfoo'));
@@ -209,7 +209,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateScope')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a));
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials());
$a->issueAccessToken(array(
'grant_type' => 'client_credentials',
@@ -243,7 +243,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateAccessToken')->andReturn(1);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a));
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials());
$v = $a->issueAccessToken(array(
'grant_type' => 'client_credentials',
@@ -275,7 +275,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateAccessToken')->andReturn(1);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a));
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials());
$a->requireScopeParam(false);
$v = $a->issueAccessToken(array(
@@ -290,7 +290,6 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}
function test_issueAccessToken_clientCredentialsGrant()
@@ -310,7 +309,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateAccessToken')->andReturn(1);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a));
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials());
$a->requireScopeParam(false);
$_POST['grant_type'] = 'client_credentials';
@@ -328,7 +327,6 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}
function test_issueAccessToken_clientCredentialsGrant_customExpiresIn()
@@ -348,7 +346,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateAccessToken')->andReturn(1);
$a = $this->returnDefault();
$grant = new League\OAuth2\Server\Grant\ClientCredentials($a);
$grant = new League\OAuth2\Server\Grant\ClientCredentials();
$grant->setAccessTokenTTL(30);
$a->addGrantType($grant);
$a->requireScopeParam(false);
@@ -390,7 +388,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateAccessToken')->andReturn(1);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a));
$a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials());
$a->requireScopeParam(false);
$_POST['grant_type'] = 'client_credentials';
@@ -408,7 +406,6 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}
}

View File

@@ -27,7 +27,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
public function test_issueAccessToken_passwordGrant_missingClientId()
{
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\Password($a));
$a->addGrantType(new League\OAuth2\Server\Grant\Password());
$request = new League\OAuth2\Server\Util\Request(array(), $_POST);
$a->setRequest($request);
@@ -44,7 +44,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
public function test_issueAccessToken_passwordGrant_missingClientPassword()
{
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\Password($a));
$a->addGrantType(new League\OAuth2\Server\Grant\Password());
$request = new League\OAuth2\Server\Util\Request(array(), $_POST);
$a->setRequest($request);
@@ -64,7 +64,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$this->client->shouldReceive('getClient')->andReturn(false);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\Password($a));
$a->addGrantType(new League\OAuth2\Server\Grant\Password());
$request = new League\OAuth2\Server\Util\Request(array(), $_POST);
$a->setRequest($request);
@@ -98,7 +98,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$testCredentials = null;
$a = $this->returnDefault();
$pgrant = new League\OAuth2\Server\Grant\Password($a);
$pgrant = new League\OAuth2\Server\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
@@ -134,7 +134,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$testCredentials = function() { return false; };
$a = $this->returnDefault();
$pgrant = new League\OAuth2\Server\Grant\Password($a);
$pgrant = new League\OAuth2\Server\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
@@ -168,7 +168,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$testCredentials = function() { return false; };
$a = $this->returnDefault();
$pgrant = new League\OAuth2\Server\Grant\Password($a);
$pgrant = new League\OAuth2\Server\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
@@ -203,7 +203,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$testCredentials = function() { return false; };
$a = $this->returnDefault();
$pgrant = new League\OAuth2\Server\Grant\Password($a);
$pgrant = new League\OAuth2\Server\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
@@ -240,7 +240,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$testCredentials = function() { return 1; };
$a = $this->returnDefault();
$pgrant = new League\OAuth2\Server\Grant\Password($a);
$pgrant = new League\OAuth2\Server\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
@@ -276,7 +276,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$testCredentials = function() { return 1; };
$a = $this->returnDefault();
$pgrant = new League\OAuth2\Server\Grant\Password($a);
$pgrant = new League\OAuth2\Server\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
$a->requireScopeParam(true);
@@ -317,7 +317,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$testCredentials = function() { return 1; };
$a = $this->returnDefault();
$pgrant = new League\OAuth2\Server\Grant\Password($a);
$pgrant = new League\OAuth2\Server\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
$a->requireScopeParam(false);
@@ -365,7 +365,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$testCredentials = function() { return 1; };
$a = $this->returnDefault();
$pgrant = new League\OAuth2\Server\Grant\Password($a);
$pgrant = new League\OAuth2\Server\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
$a->requireScopeParam(false);
@@ -413,7 +413,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$testCredentials = function() { return 1; };
$a = $this->returnDefault();
$pgrant = new League\OAuth2\Server\Grant\Password($a);
$pgrant = new League\OAuth2\Server\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
@@ -452,7 +452,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$testCredentials = function() { return 1; };
$a = $this->returnDefault();
$pgrant = new League\OAuth2\Server\Grant\Password($a);
$pgrant = new League\OAuth2\Server\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
$a->requireScopeParam(false);
@@ -471,7 +471,6 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}
function test_issueAccessToken_passwordGrant()
@@ -494,7 +493,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$testCredentials = function() { return 1; };
$a = $this->returnDefault();
$pgrant = new League\OAuth2\Server\Grant\Password($a);
$pgrant = new League\OAuth2\Server\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
$a->requireScopeParam(false);
@@ -516,7 +515,6 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}
function test_issueAccessToken_passwordGrant_customExpiresIn()
@@ -539,7 +537,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$testCredentials = function() { return 1; };
$a = $this->returnDefault();
$pgrant = new League\OAuth2\Server\Grant\Password($a);
$pgrant = new League\OAuth2\Server\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$pgrant->setAccessTokenTTL(30);
$a->addGrantType($pgrant);
@@ -587,10 +585,10 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$testCredentials = function() { return 1; };
$a = $this->returnDefault();
$pgrant = new League\OAuth2\Server\Grant\Password($a);
$pgrant = new League\OAuth2\Server\Grant\Password();
$pgrant->setVerifyCredentialsCallback($testCredentials);
$a->addGrantType($pgrant);
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a));
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken());
$a->requireScopeParam(false);
$_POST['grant_type'] = 'password';
@@ -611,7 +609,5 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('refresh_token', $v);
$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}
}

View File

@@ -23,7 +23,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
public function test_setRefreshTokenTTL()
{
$a = $this->returnDefault();
$rt = new League\OAuth2\Server\Grant\RefreshToken($a);
$rt = new League\OAuth2\Server\Grant\RefreshToken();
$rt->setRefreshTokenTTL(30);
$this->assertEquals(30, $rt->getRefreshTokenTTL());
}
@@ -46,8 +46,8 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('getAuthCodeScopes')->andReturn(array('scope_id' => 1));
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a));
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a));
$a->addGrantType(new League\OAuth2\Server\Grant\AuthCode());
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken());
$_POST['grant_type'] = 'authorization_code';
$_POST['client_id'] = 1234;
@@ -67,7 +67,6 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('refresh_token', $v);
$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}
/**
@@ -77,7 +76,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
public function test_issueAccessToken_refreshTokenGrant_missingClientId()
{
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a));
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken());
$request = new League\OAuth2\Server\Util\Request(array(), $_POST);
$a->setRequest($request);
@@ -94,7 +93,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
public function test_issueAccessToken_refreshTokenGrant_missingClientSecret()
{
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a));
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken());
$request = new League\OAuth2\Server\Util\Request(array(), $_POST);
$a->setRequest($request);
@@ -114,7 +113,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$this->client->shouldReceive('getClient')->andReturn(false);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a));
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken());
$request = new League\OAuth2\Server\Util\Request(array(), $_POST);
$a->setRequest($request);
@@ -135,7 +134,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$this->client->shouldReceive('getClient')->andReturn(array());
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a));
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken());
$request = new League\OAuth2\Server\Util\Request(array(), $_POST);
$a->setRequest($request);
@@ -157,7 +156,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('validateRefreshToken')->andReturn(false);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a));
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken());
$request = new League\OAuth2\Server\Util\Request(array(), $_POST);
$a->setRequest($request);
@@ -190,7 +189,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('getScopes')->andReturn(array());
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a));
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken());
$_POST['grant_type'] = 'refresh_token';
$_POST['client_id'] = 1234;
@@ -208,7 +207,6 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}
public function test_issueAccessToken_refreshTokenGrant()
@@ -232,7 +230,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateScope')->andReturn(null);
$a = $this->returnDefault();
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a));
$a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken());
$v = $a->issueAccessToken(array(
'grant_type' => 'refresh_token',
@@ -247,7 +245,6 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('expires_in', $v);
$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}
public function test_issueAccessToken_refreshTokenGrant_rotateTokens()
@@ -272,7 +269,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$a = $this->returnDefault();
$rt = new League\OAuth2\Server\Grant\RefreshToken($a);
$rt = new League\OAuth2\Server\Grant\RefreshToken();
$rt->rotateRefreshTokens(true);
$a->addGrantType($rt);
@@ -290,7 +287,6 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$this->assertArrayHasKey('refresh_token', $v);
$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}
public function test_issueAccessToken_refreshTokenGrant_customExpiresIn()
@@ -314,7 +310,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$this->session->shouldReceive('associateScope')->andReturn(null);
$a = $this->returnDefault();
$grant = new League\OAuth2\Server\Grant\RefreshToken($a);
$grant = new League\OAuth2\Server\Grant\RefreshToken();
$grant->setAccessTokenTTL(30);
$a->addGrantType($grant);
@@ -358,7 +354,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$this->scope->shouldReceive('getScope')->andReturn(array('id' => 1, 'scope' => 'foo'));
$a = $this->returnDefault();
$grant = new League\OAuth2\Server\Grant\RefreshToken($a);
$grant = new League\OAuth2\Server\Grant\RefreshToken();
$grant->setAccessTokenTTL(30);
$grant->rotateRefreshTokens(true);
$a->addGrantType($grant);
@@ -409,7 +405,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
$this->scope->shouldReceive('getScope')->andReturn(array('id' => 1, 'scope' => 'foo'));
$a = $this->returnDefault();
$grant = new League\OAuth2\Server\Grant\RefreshToken($a);
$grant = new League\OAuth2\Server\Grant\RefreshToken();
$grant->setAccessTokenTTL(30);
$grant->rotateRefreshTokens(true);
$a->addGrantType($grant);

View File

@@ -196,8 +196,8 @@ class Resource_Server_test extends PHPUnit_Framework_TestCase
));
$this->session->shouldReceive('getScopes')->andReturn(array(
array('key' => 'foo'),
array('key' => 'bar')
array('scope' => 'foo'),
array('scope' => 'bar')
));
$request = new League\OAuth2\Server\Util\Request();

View File

@@ -59,6 +59,20 @@ class Request_test extends PHPUnit_Framework_TestCase
$this->assertEquals(array('Host' => 'foobar.com'), $this->request->header());
}
function test_canonical_header()
{
$request = new League\OAuth2\Server\Util\Request(
array('foo' => 'bar'),
array('foo' => 'bar'),
array('foo' => 'bar'),
array('foo' => 'bar'),
array('HTTP_HOST' => 'foobar.com'),
array('authorization' => 'Bearer ajdfkljadslfjasdlkj')
);
$this->assertEquals('Bearer ajdfkljadslfjasdlkj', $request->header('Authorization'));
}
/**
* @expectedException InvalidArgumentException
*/