Skip to content

Commit

Permalink
Merge branch 'release/4.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbilbie committed Nov 8, 2014
2 parents b50f7ce + ad86f71 commit 73917a0
Show file tree
Hide file tree
Showing 136 changed files with 8,479 additions and 5,732 deletions.
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/vendor
/composer.lock
/tests/coverage
/build
/docs
/testing
build/coverage
/examples/relational/vendor
/examples/relational/config/oauth2.sqlite3
/examples/nosql/vendor
/examples/nosql/config/oauth2.sqlite3
/examples/relational/composer.lock
/tests/codecept/tests/_log
oauth2-server.paw
/output_*/
/_site
37 changes: 37 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
filter:
excluded_paths:
- tests/*
- vendor/*
- examples/*
checks:
php:
code_rating: true
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true
tools:
external_code_coverage:
timeout: 600
runs: 3
php_code_coverage: false
php_code_sniffer:
config:
standard: PSR2
filter:
paths: ['src']
php_loc:
enabled: true
excluded_dirs: [vendor, tests, examples]
php_cpd:
enabled: true
excluded_dirs: [vendor, tests, examples]
19 changes: 10 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ php:
- 5.5
- 5.6
- hhvm

matrix:
allow_failures:
- php: hhvm

before_script: composer install --prefer-source
script: phpunit --configuration phpunit.xml.dist
before_script:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --prefer-source --dev

cache:
directories:
- vendor
script:
- mkdir -p build/logs
- phpunit --coverage-text --verbose --coverage-clover=coverage.clover

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Changelog

## 3.2.2 (released 2014-07-23)
## 4.0.0 (released 2014-11-08)

* Fix Resource server Request HTTP header access (Issue #188)
* Complete rewrite
* Check out the documentation - [http://oauth2.thephpleague.com](http://oauth2.thephpleague.com)

## 3.2 (released 2014-04-16)
## 3.2.0 (released 2014-04-16)

* Added the ability to change the algorithm that is used to generate the token strings (Issue #151)

Expand Down
65 changes: 27 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,45 @@
# PHP OAuth 2.0 Server
# PHP OAuth 2.0 Server by [@alexbilbie](https://twitter.com/alexbilbie)

[![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")
[![Latest Version](http://img.shields.io/packagist/v/league/oauth2-server.svg?style=flat-square)](https://github.com/thephpleague/oauth2-server/releases)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Build Status](https://img.shields.io/travis/thephpleague/oauth2-server/master.svg?style=flat-square)](https://travis-ci.org/thephpleague/oauth2-server)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/thephpleague/oauth2-server.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/oauth2-server/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/thephpleague/oauth2-server.svg?style=flat-square)](https://scrutinizer-ci.com/g/thephpleague/oauth2-server)
[![Total Downloads](https://img.shields.io/packagist/dt/league/oauth2-server.svg?style=flat-square)](https://packagist.org/packages/league/oauth2-server)


A standards compliant [OAuth 2.0](http://tools.ietf.org/wg/oauth/draft-ietf-oauth-v2/) authorization server and resource server written in PHP.
A standards compliant [OAuth 2.0](http://tools.ietf.org/wg/oauth/draft-ietf-oauth-v2/) authorization server and resource server written in PHP which makes working with OAuth 2.0 trivial. You can easily configure an OAuth 2.0 server to protect your API with access tokens, or allow clients to request new access tokens and refresh them.

## Package Installation
It supports out of the box the following grants:

The framework is provided as a Composer package which can be installed by adding the package to your `composer.json` file:
* Authorization code grant
* Client credentials grant
* Resource owner password credentials grant
* Refresh grant

```javascript
{
"require": {
"league/oauth2-server": "3.*"
}
}
```
You can also define your own grants.

### Framework Integrations
In addition it supports the following token types:

* [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)
* Bearer tokens
* MAC tokens (coming soon)
* JSON web tokens (coming soon)

---

The library features 100% unit test code coverage. To run the tests yourself run `phpunit` from the project root.
## Requirements

[![Build Status](https://travis-ci.org/thephpleague/oauth2-server.png?branch=master)](https://travis-ci.org/thephpleague/oauth2-server) [master]
The following versions of PHP are supported:

[![Build Status](https://travis-ci.org/thephpleague/oauth2-server.png?branch=develop)](https://travis-ci.org/thephpleague/oauth2-server) [develop]
* PHP 5.4
* PHP 5.5
* PHP 5.6
* HHVM

## Documentation

## Current Features
This library has [full documentation](http://oauth2.thephpleague.com), powered by [Jekyll](http://jekyllrb.com/).

### Authorization Server

The authorization server is a flexible class and the following core specification grants are implemented:

* authorization code ([section 4.1](http://tools.ietf.org/html/rfc6749#section-4.1))
* refresh token ([section 6](http://tools.ietf.org/html/rfc6749#section-6))
* client credentials ([section 2.3.1](http://tools.ietf.org/html/rfc6749#section-2.3.1))
* password (user credentials) ([section 4.3](http://tools.ietf.org/html/rfc6749#section-4.3))

### 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.
Contribute to this documentation in the [gh-pages branch](https://github.com/thephpleague/oauth2-server/tree/gh-pages/).

## Changelog

Expand Down Expand Up @@ -79,5 +70,3 @@ Special thanks to:
* [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.

[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/thephpleague/oauth2-server/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
31 changes: 22 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"name": "league/oauth2-server",
"description": "A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.",
"homepage": "http://oauth2.thephpleague.com/",
"license": "MIT",
"require": {
"php": ">=5.4.0"
"php": ">=5.4.0",
"symfony/http-foundation": "~2.5",
"league/event": "1.0.*"
},
"require-dev": {
"mockery/mockery": "~0.8",
"league/phpunit-coverage-listener": "~1.0"
"phpunit/phpunit": "4.3.*",
"mockery/mockery": "0.9.*"
},
"repositories": [
{
Expand All @@ -18,8 +21,12 @@
"keywords": [
"oauth",
"oauth2",
"oauth 2",
"oauth 2.0",
"server",
"auth",
"authorization",
"authorisation",
"authentication",
"resource",
"api",
Expand All @@ -36,16 +43,22 @@
}
],
"replace": {
"lncd/oauth2": "*"
"lncd/oauth2": "*",
"league/oauth2server": "*"
},
"autoload": {
"psr-0": {
"League\\OAuth2\\Server": "src/"
"psr-4": {
"League\\OAuth2\\Server\\": "src/"
}
},
"extra": {
"branch-alias": {
"dev-master": "3.2.x-dev"
"autoload-dev": {
"psr-4": {
"LeagueTests\\": "tests/unit/"
}
},
"extra": {
"branch-alias": {
"dev-develop": "4.0.x-dev"
}
}
}
25 changes: 25 additions & 0 deletions examples/relational/Model/Users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace RelationalExample\Model;

use Illuminate\Database\Capsule\Manager as Capsule;

class Users
{
public function get($username = null)
{
$query = Capsule::table('users')->select(['username', 'password', 'name', 'email', 'photo']);

if ($username !== null) {
$query->where('username', '=', $username);
}

$result = $query->get();

if (count($result) > 0) {
return $result;
}

return null;
}
}
96 changes: 96 additions & 0 deletions examples/relational/Storage/AccessTokenStorage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace RelationalExample\Storage;

use League\OAuth2\Server\Storage\AccessTokenInterface;
use League\OAuth2\Server\Storage\Adapter;
use League\OAuth2\Server\Entity\AccessTokenEntity;
use League\OAuth2\Server\Entity\AbstractTokenEntity;
use League\OAuth2\Server\Entity\RefreshTokenEntity;
use League\OAuth2\Server\Entity\ScopeEntity;

use Illuminate\Database\Capsule\Manager as Capsule;

class AccessTokenStorage extends Adapter implements AccessTokenInterface
{
/**
* {@inheritdoc}
*/
public function get($token)
{
$result = Capsule::table('oauth_access_tokens')
->where('access_token', $token)
->get();

if (count($result) === 1) {
$token = (new AccessTokenEntity($this->server))
->setId($result[0]['access_token'])
->setExpireTime($result[0]['expire_time']);

return $token;
}

return null;
}

/**
* {@inheritdoc}
*/
public function getScopes(AbstractTokenEntity $token)
{
$result = Capsule::table('oauth_access_token_scopes')
->select(['oauth_scopes.id', 'oauth_scopes.description'])
->join('oauth_scopes', 'oauth_access_token_scopes.scope', '=', 'oauth_scopes.id')
->where('access_token', $token->getId())
->get();

$response = [];

if (count($result) > 0) {
foreach ($result as $row) {
$scope = (new ScopeEntity($this->server))->hydrate([
'id' => $row['id'],
'description' => $row['description']
]);
$response[] = $scope;
}
}

return $response;
}

/**
* {@inheritdoc}
*/
public function create($token, $expireTime, $sessionId)
{
Capsule::table('oauth_access_tokens')
->insert([
'access_token' => $token,
'session_id' => $sessionId,
'expire_time' => $expireTime
]);
}

/**
* {@inheritdoc}
*/
public function associateScope(AbstractTokenEntity $token, ScopeEntity $scope)
{
Capsule::table('oauth_access_token_scopes')
->insert([
'access_token' => $token->getId(),
'scope' => $scope->getId()
]);
}

/**
* {@inheritdoc}
*/
public function delete(AbstractTokenEntity $token)
{
Capsule::table('oauth_access_token_scopes')
->where('access_token', $token->getId())
->delete();
}
}
Loading

0 comments on commit 73917a0

Please sign in to comment.