mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-01-01 01:40:21 +05:30
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.
This commit is contained in:
commit
1d3bc85423
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -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
3
.gitignore
vendored
@ -1,6 +1,5 @@
|
||||
/vendor
|
||||
/composer.lock
|
||||
/build/logs
|
||||
/build/coverage
|
||||
/tests/coverage
|
||||
/docs
|
||||
/testing
|
@ -5,5 +5,5 @@ php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
|
||||
before_script: composer install --dev
|
||||
script: phpunit
|
||||
before_script: composer install --prefer-source
|
||||
script: phpunit --configuration phpunit.xml.dist
|
13
CHANGELOG.md
13
CHANGELOG.md
@ -1,5 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
## 3.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)
|
||||
|
69
README.md
69
README.md
@ -14,6 +14,17 @@ The framework is provided as a Composer package which can be installed by adding
|
||||
}
|
||||
```
|
||||
|
||||
#### Master branch
|
||||
|
||||
Latest stable version - [![Latest Stable Version](https://poser.pugx.org/league/oauth2-server/v/stable.png)](https://packagist.org/packages/league/oauth2-server)
|
||||
Code coverage - [![Coverage Status](https://coveralls.io/repos/php-loep/oauth2-server/badge.png?branch=master)](https://coveralls.io/r/php-loep/oauth2-server?branch=master)
|
||||
Downloads - [![Total Downloads](https://poser.pugx.org/league/oauth2-server/downloads.png)](https://packagist.org/packages/league/oauth2-server)
|
||||
|
||||
#### Develop branch
|
||||
|
||||
Latest unstable version - [![Latest Unstable Version](https://poser.pugx.org/league/oauth2-server/v/unstable.png)](https://packagist.org/packages/league/oauth2-server)
|
||||
Code coverage - [![Coverage Status](https://coveralls.io/repos/php-loep/oauth2-server/badge.png?branch=develop)](https://coveralls.io/r/php-loep/oauth2-server?branch=develop)
|
||||
|
||||
---
|
||||
|
||||
The library features 100% unit test code coverage. To run the tests yourself run `phpunit` from the project root.
|
||||
@ -47,52 +58,36 @@ If you are using MySQL and want to very quickly implement the library then all o
|
||||
|
||||
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).
|
||||
|
||||
A 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 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 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).
|
||||
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).
|
||||
|
||||
## Future Goals
|
||||
## Changelog
|
||||
|
||||
### Authorization Server
|
||||
[See the project releases page](https://github.com/php-loep/oauth2-server/releases)
|
||||
|
||||
* 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/).
|
||||
|
||||
---
|
||||
|
||||
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/).
|
||||
|
||||
|
||||
Credits
|
||||
-------
|
||||
|
||||
* [Alex Bilbie](https://github.com/alexbilbie)
|
||||
* [Dan Horrigan](https://github.com/dandoescode)
|
||||
* [Nick Jackson](https://github.com/jacksonj04)
|
||||
* [Michael Gooden](https://github.com/MichaelGooden)
|
||||
* [Phil Sturgeon] (https://github.com/philsturgeon)
|
||||
* [All contributors](https://github.com/php-loep/oauth2-server/contributors)
|
||||
|
||||
Changelog
|
||||
---------
|
||||
|
||||
[See the changelog file](https://github.com/php-loep/oauth2-server/blob/master/CHANGELOG.md)
|
||||
|
||||
Contributing
|
||||
------------
|
||||
## Contributing
|
||||
|
||||
Please see [CONTRIBUTING](https://github.com/php-loep/oauth2-server/blob/master/CONTRIBUTING.md) for details.
|
||||
|
||||
Support
|
||||
-------
|
||||
## Support
|
||||
|
||||
Bugs and feature request are tracked on [GitHub](https://github.com/php-loep/oauth2-server/issues)
|
||||
|
||||
## License
|
||||
|
||||
License
|
||||
-------
|
||||
This package is released under the MIT License. See the bundled [LICENSE](https://github.com/php-loep/oauth2-server/blob/master/LICENSE) file for details.
|
||||
|
||||
oauth2-server is released under the MIT License. See the bundled
|
||||
[LICENSE](https://github.com/php-loep/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/php-loep/oauth2-server/contributors)
|
||||
|
||||
The initial code was developed as part of the [Linkey](http://linkey.blogs.lincoln.ac.uk) project which was funded by [JISC](http://jisc.ac.uk) under the Access and Identity Management programme.
|
142
build.xml
142
build.xml
@ -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>
|
@ -1,14 +1,15 @@
|
||||
{
|
||||
"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.1",
|
||||
"version": "3.0",
|
||||
"homepage": "https://github.com/php-loep/oauth2-server",
|
||||
"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": [
|
||||
{
|
||||
@ -23,7 +24,10 @@
|
||||
"authorization",
|
||||
"authentication",
|
||||
"resource",
|
||||
"api"
|
||||
"api",
|
||||
"auth",
|
||||
"protect",
|
||||
"secure"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
@ -43,6 +47,6 @@
|
||||
}
|
||||
},
|
||||
"suggest": {
|
||||
"zetacomponents/database": "Allows use of the build in PDO storage classes"
|
||||
|
||||
}
|
||||
}
|
12
phpunit.xml
12
phpunit.xml
@ -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
53
phpunit.xml.dist
Normal 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>
|
@ -261,6 +261,11 @@ class Authorization
|
||||
return (array_key_exists($identifier, $this->grantTypes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns response types
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getResponseTypes()
|
||||
{
|
||||
return $this->responseTypes;
|
||||
@ -287,11 +292,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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -321,6 +327,7 @@ class Authorization
|
||||
public function requireStateParam($require = true)
|
||||
{
|
||||
$this->requireStateParam = $require;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -341,6 +348,7 @@ class Authorization
|
||||
public function setScopeDelimeter($scopeDelimeter = ' ')
|
||||
{
|
||||
$this->scopeDelimeter = $scopeDelimeter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -359,6 +367,7 @@ class Authorization
|
||||
public function setAccessTokenTTL($accessTokenTTL = 3600)
|
||||
{
|
||||
$this->accessTokenTTL = $accessTokenTTL;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -369,6 +378,7 @@ class Authorization
|
||||
public function setRequest(Util\RequestInterface $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -381,7 +391,6 @@ class Authorization
|
||||
if ($this->request === null) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$this->request = Request::buildFromGlobals();
|
||||
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
|
@ -24,6 +24,8 @@ use League\OAuth2\Server\Storage\ScopeInterface;
|
||||
*/
|
||||
class AuthCode implements GrantTypeInterface {
|
||||
|
||||
use GrantTrait;
|
||||
|
||||
/**
|
||||
* Grant identifier
|
||||
* @var string
|
||||
@ -64,34 +66,6 @@ class AuthCode implements GrantTypeInterface {
|
||||
$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 +250,7 @@ class AuthCode implements GrantTypeInterface {
|
||||
|
||||
$response = array(
|
||||
'access_token' => $accessToken,
|
||||
'token_type' => 'bearer',
|
||||
'token_type' => 'Bearer',
|
||||
'expires' => $accessTokenExpires,
|
||||
'expires_in' => $accessTokenExpiresIn
|
||||
);
|
||||
@ -292,4 +266,4 @@ class AuthCode implements GrantTypeInterface {
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ use League\OAuth2\Server\Storage\ScopeInterface;
|
||||
*/
|
||||
class ClientCredentials implements GrantTypeInterface {
|
||||
|
||||
use GrantTrait;
|
||||
|
||||
/**
|
||||
* Grant identifier
|
||||
* @var string
|
||||
@ -163,7 +165,7 @@ class ClientCredentials implements GrantTypeInterface {
|
||||
|
||||
$response = array(
|
||||
'access_token' => $accessToken,
|
||||
'token_type' => 'bearer',
|
||||
'token_type' => 'Bearer',
|
||||
'expires' => $accessTokenExpires,
|
||||
'expires_in' => $accessTokenExpiresIn
|
||||
);
|
||||
|
45
src/League/OAuth2/Server/Grant/GrantTrait.php
Normal file
45
src/League/OAuth2/Server/Grant/GrantTrait.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?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;
|
||||
|
||||
trait GrantTrait {
|
||||
|
||||
/**
|
||||
* 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 self
|
||||
*/
|
||||
public function setAccessTokenTTL($accessTokenTTL)
|
||||
{
|
||||
$this->accessTokenTTL = $accessTokenTTL;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
@ -28,18 +28,6 @@ interface GrantTypeInterface
|
||||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
* Complete the grant flow
|
||||
*
|
||||
|
@ -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
|
||||
@ -42,6 +44,12 @@ class Implict implements GrantTypeInterface {
|
||||
*/
|
||||
protected $authServer = null;
|
||||
|
||||
/**
|
||||
* Access token expires in override
|
||||
* @var int
|
||||
*/
|
||||
protected $accessTokenTTL = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param Authorization $authServer Authorization server instance
|
||||
@ -52,24 +60,6 @@ class Implict implements GrantTypeInterface {
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete the client credentials grant
|
||||
* @param null|array $inputParams
|
||||
@ -84,7 +74,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 +89,13 @@ class Implict implements GrantTypeInterface {
|
||||
}
|
||||
|
||||
$response = array(
|
||||
'access_token' => $accessToken
|
||||
'access_token' => $accessToken,
|
||||
'token_type' => 'Bearer',
|
||||
'expires' => $accessTokenExpires,
|
||||
'expires_in' => $accessTokenExpiresIn,
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ use League\OAuth2\Server\Storage\ScopeInterface;
|
||||
*/
|
||||
class Password implements GrantTypeInterface {
|
||||
|
||||
use GrantTrait;
|
||||
|
||||
/**
|
||||
* Grant identifier
|
||||
* @var string
|
||||
@ -64,34 +66,6 @@ class Password implements GrantTypeInterface {
|
||||
$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 +180,7 @@ class Password implements GrantTypeInterface {
|
||||
|
||||
$response = array(
|
||||
'access_token' => $accessToken,
|
||||
'token_type' => 'bearer',
|
||||
'token_type' => 'Bearer',
|
||||
'expires' => $accessTokenExpires,
|
||||
'expires_in' => $accessTokenExpiresIn
|
||||
);
|
||||
@ -222,4 +196,4 @@ class Password implements GrantTypeInterface {
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ use League\OAuth2\Server\Storage\ScopeInterface;
|
||||
*/
|
||||
class RefreshToken implements GrantTypeInterface {
|
||||
|
||||
use GrantTrait;
|
||||
|
||||
/**
|
||||
* Grant identifier
|
||||
* @var string
|
||||
@ -70,34 +72,6 @@ class RefreshToken implements GrantTypeInterface {
|
||||
$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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -242,7 +244,7 @@ class Resource
|
||||
* @throws Exception\MissingAccessTokenException Thrown if there is no access token presented
|
||||
* @return string
|
||||
*/
|
||||
protected function determineAccessToken($headersOnly = false)
|
||||
public function determineAccessToken($headersOnly = false)
|
||||
{
|
||||
if ($header = $this->getRequest()->header('Authorization')) {
|
||||
// Check for special case, because cURL sometimes does an
|
||||
|
@ -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,6 +46,7 @@ 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>
|
||||
*
|
||||
@ -54,4 +57,4 @@ interface ClientInterface
|
||||
* @return bool|array Returns false if the validation fails, array on success
|
||||
*/
|
||||
public function getClient($clientId, $clientSecret = null, $redirectUri = null, $grantType = null);
|
||||
}
|
||||
}
|
||||
|
@ -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 = null)
|
||||
{
|
||||
$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
|
||||
);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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
|
||||
);
|
||||
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
@ -315,7 +315,8 @@ interface SessionInterface
|
||||
* <code>
|
||||
* array (
|
||||
* array(
|
||||
* 'key' => (string),
|
||||
* 'id' => (int),
|
||||
* 'scope' => (string),
|
||||
* 'name' => (string),
|
||||
* 'description' => (string)
|
||||
* ),
|
||||
|
@ -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[$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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user