Skip to content

Commit 01f955b

Browse files
authored
Merge pull request #546 from johnnoel/randomstatefix
Change AbstractProvider getRandomState to only return alphanumeric states
2 parents 46052b5 + c916abb commit 01f955b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/Provider/AbstractProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Psr\Http\Message\RequestInterface;
2828
use Psr\Http\Message\ResponseInterface;
2929
use RandomLib\Factory as RandomFactory;
30+
use RandomLib\Generator as RandomGenerator;
3031
use UnexpectedValueException;
3132

3233
/**
@@ -302,7 +303,7 @@ protected function getRandomState($length = 32)
302303
->getRandomFactory()
303304
->getMediumStrengthGenerator();
304305

305-
return $generator->generateString($length);
306+
return $generator->generateString($length, RandomGenerator::CHAR_ALNUM);
306307
}
307308

308309
/**
@@ -358,7 +359,7 @@ protected function getAuthorizationParameters(array $options)
358359
$options['client_id'] = $this->clientId;
359360
$options['redirect_uri'] = $this->redirectUri;
360361
$options['state'] = $this->state;
361-
362+
362363
return $options;
363364
}
364365

test/src/Provider/AbstractProviderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testAuthorizationUrlStateParam()
6464
'state' => 'XXX'
6565
]));
6666
}
67-
67+
6868
/**
6969
* Tests https://github.com/thephpleague/oauth2-client/pull/485
7070
*/
@@ -75,7 +75,7 @@ public function testCustomAuthorizationUrlOptions()
7575
]);
7676
$query = parse_url($url, PHP_URL_QUERY);
7777
$this->assertNotEmpty($query);
78-
78+
7979
parse_str($query, $params);
8080
$this->assertArrayHasKey('foo', $params);
8181
$this->assertSame('BAR', $params['foo']);
@@ -307,7 +307,7 @@ public function testRandomGeneratorCreatesRandomState()
307307
$xstate = str_repeat('x', 32);
308308

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

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

0 commit comments

Comments
 (0)