Getting OAuth2 Error Epic EHR launch

647 views
Skip to first unread message

Pedram Hosseini

unread,
Aug 15, 2023, 3:15:20 PM8/15/23
to SMART on FHIR
Hi, I'm following the EHR Launch (SMART on FHIR) steps to complete one sample authorization process from my Python web app. Here's the situation:
  • I launch the EHR app using the Try it button here (first question: can I do this launch directly myself from my app?). From the list, I chose the app I created. For that app I have the clinet_id and the non-production client_id from Epic.
  • I specified the "http://0.0.0.0:8100/receive_data" which is a local address as the "launch URL to receive the request to your app"
  • Once I launch the app, it does call the endpoint on my local machine so looks like this part is working and the app is actually launched.
  • I receive the launch and iss successfully:
  • I also made a call and successfully received the Conformance Statement or SMART Configuration which includes the authorization_endpoint:
Now I need to get the Authorization Code and this is where I'm facing the error. Here's the GET request I'm sending to the authorization_endpoint with the following parameters:

The error I get is: OAuth2 Error, and it does not give me any more detail. What's wrong?

What I'm trying to do? I just simply want to authorize one of the sample users that Epic has provided for testing, through MyChart and show their MyChart profile in my Python app and make some FHIR calls for that user.

Sean Nolan

unread,
Aug 16, 2023, 3:16:59 AM8/16/23
to SMART on FHIR
The Epic sandbox is notorious for configuration update delays --- folks often find that their "oauth2 errors" have been magically fixed by waiting awhile (sometimes even a day or two, seriously). May or many not be your issue, but worth checking it again over the next couple of days. (Also probably not your issue this time, but you're sure to run into browser security problems down the road running your app as http vs https.) You could also try your client id with a "known working" sample app like mine at https://shutdownhook.com/2021/05/14/smart-part-2-a-real-app-in-less-than-100-lines/ and sniff those network connections to look for discrepancies with your code. Good luck! ---S

Heshan Wanigasooriya

unread,
Aug 17, 2023, 5:38:33 AM8/17/23
to SMART on FHIR
I recently created a sandbox environment using OAuth 2.0 at https://epic-sandbox.vercel.app/. The code can be found here: https://github.com/heshanlk/epic-sandbox. You can try running it locally and step through the authorization steps to understand what you are doing differently on your end.

Pedram Hosseini

unread,
Aug 17, 2023, 6:42:46 PM8/17/23
to SMART on FHIR
@Heshan: neat project, it's helpful, thanks for sharing. One question, I could start your code on my local machine but I'm getting the following error when I hit the Sign in with Epic MyChart button (screenshot attached). 
Just to double check one thing: where exactly should I put the .env file? And what's its format? May you provide an example?
Reason I'm asking is that I'm guessing there's an issue with the credentials (client ID and client secret), either the code can't find the EPIC_MYCHART_CLIENT_ID and EPIC_MYCHART_CLIENT_SECRET or there's an issue with the actual client ID and client secret values (I'm using the non-production client ID). I'm getting the very error on my app too

Screenshot 2023-08-17 at 3.36.39 PM.png

Heshan Wanigasooriya

unread,
Aug 18, 2023, 8:35:04 AM8/18/23
to SMART on FHIR
Added env.example to the repo also updated steps.

Pedram Hosseini

unread,
Aug 23, 2023, 12:46:30 PM8/23/23
to SMART on FHIR
@Heshan, thanks for the env example. Looks like the code can now find the client ID from the env file, but I still get the "An error has occurred. The request is invalid." after hitting the login with MyChart. Do you think there's an issue with recognizing my client ID? I'm honestly pretty confused and don't know what the problem is! The non-production client id is the only thing I can think of. Is there anything critical in my app setting page on Epic that could cause such an error?
Screenshot 2023-08-23 at 9.40.56 AM.png

Ashok Sharma

unread,
Mar 17, 2024, 8:41:55 AMMar 17
to SMART on FHIR
I am getting the same issue now. It was working fine until last week. No change in code or the FHIR-EPIC app setup. All of sudden started getting this message. Has anyone has any idea how to troubleshoot and fix this issue?

Thanks in advance for the help
Ashok

sibin c sebastian

unread,
May 10, 2024, 5:07:34 AMMay 10
to SMART on FHIR
Hey im facing the same issue? any solutions yet?
Reply all
Reply to author
Forward
0 new messages