Allow sub path for Nextcloud
When Nextcloud is not served at the root (ie: https://xxx.com/nextcloud), the post-authentication redirection fails if access is attempted via any sub-URL. For example in the case of https://xxx.com/nextcloud/apps/dashboard/ the portion of the path representing the root of the instance (ie: /nextcloud) is lost during the redirection: https://xxx.com/apps/dashboard/ => obviously leading to a 404 error.
I can't reproduce the issue. This is supposed to work as the redirect_uri Nextcloud gives to the provider's authorization endpoint is generated correctly as far as I've seen in the code.
This might be a config issue on your side. Maybe your subpath is not included in overwrite.cli.url in your Nextcloud config.
I've encountered the same issue; the callback to https://xxx.com/nextcloud/apps/user_oidc/code leads to a redirect to /apps/dashboard, thus giving https://xxx.com/apps/dashboard instead of https://xxx.com/nextcloud/apps/dashboard. I've checked the configuration of the overwrite.cli.url and overwrite.cli.webroot, both are setup correctly.
After searching a bit through the codebase, it seems that the redirect url given by Nextcloud to the /nextcloud/login route (then /nextcloud/apps/user_oidc/login/1) is only the path on the nextcloud instance, /apps/dashboard in this example. When the user comes back from the provider, on https://xxx.com/nextcloud/apps/user_oidc/code, the function simply returns the redirect_uri stored in the session (here), causing to the issue.
If I understand correctly, it should instead use the URLGenerator::linkToRoute to include webroot to the redirection.