decaporg / decaporg/decap-cms

Custom OAuth doesn't work when the base_url is set to a sub path

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

Description

**Describe the bug**
Custom github OAuth doesn't work when the base_url is set to a sub path.

**To Reproduce**
1. Configure the admin url with a base_url that contains a sub path.
2. Configure and implement a custom OAuth adapter, in this case the typescript one provided in the chart on the documentation.
3. Login to github through the CMS
4. Left with a white screen as the handshake code is never ran because of the base_url

**Expected behavior**
Once the Auth flow happens and the window messages are passed back in forth from a custom OAuth implementation, the user should be logged in if the application is configured with a base_url that has a sub path as the root.

**Applicable Versions:**
- Decap CMS version: 3
- Node.JS version: 18

**CMS configuration**

```
backend:
name: github
repo:
preview_context: pages/build
branch: main
use_graphql: true
base_url: https://authserver.domain/stage/ < --- Issue here
```

**Additional context**
My routes will be

https://authserver.domain/stage/auth

https://authserver.domain/stage/callback

I see within the decap-cms-lib-auth package, the package is checking the origin with the base_url however the origin for request will only give you the root url without any extra paths in both the handshakeCallback functions and the authorizeCallback functions.

https://github.com/decaporg/decap-cms/blob/master/packages/decap-cms-lib-auth/src/netlify-auth.js#L44

https://github.com/decaporg/decap-cms/blob/master/packages/decap-cms-lib-auth/src/netlify-auth.js#L55

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.