Skip to content

Commit

Permalink
Merge branch 'release/3.1.2'
Browse files Browse the repository at this point in the history
Conflicts:
	README.md
  • Loading branch information
Phil Sturgeon committed Feb 26, 2014
2 parents 8e7a975 + 1045c70 commit 8a29226
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 38 deletions.
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ language: php
php:
- 5.4
- 5.5
- 5.6
- hhvm

matrix:
allow_failures:
- php: hhvm

before_script: composer install --prefer-source
script: phpunit --configuration phpunit.xml.dist
script: phpunit --configuration phpunit.xml.dist

cache:
directories:
- vendor
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 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)
Expand Down
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# league\oauth2-server
# PHP OAuth 2.0 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/php-loep/oauth2-server/badge.png?branch=master)](https://coveralls.io/r/php-loep/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/php-loep/oauth2-server/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Expand All @@ -7,7 +7,7 @@ A standards compliant [OAuth 2.0](http://tools.ietf.org/wg/oauth/draft-ietf-oaut

## 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
{
Expand All @@ -19,13 +19,18 @@ The framework is provided as a Composer package which can be installed by adding

### Framework Integrations

* [Laravel 4 service provider](https://packagist.org/packages/lucadegasperi/oauth2-server-laravel) by @lucadegasperi
* [Laravel 4 Eloquent implementation](https://github.com/ScubaClick/scubaclick-oauth2) by @ScubaClick (under development)
* [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
Expand All @@ -37,27 +42,27 @@ 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/php-loep/oauth2-server/wiki/Which-OAuth-2.0-grant-should-I-use%3F) can be found in the [wiki].

### Resource Server

The resource server allows you to secure your API endpoints by checking for a valid OAuth access token in the request and ensuring the token has the correct scope(s) (i.e. permissions) to access resources.

### 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/php-loep/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 simple tutorial on how to use the authorization server can be found at [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).

A simple 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).
[Wiki]: 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
[Developing an OAuth-2.0 Authorization Server]: https://github.com/php-loep/oauth2-server/wiki/Developing-an-OAuth-2.0-authorization-server

## Changelog

Expand Down Expand Up @@ -89,5 +94,4 @@ Special thanks to:

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.

[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/php-loep/oauth2-server/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/thephpleague/oauth2-server/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"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": "3.1.1",
"homepage": "https://github.com/php-loep/oauth2-server",
"license": "MIT",
"require": {
"php": ">=5.4.0"
Expand Down Expand Up @@ -38,8 +37,7 @@
}
],
"replace": {
"lncd/oauth2": "*",
"league/oauth2server": "*"
"lncd/oauth2": "*"
},
"autoload": {
"psr-0": {
Expand Down
15 changes: 11 additions & 4 deletions src/League/OAuth2/Server/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function isValid($headersOnly = false)

$result = $this->storages['session']->validateAccessToken($accessToken);

if ( ! $result) {
if (! $result) {
throw new Exception\InvalidAccessTokenException('Access token is not valid');
}

Expand Down Expand Up @@ -227,7 +227,7 @@ public function hasScope($scopes)
return false;
} elseif (is_array($scopes)) {
foreach ($scopes as $scope) {
if ( ! in_array($scope, $this->sessionScopes)) {
if (! in_array($scope, $this->sessionScopes)) {
return false;
}
}
Expand All @@ -246,7 +246,15 @@ public function hasScope($scopes)
*/
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.
Expand All @@ -271,5 +279,4 @@ public function determineAccessToken($headersOnly = false)

return $accessToken;
}

}
2 changes: 1 addition & 1 deletion src/League/OAuth2/Server/Storage/SessionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function removeRefreshToken($refreshToken);
* 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)
*/
Expand Down
3 changes: 0 additions & 3 deletions tests/authorization/AuthServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ public function test_issueAccessToken_passedInput()
$this->assertArrayHasKey('expires_in', $v);

$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}

public function test_issueAccessToken()
Expand Down Expand Up @@ -425,7 +424,6 @@ public function test_issueAccessToken()
$this->assertArrayHasKey('expires_in', $v);

$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}

public function test_issueAccessToken_customExpiresIn()
Expand Down Expand Up @@ -507,7 +505,6 @@ public function test_issueAccessToken_HTTP_auth()
$this->assertArrayHasKey('expires_in', $v);

$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}

public function tearDown() {
Expand Down
3 changes: 0 additions & 3 deletions tests/authorization/ClientCredentialsGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ function test_issueAccessToken_clientCredentialsGrant_passedInput()
$this->assertArrayHasKey('expires_in', $v);

$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}

function test_issueAccessToken_clientCredentialsGrant()
Expand Down Expand Up @@ -328,7 +327,6 @@ function test_issueAccessToken_clientCredentialsGrant()
$this->assertArrayHasKey('expires_in', $v);

$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}

function test_issueAccessToken_clientCredentialsGrant_customExpiresIn()
Expand Down Expand Up @@ -408,7 +406,6 @@ function test_issueAccessToken_clientCredentialsGrant_withRefreshToken()
$this->assertArrayHasKey('expires_in', $v);

$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}

}
4 changes: 0 additions & 4 deletions tests/authorization/PasswordGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ function test_issueAccessToken_passwordGrant_passedInput()
$this->assertArrayHasKey('expires_in', $v);

$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}

function test_issueAccessToken_passwordGrant()
Expand Down Expand Up @@ -516,7 +515,6 @@ function test_issueAccessToken_passwordGrant()
$this->assertArrayHasKey('expires_in', $v);

$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}

function test_issueAccessToken_passwordGrant_customExpiresIn()
Expand Down Expand Up @@ -611,7 +609,5 @@ function test_issueAccessToken_passwordGrant_withRefreshToken()
$this->assertArrayHasKey('refresh_token', $v);

$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}

}
4 changes: 0 additions & 4 deletions tests/authorization/RefreshTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public function test_issueAccessToken_with_refresh_token()
$this->assertArrayHasKey('refresh_token', $v);

$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}

/**
Expand Down Expand Up @@ -208,7 +207,6 @@ public function test_issueAccessToken_refreshTokenGrant_passedInput()
$this->assertArrayHasKey('expires_in', $v);

$this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']);
$this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
}

public function test_issueAccessToken_refreshTokenGrant()
Expand Down Expand Up @@ -247,7 +245,6 @@ public function test_issueAccessToken_refreshTokenGrant()
$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()
Expand Down Expand Up @@ -290,7 +287,6 @@ public function test_issueAccessToken_refreshTokenGrant_rotateTokens()
$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()
Expand Down

0 comments on commit 8a29226

Please sign in to comment.