@automattic/mcp-wordpress-remote 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/proxy.js +56 -4
  2. package/package.json +1 -1
package/dist/proxy.js CHANGED
@@ -721,9 +721,11 @@ var AUTHORIZATION_CODE_HTML = `
721
721
  document.getElementById('details').textContent = message;
722
722
  }
723
723
 
724
- // Extract authorization code and state from URL query parameters (OAuth 2.1)
724
+ // Handle both OAuth 2.1 authorization code flow and implicit flow
725
725
  const urlParams = new URLSearchParams(window.location.search);
726
+ const hashParams = new URLSearchParams(window.location.hash.substring(1));
726
727
 
728
+ // Check for authorization code first (OAuth 2.1 flow)
727
729
  if (urlParams.has('code')) {
728
730
  const authData = {
729
731
  code: urlParams.get('code'),
@@ -759,13 +761,63 @@ var AUTHORIZATION_CODE_HTML = `
759
761
  displayStatus('\u274C Error completing authorization', 'error');
760
762
  displayDetails(error.message + '. Please try again.');
761
763
  });
762
- } else if (urlParams.has('error')) {
764
+ }
765
+ // Check for access token in URL fragment (implicit flow - WordPress.com)
766
+ else if (hashParams.has('access_token')) {
767
+ const tokens = {
768
+ access_token: hashParams.get('access_token'),
769
+ token_type: hashParams.get('token_type') || 'Bearer',
770
+ expires_in: hashParams.get('expires_in') ? parseInt(hashParams.get('expires_in')) : 3600,
771
+ scope: hashParams.get('scope'),
772
+ state: hashParams.get('state'),
773
+ obtained_at: Date.now()
774
+ };
775
+
776
+ // Send tokens to server for storage
777
+ fetch('/oauth/tokens', {
778
+ method: 'POST',
779
+ headers: {
780
+ 'Content-Type': 'application/json'
781
+ },
782
+ body: JSON.stringify(tokens)
783
+ })
784
+ .then(response => {
785
+ if (response.ok) {
786
+ displayStatus('\u2705 Authorization successful!', 'success');
787
+ displayDetails('WordPress.com OAuth authentication completed. You can now close this window.');
788
+ // Auto-close after 3 seconds
789
+ setTimeout(() => {
790
+ displayDetails('Closing window...');
791
+ setTimeout(() => window.close(), 1000);
792
+ }, 3000);
793
+ } else {
794
+ return response.json().then(err => {
795
+ throw new Error(err.error || 'Failed to store access token');
796
+ });
797
+ }
798
+ })
799
+ .catch(error => {
800
+ displayStatus('\u274C Error completing authorization', 'error');
801
+ displayDetails(error.message + '. Please try again.');
802
+ });
803
+ }
804
+ // Check for errors in query parameters
805
+ else if (urlParams.has('error')) {
763
806
  const error = urlParams.get('error');
764
807
  const errorDescription = urlParams.get('error_description');
765
808
  displayStatus('\u274C Authorization failed', 'error');
766
809
  displayDetails(\`Error: \${error}\${errorDescription ? ' - ' + errorDescription : ''}\`);
767
- } else {
768
- displayStatus('\u274C No authorization code received', 'error');
810
+ }
811
+ // Check for errors in URL fragment (implicit flow errors)
812
+ else if (hashParams.has('error')) {
813
+ const error = hashParams.get('error');
814
+ const errorDescription = hashParams.get('error_description');
815
+ displayStatus('\u274C Authorization failed', 'error');
816
+ displayDetails(\`Error: \${error}\${errorDescription ? ' - ' + errorDescription : ''}\`);
817
+ }
818
+ // No authorization code or access token found
819
+ else {
820
+ displayStatus('\u274C No authorization code or access token received', 'error');
769
821
  displayDetails('Please try the authorization process again.');
770
822
  }
771
823
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/mcp-wordpress-remote",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "MCP WordPress Remote proxy server",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"