[Bug]: "CORS requires basic auth" error when authenticating with OIDC token
Open
Nobody has claimed this yet.
0. Needs triage
26-feedback
bug
developer experience
feature: authentication
- Dominant language
- PHP
- Stars
- 36.9k
- Forks
- 5.2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 713
Description
⚠️ This issue respects the following points: ⚠️
- This is a bug, not a question or a configuration/webserver/proxy issue.
- This issue is not already reported on Github OR Nextcloud Community Forum (I've searched it).
- Nextcloud Server is up to date. See Maintenance and Release Schedule for supported versions.
- I agree to follow Nextcloud's Code of Conduct.
Bug description
- I use https://github.com/pulsejet/nextcloud-oidc-login/ for OIDC login in my server(as it supports ldap backend as a proxy)
- I'm trying to extend this plugin to support bearer token authentication for OCS API calls and also CORS API calls like the one in notes API
- I got it to work with OCS API calls but get "CORS requires basic auth" error whenever I try the notes API
- This line checks if the login was done using BASIC auth and otherwise throws an exception with the error
- I'm not sure this is a bug for most nextcloud users(it is very specific to the third party plugin I use) but would appreciate some direction as to how I can deal with my issue :)
Steps to reproduce
- Install https://github.com/pulsejet/nextcloud-oidc-login/ on your nextcloud server
- Configure the app with your OIDC provider
- Apply the following patch using
patch -u custom_apps/oidc_login/lib/AppInfo/Application.php -i oidc_api.patch
--- Application.php 2024-03-20 23:26:05.315639574 +0530
+++ Application-new.php 2024-03-20 23:27:12.099748051 +0530
@@ -20,6 +20,7 @@
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Util;
+use OCA\OIDCLogin\WebDAV\BearerAuthBackend;
class Application extends App implements IBootstrap
{
@@ -68,6 +69,15 @@
/** @var IRequest */
$request = $container->get(IRequest::class);
+ $bearerAuthBackend = $container->query(BearerAuthBackend::class);
+
+ // If it is an OCS request, try to authenticate with bearer token
+ if ($request->getHeader('OCS-APIREQUEST') === 'true' &&
+ $request->getHeader('OIDC-LOGIN-WITH-TOKEN') === 'true' &&
+ str_starts_with($request->getHeader('Authorization'), 'Bearer ')) {
+ $this->loginWithBearerToken($request, $bearerAuthBackend);
+ }
+
// Check if automatic redirection is enabled
$useLoginRedirect = $this->config->getSystemValue('oidc_login_auto_redirect', false);
@@ -157,4 +167,12 @@
}
}
}
+ private function loginWithBearerToken(IRequest $request, BearerAuthBackend $bearerAuthBackend) {
+ $authHeader = $request->getHeader('Authorization');
+ $bearerToken = substr($authHeader, 7);
+ if (empty($bearerToken)) {
+ return;
+ }
+ $bearerAuthBackend->validateBearerToken($bearerToken);
+ }
}
- Get an access token from OIDC provider
- Perform an API call to
/index.php/apps/notes/api/v0.2/noteswith Bearer authentication set using the above access token and headerOIDC-LOGIN-WITH-TOKENset totrue - Notice the "CORS requires basic auth" message
Expected behavior
- Notes API should return results correctly
Installation method
Community Docker image
Nextcloud Server version
26
Operating system
Debian/Ubuntu
PHP engine version
PHP 8.1
Web server
Nginx
Database engine version
MariaDB
Is this bug present after an update or on a fresh install?
Fresh Nextcloud Server install
Are you using the Nextcloud Server Encryption module?
Encryption is Enabled
What user-backends are you using?
- Default user-backend (database)
- LDAP/ Active Directory
- SSO - SAML
- Other
Configuration report
No response
List of activated Apps
No response
Nextcloud Signing status
No response
Nextcloud Logs
No response
Additional info
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/private/AppFramework/Middleware/Security/CORSMiddleware.php at the referenced check, then compare it with the Notes API controller and the OIDC login plugin's Application.php patch. Reproduce the bearer-authenticated request from the listed steps; done means a valid OIDC bearer request is accepted by the Notes API instead of returning “CORS requires basic auth”.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api, authentication, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100