Hi everyone,
I have successfully set up Keycloak as a social login provider and I am able to log in without any issues. Additionally, I can obtain a token using Postman, and it parses correctly when tested on jwt.io.
However, I’m encountering an error when trying to access the /api/resource/job card
endpoint with the Bearer token. The error message I receive is as follows:
{
"exception": "frappe.exceptions.AuthenticationError",
"exc_type": "AuthenticationError",
"exc": "[\"Traceback (most recent call last):\\n File \\\"apps/frappe/frappe/app.py\\\", line 101, in application\\n validate_auth()\\n File \\\"apps/frappe/frappe/auth.py\\\", line 607, in validate_auth\\n raise frappe.AuthenticationError\\nfrappe.exceptions.AuthenticationError\\n\"]"
}
After tracing the code, I found that in auth.py
’s validate_oauth
method, frappe.db.get_value("OAuth Bearer Token", token, "scopes")
returns null
, which causes the code to skip over the validation of the token’s scopes and the set_user
method.
try:
required_scopes = frappe.db.get_value("OAuth Bearer Token", token, "scopes").split(
get_url_delimiter()
)
valid, oauthlib_request = get_oauth_server().verify_request(
uri, http_method, body, headers, required_scopes
)
if valid:
frappe.set_user(frappe.db.get_value("OAuth Bearer Token", token, "user"))
frappe.local.form_dict = form_dict
except AttributeError:
pass
As a result, in the validate_auth
method, frappe.session.user
is Guest
, leading to the authentication error being raised.
if len(authorization_header) == 2 and frappe.session.user in ("", "Guest"):
raise frappe.AuthenticationError
Here are my questions:
- a. At what point and where is the “OAuth Bearer Token” stored when making API calls?
- b. If I log in directly through Keycloak into ERPNext,
frappe.session.user
is set to the user’s email, and this works fine. Why does direct login via Keycloak work while using the Bearer token for API calls does not? - c. Am I missing some configuration or setup? What do I need to do to resolve this issue?
Thank you in advance for your help!
Best regards,