Skip to content

Commit

Permalink
Merge pull request #4 from pdsinterop/feature/client-redirect-uris
Browse files Browse the repository at this point in the history
Change Client config to support Redirect URIs and Name
  • Loading branch information
Potherca authored Sep 21, 2020
2 parents e5ee559 + 3db8245 commit 70283ec
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 36 deletions.
30 changes: 17 additions & 13 deletions src/Config/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ class Client
{
////////////////////////////// CLASS PROPERTIES \\\\\\\\\\\\\\\\\\\\\\\\\\\\

/** @var string */
private $authorizationPageUrl;
/** @var string */
private $identifier;
/** @var string */
private $loginUrl;
private $name;
/** @var array */
private $redirectUris;
/** @var string */
private $secret;

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

final public function getSecret() : string
final public function getName() : string
{
return $this->secret;
return $this->name;
}

final public function getAuthorizationPageUrl() : string
final public function getRedirectUris() : array
{
return $this->authorizationPageUrl;
return $this->redirectUris;
}

final public function getLoginUrl() : string
final public function getSecret() : string
{
return $this->loginUrl;
return $this->secret;
}

//////////////////////////////// PUBLIC API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

final public function __construct(string $identifier, string $secret, string $authorizationPageUrl = '', string $loginUrl = '')
{
$this->authorizationPageUrl = $authorizationPageUrl;
final public function __construct(
string $identifier,
string $secret,
array $redirectUris,
string $name = ''
) {
$this->identifier = $identifier;
$this->loginUrl = $loginUrl;
$this->name = $name;
$this->redirectUris = $redirectUris;
$this->secret = $secret;
}
}
11 changes: 8 additions & 3 deletions src/Factory/AuthorizationServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ final public function create() : AuthorizationServer
{
$config = $this->config;

$clientIdentifier = $config->getClient()->getIdentifier();
$clientSecret = $config->getClient()->getSecret();
$client = $config->getClient();
$expiration = $config->getExpiration();
$grantTypes = $config->getGrantTypes();
$keys = $config->getKeys();

$repositoryFactory = new RepositoryFactory([
Repository::CLIENT => new Client($clientIdentifier, $clientSecret, '',$grantTypes, []),
Repository::CLIENT => new Client(
$client->getIdentifier(),
$client->getSecret(),
$client->getName(),
$grantTypes,
$client->getRedirectUris()
),
]);

$server = new AuthorizationServer(
Expand Down
17 changes: 5 additions & 12 deletions src/Factory/ConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

class ConfigFactory
{
/** @var string */
private $clientIdentifier;
/** @var string */
private $clientSecret;
/** @var Config\Client */
private $client;
/** @var string */
private $encryptionKey;
/** @var string */
Expand All @@ -24,15 +22,13 @@ class ConfigFactory
private $serverConfig;

final public function __construct(
string $clientIdentifier,
string $clientSecret,
Config\Client $client,
string $encryptionKey,
string $privateKey,
string $publicKey,
array $serverConfig
) {
$this->clientIdentifier = $clientIdentifier;
$this->clientSecret = $clientSecret;
$this->client = $client;
$this->encryptionKey = $encryptionKey;
$this->privateKey = $privateKey;
$this->serverConfig = $serverConfig;
Expand All @@ -41,14 +37,11 @@ final public function __construct(

final public function create() : Config
{
$clientIdentifier = $this->clientIdentifier;
$clientSecret = $this->clientSecret;
$client = $this->client;
$encryptionKey = $this->encryptionKey;
$privateKey = $this->privateKey;
$publicKey = $this->publicKey;

$client = new Config\Client($clientIdentifier, $clientSecret);

$expiration = new Config\Expiration(Time::HOURS_1, Time::MINUTES_10, Time::MONTHS_1);

$grantTypes = [
Expand Down
25 changes: 17 additions & 8 deletions tests/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@
? $request->getQueryParams()[\Pdsinterop\Solid\Auth\Enum\OAuth2\Parameter::CLIENT_ID]
: '';

/*/ These should come from a database, based on $clientIdentifier /*/
/*/ These should come from a database, based on $clientIdentifier
*
* They have previously been provided to or by the Client, using a Dynamic
* Registration request.
/*/
$clientName = 'Example Client Name';
$clientRedirectUris = [
'https://server/client/redirect-url',
'https://server/client/another-redirect-url',
];
$clientSecret = 'client secret';
$clientName = '';
$clientRedirectUri = ['https://server/client/redirect-url'];
// =============================================================================


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

$config = (new \Pdsinterop\Solid\Auth\Factory\ConfigFactory(
$clientIdentifier,
$clientSecret,
$encryptionKey,
$privateKey,
$publicKey,
new \Pdsinterop\Solid\Auth\Config\Client(
$clientIdentifier,
$clientSecret,
$clientRedirectUris,
$clientName
),
$encryptionKey,$privateKey, $publicKey,
[
/* URL of the OP's OAuth 2.0 Authorization Endpoint [OpenID.Core]. */
\Pdsinterop\Solid\Auth\Enum\OpenId\OpenIdConnectMetadata::AUTHORIZATION_ENDPOINT => 'https://server/authorize',
Expand Down

0 comments on commit 70283ec

Please sign in to comment.