Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid empty string for scope when inserting/updating #563

Merged
merged 3 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function login(int $providerId, string $redirectUrl = null) {
$data = [
'client_id' => $provider->getClientId(),
'response_type' => 'code',
'scope' => $provider->getScope(),
julien-nc marked this conversation as resolved.
Show resolved Hide resolved
'scope' => trim($provider->getScope()),
'redirect_uri' => $this->urlGenerator->linkToRouteAbsolute(Application::APP_ID . '.login.code'),
'claims' => json_encode($claims),
'state' => $state,
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(
}

public function createProvider(string $identifier, string $clientId, string $clientSecret, string $discoveryEndpoint,
array $settings = [], string $scope = "openid email profile"): JSONResponse {
array $settings = [], string $scope = 'openid email profile'): JSONResponse {
if ($this->providerService->getProviderByIdentifier($identifier) !== null) {
return new JSONResponse(['message' => 'Provider with the given identifier already exists'], Http::STATUS_CONFLICT);
}
Expand All @@ -78,7 +78,7 @@ public function createProvider(string $identifier, string $clientId, string $cli
}

public function updateProvider(int $providerId, string $identifier, string $clientId, string $discoveryEndpoint, string $clientSecret = null,
array $settings = [], string $scope = "openid email profile"): JSONResponse {
array $settings = [], string $scope = 'openid email profile'): JSONResponse {
$provider = $this->providerMapper->getProvider($providerId);

if ($this->providerService->getProviderByIdentifier($identifier) === null) {
Expand Down
10 changes: 8 additions & 2 deletions lib/Db/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
* @method void setClientSecret(string $clientSecret)
* @method string getDiscoveryEndpoint()
* @method void setDiscoveryEndpoint(string $discoveryEndpoint)
* @method string getScope()
* @method void setScope(string $scope)
*/
class Provider extends Entity implements \JsonSerializable {
Expand All @@ -56,14 +55,21 @@ class Provider extends Entity implements \JsonSerializable {
/** @var string */
protected $scope;

/**
* @return string
*/
public function getScope(): string {
return $this->scope ?: ' ';
}

#[\ReturnTypeWillChange]
public function jsonSerialize() {
return [
'id' => $this->id,
'identifier' => $this->identifier,
'clientId' => $this->clientId,
'discoveryEndpoint' => $this->discoveryEndpoint,
'scope' => $this->scope,
'scope' => trim($this->getScope()),
];
}
}