Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keycloak SSO #5711

Open
wants to merge 5 commits into
base: refactor/argilla-server/better-oauth2-integration
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import os
from typing import Type, Dict, Any
from typing import Type, Dict, Any, Optional

from social_core.backends.oauth import BaseOAuth2
from social_core.backends.open_id_connect import OpenIdConnectAuth
Expand Down Expand Up @@ -48,6 +48,26 @@ class HuggingfaceOpenId(OpenIdConnectAuth):
DEFAULT_SCOPE = ["openid", "profile"]


class KeycloakOpenId(OpenIdConnectAuth):
"""Huggingface OpenID Connect authentication backend."""

name = "keycloak"

def oidc_endpoint(self) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only need this one. The rest of the required values (auth URL or access token URL) should be returned by the oicd_config endpoint based on the oidc endpoint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this works, I updated the docs accordingly. Now configuring keycloak would work by just setting the SOCIAL_AUTH_OIDC_ENDPOINT environment variable in addition to the oauth yaml.

value = super().oidc_endpoint()

if value is None:
from social_core.utils import setting_name

name = setting_name("OIDC_ENDPOINT")
raise ValueError(
"oidc_endpoint needs to be set in the Keycloak configuration. "
f"Please set the {name} environment variable."
)

return value


_SUPPORTED_BACKENDS = {}


Expand All @@ -56,9 +76,9 @@ def load_supported_backends(extra_backends: list = None) -> Dict[str, Type[BaseO

backends = [
"argilla_server.security.authentication.oauth2._backends.HuggingfaceOpenId",
"argilla_server.security.authentication.oauth2._backends.KeycloakOpenId",
"social_core.backends.github.GithubOAuth2",
"social_core.backends.google.GoogleOAuth2",
"social_core.backends.keycloak.KeycloakOAuth2",
]

if extra_backends:
Expand Down