forked from thephpleague/oauth2-server
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from vend/enable-alternative-token-generation-s…
…trategy Change our OAuth2 server to enable an alternative token generation strategy
- Loading branch information
Showing
14 changed files
with
125 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ | |
/docs | ||
/nbproject | ||
composer.phar | ||
|
||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,8 @@ | |
|
||
use League\OAuth2\Server\Authorization; | ||
|
||
trait GrantTrait { | ||
trait GrantTrait | ||
{ | ||
|
||
/** | ||
* Constructor | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace League\OAuth2\Server\Grant; | ||
|
||
use League\OAuth2\Server\Util\DefaultGenerator; | ||
use League\OAuth2\Server\Util\TokenGeneratorInterface; | ||
|
||
trait TokenGeneratorTrait | ||
{ | ||
/** | ||
* @var TokenGeneratorInterface | ||
*/ | ||
private $tokenGenerator; | ||
|
||
/** | ||
* @param TokenGeneratorInterface $generator | ||
*/ | ||
public function setTokenGenerator(TokenGeneratorInterface $generator) | ||
{ | ||
$this->tokenGenerator = $generator; | ||
} | ||
|
||
/** | ||
* @return TokenGeneratorInterface | ||
*/ | ||
public function getTokenGenerator() | ||
{ | ||
if (!$this->tokenGenerator) { | ||
return new DefaultGenerator(); | ||
} | ||
|
||
return $this->tokenGenerator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace League\OAuth2\Server\Util; | ||
|
||
interface TokenGeneratorInterface | ||
{ | ||
/** | ||
* Generate a unique access token | ||
* | ||
* @param int $len | ||
* @return string | ||
*/ | ||
public function generate($len = 40); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use League\OAuth2\Server\Util\DefaultGenerator; | ||
|
||
class DefaultGenerator_test extends PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var DefaultGenerator | ||
*/ | ||
private $generator; | ||
|
||
public function setUp() | ||
{ | ||
$this->generator = new DefaultGenerator(); | ||
} | ||
|
||
function test_generate() | ||
{ | ||
$v1 = $this->generator->generate(); | ||
$v2 = $this->generator->generate(); | ||
$v3 = $this->generator->generate(50); | ||
|
||
$this->assertEquals(40, strlen($v1)); | ||
$this->assertTrue($v1 !== $v2); | ||
$this->assertEquals(50, strlen($v3)); | ||
} | ||
} |
Oops, something went wrong.