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

Fix Telegram login redirect for Mini Apps #195

Merged
merged 1 commit into from
Oct 26, 2024
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
5 changes: 5 additions & 0 deletions .changeset/sour-papayas-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wptelegram-login": patch
---

Fixed Telegram login redirect for Mini Apps
24 changes: 12 additions & 12 deletions plugins/wptelegram-login/src/includes/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function get_inline_script_data( string $for ) {

$query_params = $this->get_webapp_login_params();

$redirect_to = esc_url( $query_params['redirect_to'] );
$redirect_to = rawurlencode( $query_params['redirect_to'] );
$confirm_login = (bool) $query_params['confirm_login'];
$is_user_logged_in = is_user_logged_in();
$login_auth_url = add_query_arg(
Expand Down Expand Up @@ -439,6 +439,12 @@ public function login_enqueue_scripts() {
*/
private function get_webapp_login_params() {

$defaults = [
'action' => '',
'confirm_login' => '1',
'redirect_to' => '',
];

// Using $_SERVER['QUERY_STRING'] to avoid a bug in Telegram Mini Apps which pass HTML/URL encoded query string ¯\_(ツ)_/¯.

$query_string = ! empty( $_SERVER['QUERY_STRING'] )
Expand All @@ -447,19 +453,13 @@ private function get_webapp_login_params() {
: '';

$query_string = html_entity_decode(
sanitize_text_field(
str_replace( [ '&amp%3B', '&' ], '&', $query_string )
)
str_replace( [ '&amp%3B', '&' ], '&', $query_string )
);

return wp_parse_args(
$query_string,
[
'action' => '',
'confirm_login' => '1',
'redirect_to' => '',
]
);
$args = wp_parse_args( $query_string, $defaults );

// Sanitize each value.
return array_map( 'sanitize_text_field', $args );
}

/**
Expand Down
Loading