Skip to content

Commit

Permalink
Merge pull request #546 from johnnoel/randomstatefix
Browse files Browse the repository at this point in the history
Change AbstractProvider getRandomState to only return alphanumeric states
  • Loading branch information
shadowhand authored Jul 28, 2016
2 parents 46052b5 + c916abb commit 01f955b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use RandomLib\Factory as RandomFactory;
use RandomLib\Generator as RandomGenerator;
use UnexpectedValueException;

/**
Expand Down Expand Up @@ -302,7 +303,7 @@ protected function getRandomState($length = 32)
->getRandomFactory()
->getMediumStrengthGenerator();

return $generator->generateString($length);
return $generator->generateString($length, RandomGenerator::CHAR_ALNUM);
}

/**
Expand Down Expand Up @@ -358,7 +359,7 @@ protected function getAuthorizationParameters(array $options)
$options['client_id'] = $this->clientId;
$options['redirect_uri'] = $this->redirectUri;
$options['state'] = $this->state;

return $options;
}

Expand Down
6 changes: 3 additions & 3 deletions test/src/Provider/AbstractProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testAuthorizationUrlStateParam()
'state' => 'XXX'
]));
}

/**
* Tests https://github.com/thephpleague/oauth2-client/pull/485
*/
Expand All @@ -75,7 +75,7 @@ public function testCustomAuthorizationUrlOptions()
]);
$query = parse_url($url, PHP_URL_QUERY);
$this->assertNotEmpty($query);

parse_str($query, $params);
$this->assertArrayHasKey('foo', $params);
$this->assertSame('BAR', $params['foo']);
Expand Down Expand Up @@ -307,7 +307,7 @@ public function testRandomGeneratorCreatesRandomState()
$xstate = str_repeat('x', 32);

$generator = m::mock(RandomGenerator::class);
$generator->shouldReceive('generateString')->with(32)->times(1)->andReturn($xstate);
$generator->shouldReceive('generateString')->with(32, 7)->times(1)->andReturn($xstate);

$factory = m::mock(RandomFactory::class);
$factory->shouldReceive('getMediumStrengthGenerator')->times(1)->andReturn($generator);
Expand Down

0 comments on commit 01f955b

Please sign in to comment.