mirror of
https://github.com/makeplane/plane.git
synced 2026-07-14 06:25:58 +02:00
* [SILO-134] RUNWAY Implement new OAuth flow for Github integration (#3089) * oauth helper service + db helpers + modify plane sdk to accomodate oauth token * fix indentation + create util for remove undefined in object * add fields to workspace credential for oauth adapt * get oauth token helper method * auth callback flow changes to add plane oauth flow for github integration * integrate github user and auth callback with oauth * add user callback support with oauth for github integration * remove token from cache on app disconnection * Get Connection Details refactor change * remove unwanted logs * add missing translations * replace plane app client id and secret fetching from env to db * fix app get from db * refactoring and comments resolved * rename installation_id to plane_installation_id * use db query methods and complete the app secret fetch flow * remove unwanted logs and send missing values in update creds method * move plane app db call just before oauth token call + models export in init * Fix ssl reject error for pg * add NODE_ENV option for ssl db config + management command to reset app_secrets + iteration fix * fix oauth rate limit cache key breaking * Fix redirect uri issue * Fix pull request behaviour * remove NODE_ENV check in DB connection
111 lines
3.5 KiB
TypeScript
111 lines
3.5 KiB
TypeScript
import axios, { AxiosInstance } from "axios";
|
|
import { GithubAuthorizeState, GithubUserAuthState } from "@plane/etl/github";
|
|
// plane web types
|
|
import { TGithubWorkspaceConnection, TGithubWorkspaceUserConnection } from "@/plane-web/types/integrations";
|
|
|
|
export class GithubAuthService {
|
|
protected baseURL: string;
|
|
private axiosInstance: AxiosInstance;
|
|
|
|
constructor(baseURL: string) {
|
|
this.baseURL = baseURL;
|
|
this.axiosInstance = axios.create({ baseURL, withCredentials: true });
|
|
}
|
|
|
|
/**
|
|
* @description fetch organization
|
|
* @param { string } workspaceId
|
|
* @returns { Promise<TGithubWorkspaceConnection[] | undefined> }
|
|
*/
|
|
fetchOrganizationConnection = async (workspaceId: string): Promise<TGithubWorkspaceConnection[] | undefined> =>
|
|
await this.axiosInstance
|
|
.get(`/api/github/auth/organization-status/${workspaceId}`)
|
|
.then((res) => res.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
|
|
/**
|
|
* @description connect organization
|
|
* @param { GithubAuthorizeState } payload
|
|
* @returns { Promise<string> }
|
|
*/
|
|
connectOrganization = async (payload: GithubAuthorizeState): Promise<string> =>
|
|
await this.axiosInstance
|
|
.post(`/api/github/auth/url`, payload)
|
|
.then((res) => res.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
|
|
/**
|
|
* @description disconnect organization
|
|
* @param { string } workspaceId
|
|
* @param { string } organizationId
|
|
* @returns { Promise<void> }
|
|
*/
|
|
disconnectOrganization = async (workspaceId: string, organizationId: string, userId: string): Promise<void> =>
|
|
await this.axiosInstance
|
|
.post(`/api/github/auth/organization-disconnect/${workspaceId}/${organizationId}/${userId}`)
|
|
.then((res) => res.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
|
|
/**
|
|
* @description fetch user
|
|
* @param { string } workspaceId
|
|
* @param { string } userId
|
|
* @returns { Promise<TGithubWorkspaceUserConnection[] | undefined> }
|
|
*/
|
|
fetchUserConnection = async (
|
|
workspaceId: string,
|
|
userId: string
|
|
): Promise<TGithubWorkspaceUserConnection | undefined> =>
|
|
await this.axiosInstance
|
|
.get(`/api/github/auth/user-status/${workspaceId}/${userId}`)
|
|
.then((res) => res.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
|
|
/**
|
|
* @description connect user
|
|
* @param { GithubUserAuthState } payload
|
|
* @returns { Promise<string> }
|
|
*/
|
|
connectUser = async (payload: GithubUserAuthState): Promise<string> =>
|
|
await this.axiosInstance
|
|
.post(`/api/github/auth/user/url`, payload)
|
|
.then((res) => res.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
|
|
/**
|
|
* @description disconnect user
|
|
* @param { string } workspaceId
|
|
* @param { string } userId
|
|
* @returns { Promise<void> }
|
|
*/
|
|
disconnectUser = async (workspaceId: string, userId: string): Promise<void> =>
|
|
await this.axiosInstance
|
|
.post(`/api/github/auth/user-disconnect/${workspaceId}/${userId}`)
|
|
.then((res) => res.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
|
|
/**
|
|
* @description get plane app details
|
|
* @returns { Promise<{ appId: string; clientId: string }> }
|
|
*/
|
|
getPlaneAppDetails = async (): Promise<{ appId: string; clientId: string }> =>
|
|
await this.axiosInstance
|
|
.get(`/api/github/plane-app-details`)
|
|
.then((res) => res.data)
|
|
.catch((error) => {
|
|
throw error?.response?.data;
|
|
});
|
|
}
|