Skip to content

Commit

Permalink
Fix Telegram login redirect for Mini Apps
Browse files Browse the repository at this point in the history
  • Loading branch information
irshadahmad21 committed Oct 26, 2024
1 parent 35f1abc commit cf87140
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
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

0 comments on commit cf87140

Please sign in to comment.