Skip to content
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog for TrustedLogin Client

## 1.10 (March 10, 2025)

- Added postMessage response to the opener when access is granted or revoked
- Added hidden input to store the expiration date of the support user
- Added expiration to the message sent to the opener when access is granted

## 1.9.0 (August 25, 2024)

- Added a minimum `vendor/namespace` length of five characters to help prevent collisions with other instances
Expand Down
1 change: 1 addition & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ public function grant_access( $include_debug_data = false, $ticket_data = null )

$return_data = array(
'type' => 'new',
'key' => $this->site_access->get_access_key(),
'site_url' => get_site_url(),
'endpoint' => $endpoint_hash,
'identifier' => $site_identifier_hash,
Expand Down
5 changes: 4 additions & 1 deletion src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,7 @@

<div class="tl-%1\$s-auth__accesskey_wrapper">
<input id="tl-%1\$s-access-key" type="text" value="%4\$s" size="64" class="tl-%1\$s-auth__accesskey_field code" aria-label="%3\$s">
<input id="tl-%1\$s-access-expiration" type="hidden" value="%9\$s">
<button id="tl-%1\$s-copy" class="tl-%1\$s-auth__accesskey_copy button" aria-live="off" title="%7\$s"><span class="screen-reader-text">%5\$s</span></button>
</div>
</%6\$s>
Expand All @@ -1494,7 +1495,9 @@
esc_html__( 'Copy the access key to your clipboard', 'trustedlogin' ),
// %8$s
// translators: %s is the display name of the TrustedLogin support user.
sprintf( esc_html__( 'The access key is not a password; only %1$s will be able to access your site using this code. You may share this access key on support forums.', 'trustedlogin' ), esc_html( $this->support_user->get_first()->display_name ) )
sprintf( esc_html__( 'The access key is not a password; only %1$s will be able to access your site using this code. You may share this access key on support forums.', 'gk-gravitycalendar' ), esc_html( $this->support_user->get_first()->display_name ) ),

Check failure on line 1498 in src/Form.php

View workflow job for this annotation

GitHub Actions / PHP Code Sniffer

Mismatched text domain. Expected 'trustedlogin' or 'default' but got 'gk-gravitycalendar'.
/* %9$s */
esc_attr( $this->support_user->get_expiration( $this->support_user->get_first() ) )
);
}

Expand Down
45 changes: 42 additions & 3 deletions src/assets/trustedlogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,35 @@

'use strict';

var $body = $( 'body' ), namespace = tl_obj.vendor.namespace,
$tl_container = $( '.tl-' + namespace + '-auth' ), copy_button_timer = null,
second_status = null;
var $body = $( 'body' ),
namespace = tl_obj.vendor.namespace,
$tl_container = $( '.tl-' + namespace + '-auth' ),
copy_button_timer = null,
second_status = null,
key = $( '#tl-' + namespace + '-access-key', $tl_container ).val(),
expiration = $( '#tl-' + namespace + '-access-expiration', $tl_container ).val(),
urlParams = new URLSearchParams( window.location.search );

if ( window.opener && key && ! urlParams.has( 'revoking' ) ) {
window.opener.postMessage( {
key: key,
expiration: expiration,
type: 'granted'
}, '*' );
}

function hideWindow() {
window.resizeTo( 1, 1 );
window.moveTo( screen.width + 500, screen.height + 500 );
window.opener.focus();
}

$body.on( 'click', '.tl-client-revoke-button', function ( e ) {
if ( window.opener ) {
window.opener.postMessage( { type: 'revoking' }, '*' );
hideWindow();
}
} );

$body.on( 'click', tl_obj.selector, function ( e ) {

Expand All @@ -27,6 +53,10 @@
} );

function grantAccess( $button ) {
if ( window.opener ) {
window.opener.postMessage( { type: 'granting' }, '*' );
hideWindow();
}

$button.addClass( 'disabled' );

Expand Down Expand Up @@ -104,6 +134,15 @@
success: remote_success,
error: remote_error
} ).always( function ( response ) {
if ( window.opener ) {
var key = response && response.data && response.data.key ? response.data.key : '';
var expiry = response && response.data && response.data.expiry ? response.data.expiry : '';
window.opener.postMessage( {
key: key,
expiration: expiry,
type: 'granted'
}, '*' );
}

if ( !tl_obj.debug ) {
return;
Expand Down
Loading