decaporg / decaporg/decap-cms

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

Open
#7,183 2 comments 0 reactions 0 assignees View on GitHub
area: extensions/backends/bitbucket type: bug
Dominant language
JavaScript
Stars
19.4k
Forks
3.1k
Avg merge
1d 14h
Merged PRs (30d)
9

Description

## **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](https://github.com/decaporg/decap-cms/assets/1313681/2231f0e5-92c0-46d3-8fef-964965d87bf2)

**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 => [
{ ...(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[],
},
};
};
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.