Skip to content

SSO Authentication fails with 401 #10911

Closed

Description

@vsviridov

Please verify that this bug has NOT been raised before.

  • I checked and didn't find a similar issue

Describe the bug*

I've configured SSO using Zitadel/Open ID Connect using the config file, and now when coming back from the IDP i get redirected to the login page with a 401 error on /api/auth/v1/auth/session endpoint. There's no logs even at "TRACE" level and I can't figure out at which stage it fails.

Steps to Reproduce

Add openid configuration to the config.yaml

      social_backends:
        - 'allauth.socialaccount.providers.openid_connect'
      social_providers:
        openid_connect:
          APPS:
            - provider_id: Zitadel
              name: Zitadel
              client_id: '-----'
              settings:
                fetch_userinfo: false
                oauth_pkce_enabled: true
                server_url: 'https://auth.------.com'   

Enabled relevant SSO Flags

Image

Expected behaviour

Should be authenticated

Deployment Method

None

Version Information

InvenTree-Version: 1.1.5
Django Version: 4.2.26
Commit Hash: c09fb48
Commit Date: 2025-11-22
Commit Branch: null
Database: django.db.backends.postgresql
Debug-Mode: False
Deployed using Docker: True
Platform: Linux-6.17.2-1-pve-x86_64-with-glibc2.41
Installer: DOC
Active plugins: [{"name":"InvenTreeBarcode","slug":"inventreebarcode","version":"2.1.0"},{"name":"BOM Exporter","slug":"bom-exporter","version":"1.1.0"},{"name":"InvenTree Exporter","slug":"inventree-exporter","version":"1.0.0"},{"name":"Part Parameter Exporter","slug":"parameter-exporter","version":"1.0.0"},{"name":"InvenTreeEmailNotifications","slug":"inventree-email-notification","version":"1.0.0"},{"name":"InvenTreeUINotifications","slug":"inventree-ui-notification","version":"1.0.0"},{"name":"InvenTreeCurrencyExchange","slug":"inventreecurrencyexchange","version":"1.0.0"},{"name":"InvenTreeMachines","slug":"inventree-machines","version":"1.0.0"},{"name":"InvenTreeLabel","slug":"inventreelabel","version":"1.1.0"},{"name":"InvenTreeLabelMachine","slug":"inventreelabelmachine","version":"1.0.0"}]

Try to reproduce on the demo site

I did not try to reproduce

Is the bug reproducible on the demo site?

Not reproducible

Relevant log output

2025-11-25T23:46:20.416608000Z 2025-11-25 15:46:20,416 INFO {'request': 'GET /api/auth/v1/auth/session', 'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:145.0) Gecko/20100101 Firefox/145.0', 'event': 'request_started', 'user_id': None, 'request_id': '1beb935e-330e-4797-8b7a-f85f2784d2b8', 'ip': '192.168.1.70', 'timestamp': '2025-11-25T23:46:20.415996Z', 'logger': 'django_structlog.middlewares.request', 'level': 'info'}

2025-11-25T23:46:20.420678000Z 2025-11-25T23:46:20.420316Z [warning  ] request_finished               [django_structlog.middlewares.request] code=401 ip=192.168.1.70 request='GET /api/auth/v1/auth/session' request_id=1beb935e-330e-4797-8b7a-f85f2784d2b8 user_id=None

2025-11-25T23:46:20.420813000Z 2025-11-25 15:46:20,420 WARNING {'code': 401, 'request': 'GET /api/auth/v1/auth/session', 'event': 'request_finished', 'user_id': None, 'request_id': '1beb935e-330e-4797-8b7a-f85f2784d2b8', 'ip': '192.168.1.70', 'timestamp': '2025-11-25T23:46:20.420316Z', 'logger': 'django_structlog.middlewares.request', 'level': 'warning'}

2025-11-25T23:46:20.421771000Z 2025-11-25 15:46:20,421 WARNING Unauthorized: /api/auth/v1/auth/session

Activity

  1. added
    bug
    question
    triage:not-checked
    on Nov 25, 2025
  2. vsviridov commented on Nov 27, 2025

    @vsviridov
    Author

    I've configured an application via admin backend, and it exhibits the same issue. No logs in the system point me to any place in particular.

  3. znibb commented on Dec 1, 2025

    @znibb

    I'm believe I'm having the same issue, although I am trying to configure the backend and provider via docker environment variables. No matter what version of the config I try I can't make Inventree show a "Sign in with SSO" button on the login screen which (according to ChatGPT) could mean that the OpenID backend is never loaded, possibly due to missing social-auth-core and social-auth-app-django packages. This might just be the AI hallucinating but it's where I am at so far.

  4. matmair commented on Dec 30, 2025

    @matmair
    Member

    @vsviridov it looks like the user is not authenticated. If I had to guess that could be because the exaisting account is not associated with the OIDC identity. Maybe try activating SSO registration.

    @znibb please do not waste maintainer time with AI slop guessing. InvenTree uses django-allauth, as stated by the docs https://docs.inventree.org/en/stable/settings/SSO/

  5. added
    setup
    and removed
    bug
    triage:not-checked
    on Dec 30, 2025
  6. bunkmate5127 commented on Jan 9, 2026

    @bunkmate5127

    I hit the same thing... my primary symptom after tearing my hair out trying to figure this out is that no SSO button for login appears no matter what I do.

    I've boiled it down to django not including openid_connect, only openid:

    These are all the things installed in the current stable docker:

    >>> from django.conf import settings
    >>> print("\n".join(settings.INSTALLED_APPS))
    django.contrib.admin
    django.contrib.admindocs
    build.apps.BuildConfig
    common.apps.CommonConfig
    plugin.apps.PluginAppConfig
    company.apps.CompanyConfig
    order.apps.OrderConfig
    part.apps.PartConfig
    report.apps.ReportConfig
    stock.apps.StockConfig
    users.apps.UsersConfig
    machine.apps.MachineConfig
    data_exporter.apps.DataExporterConfig
    importer.apps.ImporterConfig
    web
    generic
    InvenTree.apps.InvenTreeConfig
    django.contrib.auth
    django.contrib.contenttypes
    django.contrib.sessions
    django.contrib.humanize
    whitenoise.runserver_nostatic
    django.contrib.messages
    django.contrib.staticfiles
    maintenance_mode
    django_filters
    rest_framework
    corsheaders
    django_cleanup.apps.CleanupConfig
    mptt
    markdownify
    djmoney
    djmoney.contrib.exchange
    error_report
    django_q
    dbbackup
    taggit
    flags
    django_structlog
    allauth
    allauth.account
    allauth.headless
    allauth.socialaccount
    allauth.mfa
    allauth.usersessions
    django_otp
    django_otp.plugins.otp_totp
    django_otp.plugins.otp_static
    oauth2_provider
    drf_spectacular
    django_ical
    django_mailbox
    anymail
    storages
    allauth.socialaccount.providers.openid
    

    Note there is: allauth.socialaccount.providers.openid, but there is not allauth.socialaccount.providers.openid_connect. These are different things:
    https://docs.allauth.org/en/dev/socialaccount/providers/openid_connect.html (current, OIDC)
    https://docs.allauth.org/en/dev/socialaccount/providers/openid.html (old, obsolete)

    The documentation sorely needs some first-party example of a working OIDC implementation.

  7. matmair commented on Jan 9, 2026

    @matmair
    Member

    Please provide more information about the setups @bunkmate5127 - this is not enough to replicate.

    OpenID and OIDC are different protocols with different audiences. InvenTree only loads the providers that are configured (via INVENTREE_SOCIAL_BACKENDS).

  8. znibb commented on Jan 10, 2026

    @znibb

    @bunkmate5127 My issue was with having no clue how the configuration options for django-allauth were to be set from the context of docker compose. Here's what I ended up with that works for me:

    I'm using Traefik as a reverse-proxy using Authentik as the Identity Provider (links are to the repos with the compose files I'm using.

    Here's my notes for how I configured Authentik and Inventree to allow OIDC: link

    Here's my Inventree docker compose file: link

    One key element here is the line "INVENTREE_SOCIAL_BACKENDS=allauth.socialaccount.providers.openid_connect" in .env that enables selecting "OpenID Connect" under SOCIAL APPLICATIONS in Inventree.

    Inventree is an amazing platform with a lot of powerful potential, kudos to @matmair and all the other contributors and maintainers. Sorry about the "AI slop" in my initial post, it was a product of me being at my wit's end due to the aforementioned lack of examples of how to configure django-allauth through the scope of docker compose.

  9. p-fruck commented on Jan 19, 2026

    @p-fruck
    Contributor

    I think there is another issue with the same question
    I've been running inventree with SSO for quite some time now but have never been able to fully configure SSO through the environment, I always had to use the django admin UI.
    My only environment based SSO config is the following:

    INVENTREE_EMAIL_HOST=localhost # https://github.com/inventree/InvenTree/issues/4553
    INVENTREE_SOCIAL_BACKENDS=allauth.socialaccount.providers.openid_connect

    Maybe throw away the config.yaml or environment variables related to social providers and only use the database config (through django admin ui)

  10. plaes commented on Jan 21, 2026

    @plaes
    Contributor

    It might be that you're missing the client_secret:

                - provider_id: Zitadel
                  name: Zitadel
                  client_id: '-----'
                  settings:
                    fetch_userinfo: false
                    oauth_pkce_enabled: true
                    server_url: 'https://auth.------.com'   
  11. vsviridov commented on Jan 21, 2026

    @vsviridov
    Author
  12. 8 remaining items

  13. matmair commented on May 19, 2026

    @matmair
    Member

    @mylesagray has enableling LOGIN_ENABLE_REG provided any further infos?

  14. mylesagray commented on May 19, 2026

    @mylesagray
  15. removed
    inactive
    on May 20, 2026
  16. stv0g commented on Jun 13, 2026

    @stv0g

    I have the same issue.

  17. github-actions commented on Aug 13, 2026

    @github-actions
    Contributor

    This issue seems stale. Please react to show this is still important.

  18. added
    inactive
    on Aug 13, 2026
  19. removed
    inactive
    on Aug 22, 2026
  20. jcpage573 commented on Aug 26, 2026

    @jcpage573

    I think the issue is here — on 1.5.2 (Entra ID / Microsoft provider, not Zitadel, so this looks provider-agnostic — it's a frontend gap, not an OIDC-specific issue).

    After a new user completes SSO auth, django-allauth correctly parks a pending SocialLogin in the session and reports it via GET /api/auth/v1/auth/session:

    {"status": 401, "data": {"flows": [{"id": "provider_signup", "provider": {...}, "is_pending": true}]}, "meta": {"is_authenticated": false}}

    checkLoginState() in src/frontend/src/functions/auth.tsx (invoked by the /logged-in page right after the OAuth callback) only branches on "authenticated" vs "not authenticated" — it never inspects flows for a pending provider_signup, unlike the MFA flows (MfaAuthenticate/MfaTrust), which are explicitly handled in the same file. So it just redirects to /login, with no error shown, and the account is never finalized.

    There doesn't seem to be an existing client-side path to complete it either: ApiEndpoints.tsx has no entry for auth/v1/auth/provider/signup (the completion endpoint), and there's no reference to provider_signup anywhere in src/frontend besides the enum declaration in lib/types/Auth.tsx. I verified server-side that POSTing to that endpoint directly does work (returns a normal validation error asking for username), so this looks like a missing frontend handler rather than a backend/config issue.

    Repro: enable SSO + LOGIN_ENABLE_SSO_REG, sign in as a user with no existing InvenTree account. Confirmed on the actual 1.5.2 tag (commit f15e35c), not just master.

    (Investigated with the help of Claude Code.)

  21. SchrodingersGat commented on Aug 29, 2026

    @SchrodingersGat
    Member

    All, please review the proposed changes incoming in #12739

  22. added this to the 1.6.0 milestone on Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionsecuritysetup

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions