404 when try to login via Keycloak SSO #7425

Closed
opened 2025-12-29 20:23:19 +01:00 by adam · 3 comments
Owner

Originally created by @3hcloud-internal on GitHub (Dec 26, 2022).

NetBox version

v3.4.1

Python version

3.10

Steps to Reproduce

  1. Configure SSO using python-social-auth. Guided by manuals Netbox docs and python-social-auth docs
...
REMOTE_AUTH_ENABLED = True
REMOTE_AUTH_BACKEND = 'social_core.backends.keycloak.KeycloakOAuth2'

SOCIAL_AUTH_KEYCLOAK_KEY: 'netbox'
SOCIAL_AUTH_KEYCLOAK_SECRET: '<secret-key>'
SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY: '<public-key>'
SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL: 'https://nb-dev/realms/netbox/protocol/openid-connect/auth'
SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL: 'https://kc-dev/auth/realms/netbox/protocol/openid-connect/token'
SOCIAL_AUTH_KEYCLOAK_ID_KEY: 'email'
...

Expected Behavior

When I tap on a Keycloak link in a Netbox login page I expect redirect to the Keycloak login page or authorization and comeback to Netbox.
image

Observed Behavior

But I get 301 redirect to https://nb-dev/oauth/login/keycloak/None?client_id=None&redirect_uri=https://nb-dev/oauth/complete/keycloak/&state=GnO9X5pHVB7CDY0qhib4aVHkjoaIipDN&response_type=code and 404 Page not found error:

image
Originally created by @3hcloud-internal on GitHub (Dec 26, 2022). ### NetBox version v3.4.1 ### Python version 3.10 ### Steps to Reproduce 1. Configure SSO using python-social-auth. Guided by manuals [Netbox docs](https://demo.netbox.dev/static/docs/administration/authentication/#single-sign-on-sso) and [python-social-auth docs](https://github.com/python-social-auth/social-core/blob/master/social_core/backends/keycloak.py) ``` ... REMOTE_AUTH_ENABLED = True REMOTE_AUTH_BACKEND = 'social_core.backends.keycloak.KeycloakOAuth2' SOCIAL_AUTH_KEYCLOAK_KEY: 'netbox' SOCIAL_AUTH_KEYCLOAK_SECRET: '<secret-key>' SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY: '<public-key>' SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL: 'https://nb-dev/realms/netbox/protocol/openid-connect/auth' SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL: 'https://kc-dev/auth/realms/netbox/protocol/openid-connect/token' SOCIAL_AUTH_KEYCLOAK_ID_KEY: 'email' ... ``` ### Expected Behavior When I tap on a Keycloak link in a Netbox login page I expect redirect to the Keycloak login page or authorization and comeback to Netbox. <img width="687" alt="image" src="https://user-images.githubusercontent.com/108896423/209585613-33d7a414-c5ee-44e4-b11a-04cbdaaddade.png"> ### Observed Behavior But I get 301 redirect to `https://nb-dev/oauth/login/keycloak/None?client_id=None&redirect_uri=https://nb-dev/oauth/complete/keycloak/&state=GnO9X5pHVB7CDY0qhib4aVHkjoaIipDN&response_type=code` and 404 Page not found error: <img width="1257" alt="image" src="https://user-images.githubusercontent.com/108896423/209585804-e37dc785-6150-44a7-87f5-a144c88de365.png">
adam closed this issue 2025-12-29 20:23:19 +01:00
Author
Owner

@zwiy commented on GitHub (Jan 4, 2023):

@3hcloud-internal How did you fix this behaviour? I get the same result with netbox v3.4.2 (netbox-docker).

@zwiy commented on GitHub (Jan 4, 2023): @3hcloud-internal How did you fix this behaviour? I get the same result with netbox v3.4.2 (netbox-docker).
Author
Owner

@tsv1991 commented on GitHub (Jan 4, 2023):

@zwiy in this case it's my syntactic mistake. I used ":" instead of "=" for SOCIAL_AUTH_KEYCLOAK_* sections.

@tsv1991 commented on GitHub (Jan 4, 2023): @zwiy in this case it's my syntactic mistake. I used ":" instead of "=" for SOCIAL_AUTH_KEYCLOAK_* sections.
Author
Owner

@zwiy commented on GitHub (Jan 5, 2023):

@tsv1991 Good hint, thanks.
In my case it was another mistake. netbox-docker doesn't read the SOCIAL_AUTH_* settings from the environment variables. They have to be set in a custom config file:
https://github.com/netbox-community/netbox-docker/wiki/Configuration#custom-configuration-files

@zwiy commented on GitHub (Jan 5, 2023): @tsv1991 Good hint, thanks. In my case it was another mistake. netbox-docker doesn't read the `SOCIAL_AUTH_*` settings from the environment variables. They have to be set in a custom config file: https://github.com/netbox-community/netbox-docker/wiki/Configuration#custom-configuration-files
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7425