Skip to content

Commit 70283ec

Browse files
authored
Merge pull request #4 from pdsinterop/feature/client-redirect-uris
Change Client config to support Redirect URIs and Name
2 parents e5ee559 + 3db8245 commit 70283ec

File tree

4 files changed

+47
-36
lines changed

4 files changed

+47
-36
lines changed

src/Config/Client.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ class Client
66
{
77
////////////////////////////// CLASS PROPERTIES \\\\\\\\\\\\\\\\\\\\\\\\\\\\
88

9-
/** @var string */
10-
private $authorizationPageUrl;
119
/** @var string */
1210
private $identifier;
1311
/** @var string */
14-
private $loginUrl;
12+
private $name;
13+
/** @var array */
14+
private $redirectUris;
1515
/** @var string */
1616
private $secret;
1717

@@ -22,28 +22,32 @@ final public function getIdentifier() : string
2222
return $this->identifier;
2323
}
2424

25-
final public function getSecret() : string
25+
final public function getName() : string
2626
{
27-
return $this->secret;
27+
return $this->name;
2828
}
2929

30-
final public function getAuthorizationPageUrl() : string
30+
final public function getRedirectUris() : array
3131
{
32-
return $this->authorizationPageUrl;
32+
return $this->redirectUris;
3333
}
3434

35-
final public function getLoginUrl() : string
35+
final public function getSecret() : string
3636
{
37-
return $this->loginUrl;
37+
return $this->secret;
3838
}
3939

4040
//////////////////////////////// PUBLIC API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
4141

42-
final public function __construct(string $identifier, string $secret, string $authorizationPageUrl = '', string $loginUrl = '')
43-
{
44-
$this->authorizationPageUrl = $authorizationPageUrl;
42+
final public function __construct(
43+
string $identifier,
44+
string $secret,
45+
array $redirectUris,
46+
string $name = ''
47+
) {
4548
$this->identifier = $identifier;
46-
$this->loginUrl = $loginUrl;
49+
$this->name = $name;
50+
$this->redirectUris = $redirectUris;
4751
$this->secret = $secret;
4852
}
4953
}

src/Factory/AuthorizationServerFactory.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@ final public function create() : AuthorizationServer
2525
{
2626
$config = $this->config;
2727

28-
$clientIdentifier = $config->getClient()->getIdentifier();
29-
$clientSecret = $config->getClient()->getSecret();
28+
$client = $config->getClient();
3029
$expiration = $config->getExpiration();
3130
$grantTypes = $config->getGrantTypes();
3231
$keys = $config->getKeys();
3332

3433
$repositoryFactory = new RepositoryFactory([
35-
Repository::CLIENT => new Client($clientIdentifier, $clientSecret, '',$grantTypes, []),
34+
Repository::CLIENT => new Client(
35+
$client->getIdentifier(),
36+
$client->getSecret(),
37+
$client->getName(),
38+
$grantTypes,
39+
$client->getRedirectUris()
40+
),
3641
]);
3742

3843
$server = new AuthorizationServer(

src/Factory/ConfigFactory.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010

1111
class ConfigFactory
1212
{
13-
/** @var string */
14-
private $clientIdentifier;
15-
/** @var string */
16-
private $clientSecret;
13+
/** @var Config\Client */
14+
private $client;
1715
/** @var string */
1816
private $encryptionKey;
1917
/** @var string */
@@ -24,15 +22,13 @@ class ConfigFactory
2422
private $serverConfig;
2523

2624
final public function __construct(
27-
string $clientIdentifier,
28-
string $clientSecret,
25+
Config\Client $client,
2926
string $encryptionKey,
3027
string $privateKey,
3128
string $publicKey,
3229
array $serverConfig
3330
) {
34-
$this->clientIdentifier = $clientIdentifier;
35-
$this->clientSecret = $clientSecret;
31+
$this->client = $client;
3632
$this->encryptionKey = $encryptionKey;
3733
$this->privateKey = $privateKey;
3834
$this->serverConfig = $serverConfig;
@@ -41,14 +37,11 @@ final public function __construct(
4137

4238
final public function create() : Config
4339
{
44-
$clientIdentifier = $this->clientIdentifier;
45-
$clientSecret = $this->clientSecret;
40+
$client = $this->client;
4641
$encryptionKey = $this->encryptionKey;
4742
$privateKey = $this->privateKey;
4843
$publicKey = $this->publicKey;
4944

50-
$client = new Config\Client($clientIdentifier, $clientSecret);
51-
5245
$expiration = new Config\Expiration(Time::HOURS_1, Time::MINUTES_10, Time::MONTHS_1);
5346

5447
$grantTypes = [

tests/example.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@
2121
? $request->getQueryParams()[\Pdsinterop\Solid\Auth\Enum\OAuth2\Parameter::CLIENT_ID]
2222
: '';
2323

24-
/*/ These should come from a database, based on $clientIdentifier /*/
24+
/*/ These should come from a database, based on $clientIdentifier
25+
*
26+
* They have previously been provided to or by the Client, using a Dynamic
27+
* Registration request.
28+
/*/
29+
$clientName = 'Example Client Name';
30+
$clientRedirectUris = [
31+
'https://server/client/redirect-url',
32+
'https://server/client/another-redirect-url',
33+
];
2534
$clientSecret = 'client secret';
26-
$clientName = '';
27-
$clientRedirectUri = ['https://server/client/redirect-url'];
2835
// =============================================================================
2936

3037

@@ -37,11 +44,13 @@
3744
$publicKey = file_get_contents($keyPath . '/public.key');
3845

3946
$config = (new \Pdsinterop\Solid\Auth\Factory\ConfigFactory(
40-
$clientIdentifier,
41-
$clientSecret,
42-
$encryptionKey,
43-
$privateKey,
44-
$publicKey,
47+
new \Pdsinterop\Solid\Auth\Config\Client(
48+
$clientIdentifier,
49+
$clientSecret,
50+
$clientRedirectUris,
51+
$clientName
52+
),
53+
$encryptionKey,$privateKey, $publicKey,
4554
[
4655
/* URL of the OP's OAuth 2.0 Authorization Endpoint [OpenID.Core]. */
4756
\Pdsinterop\Solid\Auth\Enum\OpenId\OpenIdConnectMetadata::AUTHORIZATION_ENDPOINT => 'https://server/authorize',

0 commit comments

Comments
 (0)