Authorization from apps, error 401

Nextcloud version (eg, 20.0.5): 22.1.0
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.29
PHP version (eg, 7.4): 7.4 cgi

The output of your Nextcloud log in Admin > Logging:

No public access to this resource., No 'Authorization: Basic' header found. Either the client didn't send one, or the server is misconfigured, No 'Authorization: Bearer' header found. Either the client didn't send one, or the server is mis-configured, No 'Authorization: Basic' header found. Either the client didn't send one, or the server is misconfigured.

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

  'instanceid' => 'xxx',
  'passwordsalt' => 'xxx',
  'secret' => 'xxx',
  'trusted_domains' => 
  array (
    0 => 'my.domain.com',
  ),
  'datadirectory' => '/xxx/public_html/data',
  'dbtype' => 'mysql',
  'version' => '22.1.0.1',
  'overwrite.cli.url' => 'https://my.domain.com',
  'dbname' => 'xxx',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'xxx',
  'dbpassword' => 'xxx',
  'installed' => true,

The output of your Apache/nginx/system log in /var/log/____:

PROPFIND /remote.php/dav/files/admin/ HTTP/1.1" 401

Hi! I have succesfully installed the latest version of Nextcloud on my LAMP server. There are problems with athentication from any App (tested Desktop & Android latest versions). Sign in from browser works perfectly. I have found similar problem here Cannot login with any apps - #4 by Vigrond but no solution helped for me. I am running cgi PHP and I have no possibilities to run mod_php :frowning:
Any ideas, how can I solve this problem?
A have tryed such code in .htaccess file, nothing helped:

SetEnvIf Authorization “(.*)” HTTP_AUTHORIZATION=$1
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
SetEnvIf Authorization .+ HTTP_AUTHORIZATION=$0
SetEnvIfNoCase Authorization "(Bearer .+)" HTTP_AUTHORIZATION=$1
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Header set Authorization ""
CGIPassAuth On
RewriteCond %{HTTP:Authorization} ^(.) 
RewriteRule . - [e=HTTP_AUTHORIZATION:%1]

I have such error in Android app:

Access failed: Operation finished with HTTP status code 401 (fail).

The problem is resolved. I have found original code in .htaccess

<IfModule mod_fcgid.c>
SetEnvIfNoCase ^Authorization$ "(.+)" XAUTHORIZATION=$1
RequestHeader set XAuthorization %{XAUTHORIZATION}e env=XAUTHORIZATION
</IfModule>

It was passive because of I have not FCGID, but CGI. After enabling this code (removed out of the IF statement) authorization works perfectly.

1 Like