diff --git a/packages/cli/src/cli/commands/documents.ts b/packages/cli/src/cli/commands/documents.ts index a5097be0..30ef6770 100644 --- a/packages/cli/src/cli/commands/documents.ts +++ b/packages/cli/src/cli/commands/documents.ts @@ -48,6 +48,7 @@ export const generatePreviewLink = errorHandler( let previewLink: string; try { + // TODO: Check if we can derive domain from the document previewLink = await AddOnApiHelper.previewFile(cleanedId, domain, { baseUrl, }); diff --git a/packages/cli/src/cli/commands/login.ts b/packages/cli/src/cli/commands/login.ts index e58eef78..dc621228 100644 --- a/packages/cli/src/cli/commands/login.ts +++ b/packages/cli/src/cli/commands/login.ts @@ -1,23 +1,14 @@ import nunjucks from "nunjucks"; -import { getAuthProvider } from "../../lib/auth"; +import { Auth0Provider } from "../../lib/auth"; import { errorHandler } from "../exceptions"; nunjucks.configure({ autoescape: true }); -async function login({ - authType, - scopes, -}: { - authType: "auth0" | "google"; - scopes?: string[]; -}): Promise { - const provider = getAuthProvider(authType, scopes); +async function login(): Promise { + const provider = new Auth0Provider(); await provider.login(); } -export default errorHandler<{ - authType: "auth0" | "google"; - scopes?: string[]; -}>(login); +export default errorHandler(login); export const LOGIN_EXAMPLES = [ { description: "Login the user", command: "$0 login" }, ]; diff --git a/packages/cli/src/cli/index.ts b/packages/cli/src/cli/index.ts index 327fa911..21d5ef1c 100755 --- a/packages/cli/src/cli/index.ts +++ b/packages/cli/src/cli/index.ts @@ -896,7 +896,7 @@ yargs(hideBin(process.argv)) () => { // noop }, - async () => await login({ authType: "auth0" }), + async () => await login(), ) .command( "logout", diff --git a/packages/cli/src/lib/addonApiHelper.ts b/packages/cli/src/lib/addonApiHelper.ts index 9e4b1a0f..4fd03558 100644 --- a/packages/cli/src/lib/addonApiHelper.ts +++ b/packages/cli/src/lib/addonApiHelper.ts @@ -154,24 +154,20 @@ class AddOnApiHelper { } static async publishDocument(documentId: string, domain: string) { - const { id_token: idToken, access_token: oauthToken } = - await this.getGoogleTokens({ - scopes: ["https://www.googleapis.com/auth/drive.file"], - domain, - }); - - if (!idToken || !oauthToken) { - throw new UserNotLoggedIn(); - } + const { access_token: auth0AccessToken } = await this.getAuth0Tokens(); + const { access_token: googleAccessToken } = await this.getGoogleTokens({ + scopes: ["https://www.googleapis.com/auth/drive.file"], + domain, + }); const resp = await axios.post<{ url: string }>( `${(await getApiConfig()).DOCUMENT_ENDPOINT}/${documentId}/publish`, {}, { headers: { - Authorization: `Bearer ${idToken}`, + Authorization: `Bearer ${auth0AccessToken}`, "Content-Type": "application/json", - "oauth-token": oauthToken, + "oauth-token": googleAccessToken, }, }, ); diff --git a/packages/cli/src/lib/apiConfig.ts b/packages/cli/src/lib/apiConfig.ts index 1d27261d..de48d75b 100644 --- a/packages/cli/src/lib/apiConfig.ts +++ b/packages/cli/src/lib/apiConfig.ts @@ -21,6 +21,7 @@ const apiConfigMap: { [key in TargetEnvironment]: ApiConfig } = { [TargetEnvironment.production]: { addOnApiEndpoint: "https://us-central1-pantheon-content-cloud.cloudfunctions.net/addOnApi", + // TODO: Update with the Auth0 prod tenant auth0ClientId: "432998952749-6eurouamlt7mvacb6u4e913m3kg4774c.apps.googleusercontent.com", auth0RedirectUri: "http://localhost:3030/oauth-redirect", @@ -32,9 +33,11 @@ const apiConfigMap: { [key in TargetEnvironment]: ApiConfig } = { playgroundUrl: "https://live-collabcms-fe-demo.appa.pantheon.site", }, [TargetEnvironment.staging]: { + // TODO: Uncomment the correct one // addOnApiEndpoint: // "https://us-central1-pantheon-content-cloud-staging.cloudfunctions.net/addOnApi", addOnApiEndpoint: "http://localhost:8080", + // TODO: Update with the Auth0 staging tenant auth0ClientId: "RAHxEbc251zD529hByapcv6Dcp3pmv4P", auth0RedirectUri: "http://localhost:3030/oauth-redirect", auth0Audience: "https://addonapi-cxog5ytt4a-uc.a.run.app", diff --git a/packages/cli/src/lib/localStorage.ts b/packages/cli/src/lib/localStorage.ts index 76061857..0ded324e 100644 --- a/packages/cli/src/lib/localStorage.ts +++ b/packages/cli/src/lib/localStorage.ts @@ -33,33 +33,30 @@ const readFile = async (path: string): Promise => { export const getConfigDetails = async (): Promise => { return readFile(CONFIG_FILE_PATH); }; +export const getAuthDetails = async (): Promise => { + return readFile(AUTH_FILE_PATH); +}; +export const getGoogleAuthDetails = async (): Promise< + PersistedTokens[] | null +> => { + return readFile(GOOGLE_AUTH_FILE_PATH); +}; export const persistConfigDetails = async (payload: Config): Promise => { await persistDetailsToFile(payload, CONFIG_FILE_PATH); }; - -export const deleteConfigDetails = async () => remove(CONFIG_FILE_PATH); - -export const getAuthDetails = async (): Promise => { - return readFile(AUTH_FILE_PATH); -}; export const persistAuthDetails = async ( payload: PersistedTokens, ): Promise => { await persistDetailsToFile(payload, AUTH_FILE_PATH); }; - -export const getGoogleAuthDetails = async (): Promise< - PersistedTokens[] | null -> => { - return readFile(GOOGLE_AUTH_FILE_PATH); -}; export const persistGoogleAuthDetails = async ( payload: PersistedTokens[], ): Promise => { await persistDetailsToFile(payload, GOOGLE_AUTH_FILE_PATH); }; +export const deleteConfigDetails = async () => remove(CONFIG_FILE_PATH); export const deleteAuthDetails = async () => remove(AUTH_FILE_PATH); export const deleteGoogleAuthDetails = async () => remove(GOOGLE_AUTH_FILE_PATH);