-
Notifications
You must be signed in to change notification settings - Fork 399
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
Feature - SSO keycloak #5691
Open
paulbauriegel
wants to merge
3
commits into
argilla-io:develop
Choose a base branch
from
paulbauriegel:feature/sso_keycloak
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature - SSO keycloak #5691
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Create sso_keycloak.md
- Loading branch information
commit 572af7a337068a49437b41f164fd1d0ee4b0426f
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
docs/_source/tutorials_and_integrations/integrations/sso_keycloak.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# SSO Integration Keycloak | ||
|
||
To test this run a test version of Keycloak in Docker: | ||
|
||
```bash | ||
docker run -p 8080:8080 -e KC_BOOTSTRAP_ADMIN_USERNAME=admin -e KC_BOOTSTRAP_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:26.0.5 start-dev | ||
``` | ||
|
||
After that you might want to create a new realm and a client for Argilla to use. The client should expose the client audience via userinfo. And then add a user. | ||
The script below should do all of that for you to test. | ||
|
||
```python | ||
from keycloak import KeycloakAdmin | ||
from keycloak import KeycloakOpenIDConnection | ||
from keycloak import KeycloakOpenID | ||
|
||
keycloak_connection = KeycloakOpenIDConnection( | ||
server_url="http://localhost:8080/", | ||
username="admin", | ||
password="admin", | ||
realm_name="master", | ||
client_id="admin-cli", | ||
) | ||
|
||
keycloak_admin = KeycloakAdmin(connection=keycloak_connection) | ||
|
||
keycloak_admin.create_realm( | ||
{ | ||
"realm": "argilla", | ||
"enabled": True, | ||
"displayName": "Argilla", | ||
"userManagedAccessAllowed": True, | ||
} | ||
) | ||
keycloak_connection = KeycloakOpenIDConnection( | ||
server_url="http://localhost:8080/", | ||
username="admin", | ||
password="admin", | ||
user_realm_name="master", | ||
realm_name="argilla", | ||
) | ||
|
||
keycloak_admin = KeycloakAdmin(connection=keycloak_connection) | ||
|
||
new_user = keycloak_admin.create_user( | ||
{ | ||
"email": "example@example.com", | ||
"username": "example", | ||
"enabled": True, | ||
"firstName": "Example", | ||
"lastName": "User", | ||
"credentials": [ | ||
{ | ||
"value": "secret", | ||
"type": "password", | ||
} | ||
], | ||
} | ||
) | ||
|
||
client = keycloak_admin.create_client( | ||
{ | ||
"clientId": "example-client", # The client ID (you can choose a name) | ||
"enabled": True, | ||
"protocol": "openid-connect", # Protocol (you can use other protocols like 'saml' if needed) | ||
"publicClient": False, # Set to False if the client will use client secrets | ||
"directAccessGrantsEnabled": True, | ||
"standardFlowEnabled": True, | ||
"frontchannelLogout": True, | ||
"secret": "client-secret", # Set a secret if it's not a public client | ||
"redirectUris": [ | ||
"http://localhost:3000/*", | ||
"http://localhost:6900/*", | ||
], # Redirect URIs after authentication | ||
} | ||
) | ||
|
||
keycloak_openid = KeycloakOpenID(server_url="http://localhost:8080/", | ||
client_id="example-client", | ||
realm_name="argilla") | ||
|
||
public_key = keycloak_openid.public_key() | ||
|
||
client_scope = keycloak_admin.create_client_scope({ | ||
"name": "example-client-scope_3", | ||
"protocol": "openid-connect" | ||
}) | ||
|
||
# Create Audience Mapper | ||
mapper = keycloak_admin.add_mapper_to_client_scope( | ||
client_scope_id=client_scope, | ||
payload={ | ||
"name": "Client Audience", | ||
"protocol": "openid-connect", | ||
"protocolMapper": "oidc-audience-mapper", | ||
"consentRequired": False, | ||
"config": { | ||
"included.client.audience": "example-client", | ||
"id.token.claim": "false", | ||
"access.token.claim": "true" | ||
} | ||
}) | ||
|
||
keycloak_admin.add_default_default_client_scope(client_scope) | ||
``` | ||
|
||
After that you need to configure you endpoints in the `.oauth.yaml` same as this is done for the HuggingFace Oauth: | ||
|
||
```yaml | ||
# Change to `false` to disable HF oauth integration | ||
#enabled: false | ||
|
||
allow_http_redirect: true | ||
|
||
providers: | ||
- name: keycloak | ||
client_id: <name of your client e.g. example-client> | ||
client_secret: <value of your specified secret e.g. client-secret> | ||
redirect_uri: http://0.0.0.0:3000/oauth/keycloak/callback | ||
oidc_endpoint: http://localhost:8080/realms/<name of your realm e.g. argilla> | ||
- name: huggingface | ||
client_id: <create a new https://huggingface.co/settings/connected-applications> | ||
client_secret: <create a new https://huggingface.co/settings/connected-applications> | ||
redirect_uri: http://0.0.0.0:3000/oauth/huggingface/callback # if you test locally | ||
|
||
# Allowed workspaces must exists | ||
allowed_workspaces: | ||
- name: default | ||
``` | ||
|
||
And you are good to go |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This docs folder is outdated. For 2.x docs you should use the
argilla/docs
folder.