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

Problems with oAuth/Bitbucket update from NetlifyCMS@2 to DecapCMS@3 #7183

Open
crs1138 opened this issue Apr 17, 2024 · 0 comments
Open

Problems with oAuth/Bitbucket update from NetlifyCMS@2 to DecapCMS@3 #7183

crs1138 opened this issue Apr 17, 2024 · 0 comments
Labels
type: bug code to address defects in shipped code

Comments

@crs1138
Copy link

crs1138 commented Apr 17, 2024

Describe the bug

Current setup

We have a repository in Bitbucket Cloud that we use for storing the content as generated by NetlifyCMS@2. We have set up oAuth for the production using the auth_type='implicit in production. Meanwhile in development we access the CMS from http://localhost:3001/admin and the auth_type = undefined. This results in a call to API Netlify with https://api.netlify.com/auth?provider=bitbucket&site_id=cms.netlify.com&scope=repo which let's our developers to authenticate and enter in CMS.

Problem

One of the changes introduced in DecapCMS@3 is the change of the default site_domain used during the authentication. The site_domain (and consecutively the siteId) passed in the oAuth has changes from cms.netlify.com to demo.decapcms.org, this results in Not found response from https://api.netlify.com/auth?provider=bitbucket&site_id=demo.decapcms.org&scope=repo. As the demo.decapcms.org value is hardcoded for localhost, I can't override it.

If I search and replace all occurrences of demo.decapcms.org with cms.netlify.com, I am able to obtain the correct oAuth token and access into the CMS in localhost.

What am I supposed to do to enable access to CMS from localhost?

To Reproduce

  1. Update dependencies from
  • "netlify-cms-app": "^2.15.72" => "decap-cms-app": "^3.1.10"
  • "netlify-cms-core": "^2.55.2" => "decap-cms": "^3.1.10"

Expected behavior

I expect to be able to authenticate and enter CMS from the local development environment running on http://localhost:3001/admin.

Screenshots
demo.decapcms.org – failed login access

Applicable Versions:

  • Decap CMS version: 3.1.10
  • Git provider: Bitbucket
  • OS: MacOS 13.6.6, Ubuntu
  • Browser version brave 1.64.116
  • Node.JS version: 20.5.0
  • yarn 3.4.1

CMS configuration

Dynamic configuration

import type { CmsCollection } from 'decap-cms';
import type { ProductCmsConfig } from './types';
import type { EditorURLSearchParams } from 'web/app/admin/types';
import { components } from 'cms/collections/components';
import { sections } from 'cms/collections/sections';
import { pages } from 'cms/collections/pages';
import { commonPages } from 'cms/collections/commonPages';
import { commonProductPages } from 'cms/collections/commonProductPages';

const getCollections = async (
	product: string,
	theme: string,
): Promise<Object[]> => [
	{ ...(await components(product, theme)) },
	{ ...(await sections(product, theme)) },
	{ ...pages(product, theme) },
	{ ...commonPages },
	{ ...commonProductPages(product) },
];

export const getConfig = async ({
	branch,
	product,
	theme,
}: EditorURLSearchParams): Promise<{ config: ProductCmsConfig }> => {
	const IS_PROD = process.env!.NODE_ENV === 'production';
	const IS_STAGE = process.env!.NEXT_PUBLIC_APP_ENV === 'stage';

	const app_id = IS_STAGE
		? process.env!.NEXT_PUBLIC_CMS_APP_ID_STAGE
		: process.env!.NEXT_PUBLIC_CMS_APP_ID_PROD;
	return {
		config: {
			load_config_file: false,
			logo_url: '/common/logo.webp',
			backend: {
				open_authoring: true,
				name: 'bitbucket',
				branch: branch || process.env!.GIT_BRANCH,
				repo: process.env!.NEXT_PUBLIC_REPO,
				auth_type: IS_PROD ? 'implicit' : undefined,
				app_id,
				product,
				styleweb: theme,
				commit_messages: {
					create: 'Create {{collection}} “{{slug}}”',
					update: 'Update {{collection}} “{{slug}}”',
					delete: 'Delete {{collection}} “{{slug}}”',
					uploadMedia: '[skip ci] Upload “{{path}}”',
					deleteMedia: '[skip ci] Delete “{{path}}”',
				},
				siteId: 'mydomain.com',
			},
			publish_mode: 'editorial_workflow',
			// allow_nesting: true,
			media_folder: `/${
				IS_PROD ? '' : 'public'
			}/${product}/${theme}/assets/`, // Media files will be stored here.
			public_folder: `/${product}/${theme}/assets`, // The src attribute for uploaded media will begin with this path.
			site_url: IS_PROD
				? 'https://mydomain.com/editor'
				: 'http://localhost:3001/editor',
			collections: (await getCollections(
				product,
				theme,
			)) as CmsCollection[],
		},
	};
};
@crs1138 crs1138 added the type: bug code to address defects in shipped code label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

1 participant