Skip to content

Commit

Permalink
init commit for wordpress tool oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
tybalex committed Jan 17, 2025
1 parent 6518102 commit 67932ec
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions apiclient/types/oauthapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const (
OAuthAppTypeGitHub OAuthAppType = "github"
OAuthAppTypeGoogle OAuthAppType = "google"
OAuthAppTypeSalesforce OAuthAppType = "salesforce"
OAuthAppTypeWordPress OAuthAppType = "wordpress"
OAuthAppTypeZoom OAuthAppType = "zoom"
OAuthAppTypeCustom OAuthAppType = "custom"
)
Expand Down
6 changes: 6 additions & 0 deletions pkg/gateway/types/oauth_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const (

GitHubAuthorizeURL = "https://github.com/login/oauth/authorize"

WordPressAuthorizeURL = "https://public-api.wordpress.com/oauth2/authorize"
WordPressTokenURL = "https://public-api.wordpress.com/oauth2/token"

ZoomAuthorizeURL = "https://zoom.us/oauth/authorize"
ZoomTokenURL = "https://zoom.us/oauth/token"
)
Expand Down Expand Up @@ -71,6 +74,9 @@ func ValidateAndSetDefaultsOAuthAppManifest(r *types.OAuthAppManifest, create bo
case types.OAuthAppTypeGitHub:
r.AuthURL = GitHubAuthorizeURL
r.TokenURL = GitHubTokenURL
case types.OAuthAppTypeWordPress:
r.AuthURL = WordPressAuthorizeURL
r.TokenURL = WordPressTokenURL
case types.OAuthAppTypeZoom:
r.AuthURL = ZoomAuthorizeURL
r.TokenURL = ZoomTokenURL
Expand Down
2 changes: 2 additions & 0 deletions ui/admin/app/components/oauth-apps/OAuthAppTypeIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
FaMicrosoft,
FaSalesforce,
FaSlack,
FaWordpress,
} from "react-icons/fa";

import { OAuthProvider } from "~/lib/model/oauthApps/oauth-helpers";
Expand All @@ -21,6 +22,7 @@ const IconMap = {
[OAuthProvider.Google]: FaGoogle,
[OAuthProvider.Microsoft365]: FaMicrosoft,
[OAuthProvider.Notion]: NotionLogoIcon,
[OAuthProvider.WordPress]: FaWordpress,
[OAuthProvider.Zoom]: BiLogoZoom,
[OAuthProvider.Custom]: KeyIcon,
};
Expand Down
2 changes: 2 additions & 0 deletions ui/admin/app/lib/model/oauthApps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Microsoft365OAuthApp } from "~/lib/model/oauthApps/providers/microsoft3
import { NotionOAuthApp } from "~/lib/model/oauthApps/providers/notion";
import { SalesforceOAuthApp } from "~/lib/model/oauthApps/providers/salesforce";
import { SlackOAuthApp } from "~/lib/model/oauthApps/providers/slack";
import { WordPressOAuthApp } from "~/lib/model/oauthApps/providers/wordpress";
import { ZoomOAuthApp } from "~/lib/model/oauthApps/providers/zoom";
import { EntityMeta } from "~/lib/model/primitives";

Expand All @@ -22,6 +23,7 @@ export const OAuthAppSpecMap = {
[OAuthProvider.Slack]: SlackOAuthApp,
[OAuthProvider.Salesforce]: SalesforceOAuthApp,
[OAuthProvider.Notion]: NotionOAuthApp,
[OAuthProvider.WordPress]: WordPressOAuthApp,
[OAuthProvider.Zoom]: ZoomOAuthApp,
// Custom OAuth apps are intentionally omitted from the map.
// They are handled separately
Expand Down
1 change: 1 addition & 0 deletions ui/admin/app/lib/model/oauthApps/oauth-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const OAuthProvider = {
Slack: "slack",
Salesforce: "salesforce",
Notion: "notion",
WordPress: "wordpress",
Zoom: "zoom",
Custom: "custom",
} as const;
Expand Down
71 changes: 71 additions & 0 deletions ui/admin/app/lib/model/oauthApps/providers/wordpress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { z } from "zod";

import {
OAuthAppSpec,
OAuthFormStep,
getOAuthLinks,
} from "~/lib/model/oauthApps/oauth-helpers";
import { assetUrl } from "~/lib/utils";

const schema = z.object({
clientID: z.string().min(1, "Client ID is required"),
clientSecret: z.string().min(1, "Client Secret is required"),
});

const steps: OAuthFormStep<z.infer<typeof schema>>[] = [
{
type: "markdown",
text:
"### Step 1: Create a New Application at Developer.wordpress.com:\n" +
"If you already have an app, you can skip to Step 2.\n\n" +
"- Ensure you are logged into your preferred Wordpress.com account.\n" +
"- You can create and manage your apps at the [Apps](https://developer.wordpress.com/apps/) page.\n" +
"- Click **Create New Application** on the top right corner.\n" +
"- Enter a **Name**, **Description**, and **Website** for your application.\n" +
"- Copy the url below and paste it into the **Redirect URL** field.\n",
},
{
type: "copy",
text: getOAuthLinks("wordpress").redirectURL,
},
{
type: "markdown",
text:
"- Leave **Javascript Origins** blank for now, but you can update it later.\n" +
"- For **Type**, select **Web**.\n" +
"- Click **Create**.\n" +
"- You will be redirected to the **Manage Application** page of the app you just created.\n",
},
{
type: "markdown",
text:
"### Step 2: Register your App with Obot\n" +
"- In the **Manage Application** page, you can find the **Client ID** and **Client Secret** in the **OAuth Information** section.\n" +
"- Copy and paste them into the respective fields below.\n",
},
{ type: "input", input: "clientID", label: "Client ID" },
{
type: "input",
input: "clientSecret",
label: "Client Secret",
inputType: "password",
},
{
type: "markdown",
text:
"### (Optional) Create a New Site\n" +
"If you don't have a site yet, you can create one by following these steps:\n" +
"- Visit [WordPress Sites](https://wordpress.com/sites).\n" +
"- Click **Add New Site** in the top-right corner, and follow the instructions to create a new site.\n",
},
];

export const WordPressOAuthApp = {
schema,
alias: "wordpress",
type: "wordpress",
displayName: "WordPress",
logo: assetUrl("/assets/wordpress-logo.png"),
steps: steps,
noGatewayIntegration: true,
} satisfies OAuthAppSpec;
Binary file added ui/admin/public/assets/wordpress-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 67932ec

Please sign in to comment.