The issue describes a clear bug with a straightforward fix.
The issue reports a bug where the OAuth token cache fails when the server omits the `token_type` field. The fix involves defaulting to 'bearer' when the field is absent, which is a simple code change. There are no apparent blockers.
TokenCache.update_data() throws an exception when the OAuth server response
does not include a token_type field. While RFC 6749 Section 5.1 technically
requires this field, many real-world OAuth servers — particularly internal/custom
implementations and some token refresh responses — omit it, implicitly defaulting
to Bearer. This makes Frappe's Connected App integration fail with any such server.
Output of bench version
frappe 15.x.x (or develop branch)
token_type
from its token responsefrappe.exceptions.ValidationError: Received an invalid token type.
The token is never stored. The Connected App integration is broken for that server.
When token_type is absent, Frappe should default to "bearer" (the RFC
implied default) and store the token successfully, matching the behaviour of
oauthlib and requests-oauthlib.
Traceback (most recent call last):
File "frappe/integrations/doctype/token_cache/token_cache.py", in update_data
frappe.throw(_("Received an invalid token type."))
frappe.exceptions.ValidationError: Received an invalid token type.
Root cause:
# Current (BUGGY):
token_type = cstr(data.get("token_type", "")).lower()
# If token_type absent: "" → not in ["bearer", "mac"] → throws
if token_type not in ["bearer", "mac"]:
frappe.throw(_("Received an invalid token type."))
Fix — default to "bearer" when absent:
# Fixed:
token_type = cstr(data.get("token_type", "bearer")).lower()
if token_type not in ["bearer", "mac"]:
frappe.throw(_("Received an invalid token type."))
This matches the behaviour of oauthlib (the library Frappe already us
Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!