smart-on-fhir / sample-apps-stu3

Collection of simple sample apps
Other
47 stars 43 forks source link

error:0909006C:PEM routines:get_name:no start line #20

Open awatson1978 opened 3 years ago

awatson1978 commented 3 years ago

Hello, I'm trying to follow the backend-service example in a code sandbox, and we're getting the following error.

[nodemon] restarting due to changes...
[nodemon] starting `node src/index.js`
Authorizing...
jwtToken { iss: 'https://sandbox.symptomatic.io/',
  sub: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwdWJfa2V5IjoiLS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS1cbk1JSUJJakFOQmdrcWhraUc5dzBCQVFFRkFBT0NBUThBTUlJQkNnS0NBUUVBbjFVaUNFRVpsY1ZKZDFUVmFoY1FcbmIwVnIvbjlHTGJYTzRadmYwSnloSEJwOC9sOEtXVUhOOUx5NU9nTkV6akFvWldTQU5HcVdmakttckZqb3U0eStcblRVRDhWTW9adGUvMEdNQjRrMHc3VG8vMmpHMzhZQi8yQ214alZ6S1RZT3lXL2liQ1JXbzZsMmxZZ00yQjFhTDNcbktEWXlBTnc5NUhNUVQvTXI1WEhNMXR2NUN0S1ZsNTI1YTQvSDFSSytwOVhFQ1F5U2Z4NDhJOGFTRFkvTlE3NGVcbi9pMmhRaE9halIxejUzWWZlS3paNjlpZW82YWdnb3JUMzdOcDQ0Ymo5Wnljcldmem1wdUpESkFIRUZPbEpTK1lcbktuNUxINmNaVmUzcUZEcFVvQnlVdGhZSEVVbUF3WDNBSkJsWEpRWEllRGFDUU1Xa0ZWWXhNSXFzb0VWeGN6YlpcbnRRSURBUUFCXG4tLS0tLUVORCBQVUJMSUMgS0VZLS0tLS0iLCJpc3MiOiJodHRwczovL293OHNrLnNzZS5jb2Rlc2FuZGJveC5pby8iLCJhY2Nlc3NUb2tlbnNFeHBpcmVJbiI6MTUsImlhdCI6MTYwNzQ5MzY3MH0.gsR2Q1Zd0NHlzamKg197Z1l9oD4hAJ8E8yryHLGWUYs',
  aud: 'https://launch.smarthealthit.org/v/r3/auth/token',
  exp: 1607497205.693,
  jti:
   'dba64937a085f62b22e269ab874350ed3d94069ff5992aea4ee4fc81760f0fbf' }

internal/crypto/sig.js:80
  var ret = this._handle.sign(key, passphrase, rsaPadding, pssSaltLength);
                         ^

Error: error:0909006C:PEM routines:get_name:no start line
    at Sign.sign (internal/crypto/sig.js:80:26)
    at Object.sign (/sandbox/node_modules/jwa/index.js:152:45)
    at Object.jwsSign [as sign] (/sandbox/node_modules/jws/lib/sign-stream.js:32:24)
    at Object.module.exports [as sign] (/sandbox/node_modules/jsonwebtoken/sign.js:186:16)
    at authorize (/sandbox/src/index.js:120:29)
    at getPatients (/sandbox/src/index.js:63:12)
    at countPatients (/sandbox/src/index.js:140:3)
    at Object.<anonymous> (/sandbox/src/index.js:156:13)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

Has anybody seen this error before? Has this demo been confirmed to work recently?

WestonSkeans commented 3 years ago

I know this thread is a little old, but I ran into this as well and found the root cause / solution. There are two paths depending on which FHIR server you are interacting with.

Are you using the SMART App Launcher (or docker container)? If so, then you might be confused by the "Download to JSON" button in the launcher that provides a config.json file that looks (almost) identical to the one used in this example app. It looks though like it doesn't quite work that way. I haven't been able to get the app launcher to persist / recognize any public/private key combination used in the launcher. It appears that only the config used in this repo (or others used in SMART example apps) will let you authenticate. So long story short, just use the config.json used in this repo if connecting to the SMART Launcher, change the fhir_url and token_url if you have the launcher running in a docker container but don't touch the private key, client id or service url.

Are you connecting to a real SMART instance? If so, then to use this example app you need to replace the private_key variable with the private key base64 encoded (including the key start and end markers including -----BEGIN RSA PRIVATE KEY-----). This is understandably confusing because the SMART App launcher has "Download to JSON" button that returns a config.json file that is almost identical to the file used in this example app, except the private key is not base64 encoded in the file it generates, though this app expects it to be.