Testing OAuth2
I am attempting to setup my first OAuth2 client, as we are adventuring into the realm of making FHIR API calls to our EMR from HealthShare Health Connect.
I have gone through and set up the Issuer Endpoint, and Client Configuration but now I want to test it and verify that the setup is correct. When I setup the Client Configuration, it would not allow me to use Discovery as it was saying I needed a "Client secret" but was not given one. So I set it up manually, thinking I hit all the information correctly.
However, if I go through the documentation and use GetAuthorizationCodeEndpoint, I am receiving an error saying the AccessTokenID is required. Did I miss a step in trying to test the connection?
%SYS>set url = ##class(%SYS.OAuth2.Authorization).GetAuthorizationCodeEndpoint(OAUTHCLIENT,"scope1",OAUTHURL,.properties,.isAuthorized,.sc)
%SYS>zwrite sc
sc="0 "_$lb($lb(5659,"OAuth2.AccessToken::SessionId(6@OAuth2.AccessToken,ID=)",,,,,,,,$lb("%ValidateObject+24^OAuth2.AccessToken.1","%SYS",$lb("e^%ValidateObject+24^OAuth2.AccessToken.1^3","e^%SerializeObject+3^OAuth2.AccessToken.1^1","e^%Save+8^OAuth2.AccessToken.1^5","e^GetRequestEndpoint+139^%SYS.OAuth2.Authorization.1^1","e^GetAuthorizationCodeEndpoint+1^%SYS.OAuth2.Authorization.1^1","e^^^0"))))/* ERROR #5659: Property 'OAuth2.AccessToken::SessionId(6@OAuth2.AccessToken,ID=)' required */Does anyone have the proper sequence written out that I can use to test the OAuth from Terminal so I can continue on my quest to access the EMR FHIR repository?
Comments
I was able to get past the ERROR #5659: Property 'OAuth2.AccessToken::SessionId(6@OAuth2.AccessToken,ID=)' required by specifying an ID at the end of the request...
%SYS>set url = ##class(%SYS.OAuth2.Authorization).GetAuthorizationCodeEndpoint("EpicFHIRPOC",scope,OAUTHURL,.properties,.isAuthorized,.sc,,123)so the sc returns 1, however isAuthorized is still returning 0. If I run IsAuthorized, I am not seeing any errors.
Am I taking the correct steps? How do I get the Token?
GetAuthorizationCodeEndpoint() needs to be called from a valid %session. One way to do this is extend from %OAuth2.Login.