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

Add license key to auth button #85

Merged
merged 17 commits into from
Sep 13, 2024
Merged

Conversation

tarecord
Copy link
Contributor

When a site needs to connect to the licensing server to generate a token or connect securely with an external service, a license key should be passed with the request. This attaches the license key to the auth button and adjusts a little of the functionality to make the UX more fluid for the user.

This also fixes some styling of the button so that it displays to the right of the license field that is used for authentication.

No License Key Present

CleanShot 2024-09-13 at 09 45 14@2x

License Key Invalid

CleanShot 2024-09-13 at 09 46 04@2x

License Key Valid

CleanShot 2024-09-13 at 09 46 44@2x

Site Connected

CleanShot 2024-09-13 at 09 47 48@2x

@tarecord tarecord requested review from lucatume and removed request for lucatume September 13, 2024 13:48
@tarecord tarecord marked this pull request as ready for review September 13, 2024 14:26
src/Uplink/Admin/Ajax.php Outdated Show resolved Hide resolved
src/Uplink/functions.php Outdated Show resolved Hide resolved
@@ -266,7 +266,7 @@ public function it_should_render_correct_html_for_oauth_resource_with_license_ke
update_option( 'test_storage', [
'stellarwp_auth_url_service_oauth_with_license_key_field_1' => [
'expiration' => 0,
'value' => 'https://licensing.stellarwp.com/account-auth?uplink_domain=&uplink_slug=service-oauth-with-license-key-field-1&_uplink_nonce=535281edcd',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why this is being removed? Was the test passing before? Did something change to actually not require those query args? Were they useless before and this is cleanup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, they were unnecessary when the test was first added. Those values are combined and encoded for the uplink_callback parameter here in Auth_Url_Builder::build():

// Query arguments to combine with $_GET and add to the authorization URL.
$args = [
'uplink_domain' => $domain,
'uplink_slug' => $slug,
];
// Optionally include a license key if set.
if ( ! empty( $this->license_key ) ) {
$args['uplink_license'] = $this->license_key;
}
$url = add_query_arg(
array_filter( array_merge( $_GET, $args ) ),
admin_url( $pagenow )
);
return sprintf( '%s?%s',
$auth_url,
http_build_query( [
'uplink_callback' => base64_encode( $this->nonce->create_url( $url ) ),
] )
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to update this because of the new data attribute, so I made some changes there too.

Copy link
Member

@borkweb borkweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks fantastic! 👯

@tarecord tarecord merged commit 3c1fa91 into main Sep 13, 2024
13 checks passed
@tarecord tarecord deleted the feature/add-license-key-to-oauth branch September 13, 2024 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants