Skip to content

Commit 3d4730e

Browse files
committed
Merge branch 'saml-oauth-debug-logs' into 'develop'
Add debug logs to SAML and Oauth See merge request baserow/baserow!3779
2 parents 68e91b5 + f125a53 commit 3d4730e

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"type": "refactor",
3+
"message": "Add debug logging to SAML/OAuth2 views to get more information on issues.",
4+
"domain": "core",
5+
"issue_number": null,
6+
"bullet_points": [],
7+
"created_at": "2025-10-07"
8+
}

docs/development/sso-saml.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Setting up SAML SSO for development
2+
3+
* Create a new SAML authentication provider by going to
4+
http://localhost:3000/admin/auth-providers and clicking on "Add provider" and then on
5+
"SSO SAML provider".
6+
* Set SAML Domain to `example.com`.
7+
* Go to https://mocksaml.com/ and click on "Download Metadata". Put the contents of the
8+
file in the Metadata input.
9+
* Open the SAML Response Attributes and set the following.
10+
* Email: `email`
11+
* First name: `firstName`
12+
* Last name: `lastName`
13+
* Click on save, logout and try to log in using the newly created SAML provider.
14+
* Observe that you're redirected to the https://mocksaml.com login page where you can
15+
use any @example.com address to log in with.

enterprise/backend/src/baserow_enterprise/api/integrations/common/sso/saml/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from drf_spectacular.openapi import OpenApiParameter, OpenApiTypes
66
from drf_spectacular.utils import extend_schema
7+
from loguru import logger
78
from rest_framework.permissions import AllowAny
89
from rest_framework.request import Request
910
from rest_framework.views import APIView
@@ -81,6 +82,8 @@ def post(
8182
application_urls = None
8283
error_raised = {"code": None}
8384

85+
logger.debug("SAML ACS response payload: {0}", request.data)
86+
8487
def on_error(error_code):
8588
error_raised["code"] = error_code
8689

enterprise/backend/src/baserow_enterprise/api/sso/oauth2/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from drf_spectacular.openapi import OpenApiParameter, OpenApiTypes
88
from drf_spectacular.utils import extend_schema
9+
from loguru import logger
910
from rest_framework.permissions import AllowAny
1011
from rest_framework.request import Request
1112
from rest_framework.views import APIView
@@ -147,10 +148,17 @@ def get(self, request: Request, provider_id: int) -> HttpResponseRedirect:
147148

148149
provider = AuthProviderHandler.get_auth_provider_by_id(provider_id)
149150

151+
logger.debug(
152+
"OAuth2 callback request GET query params: {0}", dict(request.query_params)
153+
)
154+
logger.debug("OAuth2 callback session data: {0}", request.session._session)
155+
150156
code = request.query_params.get("code", None)
151157
user_info, original_url = provider.get_type().get_user_info(
152158
provider, code, request.session
153159
)
160+
logger.debug("OAuth2 extracted user info: {0}", user_info)
161+
154162
(
155163
user,
156164
_,

enterprise/backend/src/baserow_enterprise/sso/oauth2/auth_provider_types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ def get_user_info(
215215
"""
216216

217217
_, json_response = self.get_oauth_token_and_response(instance, code, session)
218+
219+
logger.debug("OAuth2 response: {0} {1}", _, json_response)
220+
218221
return self.get_user_info_from_oauth_json_response(json_response, session)
219222

220223

@@ -335,6 +338,8 @@ def get_user_info(
335338
token, json_response = self.get_oauth_token_and_response(
336339
instance, code, session
337340
)
341+
logger.debug("OAuth2 response: {0} {1}", token, json_response)
342+
338343
try:
339344
json_response["email"] = self.get_email(
340345
{"Authorization": "token {}".format(token.get("access_token"))},
@@ -557,6 +562,8 @@ def get_user_info(
557562
instance, code, session
558563
)
559564

565+
logger.debug("OAuth2 response: {0} {1}", token, json_response)
566+
560567
if instance.use_id_token:
561568
if "id_token" not in token:
562569
raise AuthFlowError("Id token is missing")
@@ -627,6 +634,7 @@ def get_user_info_from_id_token(self, instance, id_token):
627634
audience=instance.client_id,
628635
issuer=self.get_issuer(instance),
629636
)
637+
logger.debug("OIDC decoded id_token: {0}", decoded_token)
630638

631639
email = decoded_token.get(instance.email_attr_key)
632640

enterprise/backend/src/baserow_enterprise/sso/saml/handler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ def get_user_info_from_authn_user_identity(
160160
first_name_key = saml_auth_provider.first_name_attr_key
161161
last_name_key = saml_auth_provider.last_name_attr_key
162162

163+
logger.debug("Expected email key: {0}", email_key)
164+
logger.debug("SAML authn identity: {0}", authn_identity)
165+
163166
saml_request_data = saml_request_data or {}
164167
email = authn_identity[email_key][0]
165168
if first_name_key in authn_identity:
@@ -175,6 +178,7 @@ def get_user_info_from_authn_user_identity(
175178
else:
176179
name = email
177180

181+
logger.debug("Extracted user info: {0} {1} {2}", email, name, saml_request_data)
178182
return UserInfo(email, name, **saml_request_data)
179183

180184
@classmethod

0 commit comments

Comments
 (0)