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

Changes to support Keycloak v24 #193

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions django_airavata/apps/auth/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def _get_token_and_userinfo_password_flow(self, username, password):
token_url = settings.KEYCLOAK_TOKEN_URL
userinfo_url = settings.KEYCLOAK_USERINFO_URL
verify_ssl = settings.KEYCLOAK_VERIFY_SSL
oauth2_session = OAuth2Session(client=LegacyApplicationClient(
client_id=client_id))
scope = ['openid', 'profile', 'email']
oauth2_session = OAuth2Session(client=LegacyApplicationClient(client_id=client_id), scope=scope)
verify = verify_ssl
if verify_ssl and hasattr(settings, 'KEYCLOAK_CA_CERTFILE'):
verify = settings.KEYCLOAK_CA_CERTFILE
Expand All @@ -113,7 +113,8 @@ def _get_token_and_userinfo_password_flow(self, username, password):
password=password,
client_id=client_id,
client_secret=client_secret,
verify=verify)
verify=verify,
scope=scope)
userinfo = oauth2_session.get(userinfo_url).json()
return token, userinfo
except InvalidGrantError as e:
Expand All @@ -133,7 +134,7 @@ def _get_token_and_userinfo_redirect_flow(self, request):
redirect_uri = request.session['OAUTH2_REDIRECT_URI']
logger.debug("state={}".format(state))
oauth2_session = OAuth2Session(client_id,
scope='openid',
scope='openid profile email',
redirect_uri=redirect_uri,
state=state)
verify = verify_ssl
Expand All @@ -159,7 +160,7 @@ def _get_token_and_userinfo_from_refresh_token(self,
token_url = settings.KEYCLOAK_TOKEN_URL
userinfo_url = settings.KEYCLOAK_USERINFO_URL
verify_ssl = settings.KEYCLOAK_VERIFY_SSL
oauth2_session = OAuth2Session(client_id, scope='openid')
oauth2_session = OAuth2Session(client_id, scope='openid profile email')
verify = verify_ssl
if verify_ssl and hasattr(settings, 'KEYCLOAK_CA_CERTFILE'):
verify = settings.KEYCLOAK_CA_CERTFILE
Expand Down
7 changes: 2 additions & 5 deletions django_airavata/apps/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def redirect_login(request, idp_alias):
if passthrough_query_param in request.GET:
redirect_uri += f"&{passthrough_query_param}={quote(request.GET[passthrough_query_param])}"
oauth2_session = OAuth2Session(
client_id, scope='openid', redirect_uri=redirect_uri)
client_id, scope='openid profile email', redirect_uri=redirect_uri)
authorization_url, state = oauth2_session.authorization_url(
base_authorize_url)
authorization_url += '&kc_idp_hint=' + quote(idp_alias)
Expand Down Expand Up @@ -145,10 +145,7 @@ def handle_login(request):

def start_logout(request):
logout(request)
redirect_url = request.build_absolute_uri(
resolve_url(settings.LOGOUT_REDIRECT_URL))
return redirect(settings.KEYCLOAK_LOGOUT_URL +
"?redirect_uri=" + quote(redirect_url))
return redirect(settings.KEYCLOAK_LOGOUT_URL)


def callback(request):
Expand Down
Loading