Skip to content

Commit 864ca9d

Browse files
committed
refactor: Improve logout URL generation and parameter parsing
This commit refines the `create_logout_url` function to utilize a query string builder for constructing the logout URL, enhancing readability and maintainability. Additionally, the `parse_logout_params` function is updated to use `Query::into_inner`, streamlining the extraction of logout parameters from the request.
1 parent 485f3f9 commit 864ca9d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/webserver/oidc.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ use openidconnect::core::{
2323
CoreRevocationErrorResponse, CoreTokenIntrospectionResponse, CoreTokenType,
2424
};
2525
use openidconnect::{
26-
core::CoreAuthenticationFlow, url::Url, AsyncHttpClient, Audience, CsrfToken, EndSessionUrl,
27-
EndpointMaybeSet, EndpointNotSet, EndpointSet, IssuerUrl, LogoutRequest, Nonce,
28-
OAuth2TokenResponse, PostLogoutRedirectUrl, ProviderMetadataWithLogout, RedirectUrl, Scope,
29-
TokenResponse,
26+
core::CoreAuthenticationFlow,
27+
url::{form_urlencoded, Url},
28+
AsyncHttpClient, Audience, CsrfToken, EndSessionUrl, EndpointMaybeSet, EndpointNotSet,
29+
EndpointSet, IssuerUrl, LogoutRequest, Nonce, OAuth2TokenResponse, PostLogoutRedirectUrl,
30+
ProviderMetadataWithLogout, RedirectUrl, Scope, TokenResponse,
3031
};
3132
use openidconnect::{
3233
EmptyExtraTokenFields, IdTokenFields, IdTokenVerifier, StandardErrorResponse,
@@ -441,7 +442,7 @@ const LOGOUT_TOKEN_VALIDITY_SECONDS: i64 = 600;
441442
fn parse_logout_params(query: &str) -> anyhow::Result<LogoutParams> {
442443
Query::<LogoutParams>::from_query(query)
443444
.with_context(|| format!("{SQLPAGE_LOGOUT_URI}: missing required parameters"))
444-
.map(|q| q.into_inner())
445+
.map(Query::into_inner)
445446
}
446447

447448
async fn process_oidc_logout(
@@ -552,16 +553,16 @@ fn verify_logout_params(params: &LogoutParams, client_secret: &str) -> anyhow::R
552553
pub fn create_logout_url(redirect_uri: &str, site_prefix: &str, client_secret: &str) -> String {
553554
let timestamp = chrono::Utc::now().timestamp();
554555
let signature = compute_logout_signature(redirect_uri, timestamp, client_secret);
556+
let query = form_urlencoded::Serializer::new(String::new())
557+
.append_pair("redirect_uri", redirect_uri)
558+
.append_pair("timestamp", &timestamp.to_string())
559+
.append_pair("signature", &signature)
560+
.finish();
555561
format!(
556-
"{}{}?redirect_uri={}&timestamp={}&signature={}",
562+
"{}{}?{}",
557563
site_prefix.trim_end_matches('/'),
558564
SQLPAGE_LOGOUT_URI,
559-
percent_encoding::percent_encode(
560-
redirect_uri.as_bytes(),
561-
percent_encoding::NON_ALPHANUMERIC
562-
),
563-
timestamp,
564-
percent_encoding::percent_encode(signature.as_bytes(), percent_encoding::NON_ALPHANUMERIC)
565+
query
565566
)
566567
}
567568

0 commit comments

Comments
 (0)