Skip to content

docs: Update oauth keycloak example with new security manager #50284

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

Merged
merged 2 commits into from
May 12, 2025
Merged
Changes from all commits
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
16 changes: 8 additions & 8 deletions providers/fab/docs/auth-manager/webserver-authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ Here is an example of what you might have in your webserver_config.py:

.. code-block:: python

import os
import jwt
import requests
import logging
from base64 import b64decode

import jwt
import requests
from cryptography.hazmat.primitives import serialization
from flask_appbuilder.security.manager import AUTH_DB, AUTH_OAUTH
from airflow import configuration as conf
from airflow.www.security import AirflowSecurityManager
from flask_appbuilder.security.manager import AUTH_OAUTH

from airflow.providers.fab.auth_manager.security_manager.override import FabAirflowSecurityManagerOverride

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -284,11 +284,11 @@ Here is an example of what you might have in your webserver_config.py:
public_key = serialization.load_der_public_key(key_der)


class CustomSecurityManager(AirflowSecurityManager):
class CustomSecurityManager(FabAirflowSecurityManagerOverride):
def get_oauth_user_info(self, provider, response):
if provider == "keycloak":
token = response["access_token"]
me = jwt.decode(token, public_key, algorithms=["HS256", "RS256"])
me = jwt.decode(token, public_key, algorithms=["HS256", "RS256"], audience="account")

# Extract roles from resource access
realm_access = me.get("realm_access", {})
Expand Down