Closed Ashutosh2547 closed 3 months ago
Subscribing, getting same issue
Hi @Ashutosh2547 and/or @kanwaljit-mq can you please provide your full config.yml
? Before pasting, please make sure to remove any of the sensitive information such as keys, usernames, passwords, etc. I do not need those, just the rest of the configuration.
I have found two things I would like to ask you to check on the Salesforce side.
Can you ensure what the expiration date on the token is set to? I think this may be the "Token Timeout" described in the last paragraph here.
Can you also check the system time on the machine where the exporter is running? I've seen a few posts where people indicated that incorrect system times caused this error.
@Ashutosh2547 This is how I fixed the issue and I am sure there is an elegant way to do it besides this.
In file :/src/newrelic_logging/auth.py [Ref]
Go to Line #107 exp = int((datetime.utcnow() - timedelta(minutes=5)).timestamp())
P.S. Line number may be different based on branch you are on.
Update the minus to plus. This is where the session expiry time is set for your (Bearer) token. You can increase the number (5) it to however more/less needed for your use case.
So , it should look like : exp = int((datetime.utcnow() + timedelta(minutes=5)).timestamp())
HTH
Thanks @kanwaljit-mq , This fix worked for me.
Hi @kanwaljit-mq and @Ashutosh2547 , can you update your remote and checkout the branch fix/jwt-expired-auth-code
and see if this fixes your issue? The fix is the same as what you suggested (add instead of subtract) but also exposes a configuration variable for this value (default is 5).
@kanwaljit-mq @Ashutosh2547 PR #39 is now merged to main
. Please update your remote and give this a try.
Reopening this issue to address the error reported by @kanwaljit-mq here
@kanwaljit-mq This should fix it. I admit that I don't have an environment to test JWT authentication so it's possible there are still issues. Please give this a go and let me know how it works.
Description
After configuring the config.yml to point to the connected app and using the grant_type "jwt-bearer". Getting 400 bad request
Steps to Reproduce
Getting below error in auth.py
raise LoginException(f'sfdc token request failed. http-status-code:{resp.status_code}, reason: {resp.text}, full response {resp}') newrelic_logging.LoginException: sfdc token request failed. http-status-code:400, reason: {"error":"invalid_grant","error_description":"expired authorization code"}, full response <Response [400]>
Expected Behavior
JWT token should be retrieved and app should pull the data from SFDC.
Relevant Logs / Console output
File "C:\Application_Development\Personal\newrelic-salesforce-exporter\src__main.py", line 272, in main run(config, event_type_fields_mapping, numeric_fields_list) File "C:\Application_Development\Personal\newrelic-salesforce-exporter\src\main.py", line 213, in run run_once( File "C:\Application_Development\Personal\newrelic-salesforce-exporter\src\main__.py", line 165, in run_once ).run() ^^^^^ File "C:\Application_Development\Personal\newrelic-salesforce-exporter\src\newrelic_logging\integration.py", line 41, in run raise e File "C:\Application_Development\Personal\newrelic-salesforce-exporter\src\newrelic_logging\integration.py", line 37, in run instance.harvest(session) File "C:\Application_Development\Personal\newrelic-salesforce-exporter\src\newrelic_logging\instance.py", line 24, in harvest self.api.authenticate(session) File "C:\Application_Development\Personal\newrelic-salesforce-exporter\src\newrelic_logging\api.py", line 81, in authenticate self.authenticator.authenticate(session) File "C:\Application_Development\Personal\newrelic-salesforce-exporter\src\newrelic_logging\auth.py", line 197, in authenticate self.authenticate_with_jwt(session) File "C:\Application_Development\Personal\newrelic-salesforce-exporter\src\newrelic_logging\auth.py", line 147, in authenticate_with_jwt raise LoginException(f'sfdc token request failed. http-status-code:{resp.status_code}, reason: {resp.text}, full response {resp}') newrelic_logging.LoginException: sfdc token request failed. http-status-code:400, reason: {"error":"invalid_grant","error_description":"expired authorization code"}, full response <Response [400]> 2024-05-23 19:10:42,525 (15736/MainThread) newrelic.core.agent INFO - New Relic Python Agent Shutdown
Your Environment
Additional context