Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid access token #124

Closed
Koudysmen opened this issue Apr 20, 2021 · 2 comments
Closed

Invalid access token #124

Koudysmen opened this issue Apr 20, 2021 · 2 comments

Comments

@Koudysmen
Copy link

Issue
I am trying to implement Smart on FHIR in my application using Angular and
I faced problem with authorization. I already registered new provider application in cerner sandbox
Currently I am possible run my application from Cerner sandbox. I guess that authorization process is successful because the server will send the access token back and also redirection working properly, but if I want to use this access token to get patient info from the FHIR server I will retrieve unauthorized response from FHIR server.

Unauthorized response (401):

{
    "resourceType": "OperationOutcome",
    "issue": [
        {
            "severity": "error",
            "code": "login",
            "diagnostics": "Bearer realm=\"fhir-ehr-code.cerner.com\", error=\"invalid_token\"",
            "location": [
                "http.Authorization"
            ]
        }
    ]
}

My implementation
Launch app

SMART.authorize({   
      clientId :"bacad00e-2fa4-48a6-9372-26ce70f0d16d",
      scope    : "patient/Patient.read patient/Observation.read launch online_access openid fhirUser",
      redirectUri : "http://localhost:4200/cdslung/?PatientId=12742400",           
  });

Index app

SMART.ready()
            .then(client => {
                const token = client.getAuthorizationHeader();
                console.log(token);
                client.request(`/Patient/${client.getPatientId()}`);            
            })
            .then(
                (patient) => {
                    console.log(patient);
                },
                error => {
                    console.error(error);
                }); 

Enviroment:
Angular CLI: 10.1.3
Node: 10.16.0
OS: win32 x64
fhirclient 2.3.11

@Koudysmen Koudysmen changed the title Invalid access tokne Invalid access token Apr 20, 2021
@SatioO
Copy link

SatioO commented May 2, 2021

I am facing the similar issue

"HttpError: 401 Unauthorized
URL: https://fhir-ehr-code.cerner.com/dstu2/ec2458f2-1e24-41c8-b71b-0e701af7583d/Patient/12724067

{
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "error",
"code": "login",
"diagnostics": "Bearer realm="fhir-ehr-code.cerner.com", error="invalid_token"",
"location": [
"http.Authorization"
]
}
]
}
Session expired! Please re-launch the app
at checkResponse (http://localhost:3000/static/js/0.chunk.js:11133:19)"

@vlad-ignatov
Copy link
Collaborator

@Koudysmen

  1. Remove the ?PatientId=12742400 portion of your redirectUri. Patient should be pre-selected at launch time.
  2. In your Index app in the first then function you need to return the client.request call
  3. In your app (in the browser) open the console, execute localStorage.debug = "FHIR.*". Then in console settings make sure logs are persisted across navigation. Then close the tab, re-launch your app, open the console and see if the debug log can help.

@SatioO
"Session expired! Please re-launch the app" might as well be an expected behavior. Try adding offline_access or online_access to to the scopes you request at authorize to see if that will enable token auto-refresh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants