oauth2 add trailing slash variable#1127
oauth2 add trailing slash variable#1127PVTGoesen wants to merge 4 commits intoLibreBooking:developfrom
Conversation
Add variable 'LB_AUTHENTICATION_OAUTH2_TRAILING_SLASH' to choose if to cut or keep the trailing slash in oauth2 authorize URL, this is needed for some providers.
Add variable 'LB_AUTHENTICATION_OAUTH2_TRAILING_SLASH' to choose if to cut or keep the trailing slash in oauth2 authorize URL, this is needed for some providers.
Add variable 'LB_AUTHENTICATION_OAUTH2_TRAILING_SLASH' to choose if to cut or keep the trailing slash in oauth2 authorize URL, this is needed for some providers.
|
Hi, |
There was a problem hiding this comment.
Pull request overview
Adds a configuration toggle to control whether the OAuth2 authorization URL should keep or trim a trailing slash, to support providers that require /authorize/ vs /authorize.
Changes:
- Introduces
authentication.oauth2.trailing.slashconfig key (defaultfalse). - Documents the new setting in
config.dist.phpunder authentication → generic OAuth2. - Updates
LoginPresenter::GetOauth2Url()to conditionallyrtrim()the configured authorize URL.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| lib/Config/ConfigKeys.php | Adds a new boolean config key for OAuth2 authorize URL trailing-slash handling. |
| config/config.dist.php | Adds the new OAuth2 trailing-slash setting to the distributed config template. |
| Presenters/LoginPresenter.php | Applies the new config flag when building the OAuth2 authorize URL. |
Comments suppressed due to low confidence (1)
Presenters/LoginPresenter.php:406
- This new behavior in GetOauth2Url() isn’t covered by the existing LoginPresenter tests. Please add tests for both cases (trailing-slash preservation enabled/disabled) to ensure the generated authorize URL is correct when the configured base URL ends with '/'.
public function GetOauth2Url()
{
// Retrieve Oauth2 configuration values
$trailingSlash = Configuration::Instance()->GetKey(ConfigKeys::AUTHENTICATION_OAUTH2_TRAILING_SLASH);
if (!$trailingSlash){
$baseUrl = rtrim(Configuration::Instance()->GetKey(ConfigKeys::AUTHENTICATION_OAUTH2_URL_AUTHORIZE), '/');
}
else {
$baseUrl = Configuration::Instance()->GetKey(ConfigKeys::AUTHENTICATION_OAUTH2_URL_AUTHORIZE);
}
$clientId = Configuration::Instance()->GetKey(ConfigKeys::AUTHENTICATION_OAUTH2_CLIENT_ID);
$redirectUri = $this->buildRedirectUri(Configuration::Instance()->GetKey(ConfigKeys::AUTHENTICATION_OAUTH2_REDIRECT_URI));
$params = [
'client_id' => $clientId,
'redirect_uri' => $redirectUri,
'scope' => 'openid email profile',
'response_type' => 'code'
];
$Oauth2Url = $baseUrl . '?' . http_build_query($params, '', '&', PHP_QUERY_RFC3986);
return $Oauth2Url;
You can also share your feedback on Copilot code review. Take the survey.
Presenters/LoginPresenter.php
Outdated
| if (!$trailingSlash){ | ||
| $baseUrl = rtrim(Configuration::Instance()->GetKey(ConfigKeys::AUTHENTICATION_OAUTH2_URL_AUTHORIZE), '/'); | ||
| } | ||
| else { |
There was a problem hiding this comment.
Code style is inconsistent with the rest of this file: if (!$trailingSlash){ is missing a space before {, and the else is on a new line (elsewhere it’s } else {). Please align the formatting to match the surrounding conventions.
| if (!$trailingSlash){ | |
| $baseUrl = rtrim(Configuration::Instance()->GetKey(ConfigKeys::AUTHENTICATION_OAUTH2_URL_AUTHORIZE), '/'); | |
| } | |
| else { | |
| if (!$trailingSlash) { | |
| $baseUrl = rtrim(Configuration::Instance()->GetKey(ConfigKeys::AUTHENTICATION_OAUTH2_URL_AUTHORIZE), '/'); | |
| } else { |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Hi, |
You can do that or you can do an "interactive rebase" and squash it down to one commit. https://docs.github.com/en/get-started/using-git/using-git-rebase-on-the-command-line |
|
I will open a new pull request |
Some OAuth2 provider need a trailing slash in the authorization URL. This changes let you choose if you want to cut or keep the trailing slash in oauth2 authorize URL.